XNA Creators Club Online
Page 1 of 1 (1 items)
Sort Posts: Previous Next

Shading Problem??

Last post 9/23/2009 12:13 PM by Clarkey84. 0 replies.
  • 9/23/2009 12:13 PM

    Shading Problem??

    Hi there,

    I am working on a piece of software which I originally wrote with VS2005, DirectX SDK (August 2006) on a laptop running Windows XP Pro with Mobile Intel(R) 915GM/GMS, 910 GML Integrated Graphics. On this machine I had no problems rendering a 3D head in my software, a screen dump of which is shown here. I have also run this software successfully on other various machines with various graphics cards, the only common factor being they were all running XP.

    I recently purchased a new desktop, which has an Nvidia 9300 GeForce GE, DirectX SDK (March 2009), and runs Windows Vista Home Premium. When I run my software on this machine however there seems to be a problem rendering the 3D head, as shown here.

    Now I am fairly new to 3D graphics programming, so am not really sure what the problem could be. Is it a shading problem maybe, I really have no idea! At first I thought it was a depth problem, because from the front the head looks totally flat, but if you rotate the head to the side in the software, then the depth and shape appear to be correct, so I am guessing this means the depth buffer is working ok. I haven't changed any of the code which is responsible for rendering the head (see below), so I am guessing its something either to do with the fact that this machine is running Vista (unlikely?), or something to do with the settings of my graphics card (have looked but can't see anything obvious), or the different DirectX SDK. Problem is I dont know where to start with trying to find out what is actually causing the problem, so was wondering if anyone here might have an idea, or could point me in the right direction! Any help or advice would be great, it would be nice to be able to write this software on my desktop as it is much faster than the laptop I started with :-)

    Thanks!

    Here is all the code for rendering the head (some unrelated stuff has been omitted):
    bool InitializeGraphics()     
            {     
                try    
                {     
                    DisplayMode disp = Manager.Adapters[Manager.Adapters.Default.Adapter].CurrentDisplayMode;     
                    presentParams.Windowed = true;     
                    presentParams.SwapEffect = SwapEffect.Discard;     
                    presentParams.MultiSample = MultiSampleType.None;     
                    presentParams.EnableAutoDepthStencil = true;     
                    presentParams.AutoDepthStencilFormat = DepthFormat.D16;     
        
                    bufwid = presentParams.BackBufferWidth;     
                    buflen = presentParams.BackBufferHeight;     
        
                    // Create the D3DDevice     
                    device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);     
        
                    device.DeviceReset += new System.EventHandler(this.OnResetDevice);     
                    this.OnResetDevice(device, null);     
                    pause = false;     
                    SetupMatrices();     
                    setMeshVerts();     
                    //TextureMap();     
                }     
                catch (DirectXException)     
                {     
                    return false;     
                }     
                return true;     
            }     
        
    void SetupMatrices()     
            {     
                device.RenderState.CullMode = Cull.None;     
                Viewport frontView = new Viewport();     
                frontView.X = 0;     
                frontView.Y = 0;     
                frontView.Width = this.Width;//2;     
                frontView.Height = this.Height;//2;     
                frontView.MinZ = 0;     
        
                frontView.MaxZ = 1;     
        
                device.Transform.World = worldFix * Matrix.Translation(xMovement, modMovement, 0) * Matrix.RotationY(rotYAng) * Matrix.RotationX(rotXAng);     
        
                device.Transform.View = Matrix.LookAtLH(new Vector3(angle, 0, -550000 + zoom),     
                new Vector3(0.0f, 0.0f, 0.0f),     
                new Vector3(0.0f, 1.0f, 0.0f));     
        
        
                if (viewFound == 0)     
                {     
                    view = device.Transform.View;     
                }     
        
                device.Transform.Projection = Matrix.PerspectiveFovLH((float)(Math.PI / 7), 239.0f / 294.0f, 100.0f, 1000000.0f);     
        
                device.RenderState.ZBufferEnable = true;     
                     
                if (!texturise)     
                {     
                    device.RenderState.Lighting = true;     
        
                    device.Lights[0].Diffuse = Color.Beige;     
                    device.Lights[0].Type = LightType.Directional;     
                    device.Lights[0].Direction = new Vector3(0, -1, -1);     
                    device.Lights[0].Enabled = true;     
        
                    device.Lights[1].Diffuse = Color.Beige;     
                    device.Lights[1].Type = LightType.Directional;     
                    //not working!!     
                    device.Lights[1].Direction = new Vector3(0, 1, 1);     
                    device.Lights[1].Enabled = true;                   
                }     
                else    
                {     
                    device.RenderState.Lighting = false;     
                }     
        
                if (texturise)     
                {     
                    device.SamplerState[0].MinFilter = TextureFilter.Anisotropic;     
                    device.SamplerState[0].MagFilter = TextureFilter.Anisotropic;     
        
                    device.SamplerState[0].AddressU = TextureAddress.Mirror;     
                    device.SamplerState[0].AddressV = TextureAddress.Mirror;     
        
                }     
            }     
        
    public void Render()     
            {     
                if (device == null)     
                    return;     
        
                if (pause)     
                    return;     
        
        
                try    
                {       
                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.White, 1.0f, 0);     
        
                    device.BeginScene();     
        
                    SetupMatrices();     
                         
                    if (texturise)     
                    {     
                        device.VertexFormat = CustomVertex.PositionNormalTextured.Format;     
        
                        device.SetTexture(0, txt);     
                    }     
                    else    
                    {     
                        device.VertexFormat = CustomVertex.PositionNormalColored.Format;     
                        mesh.ComputeNormals();     
                        device.RenderState.ShadeMode = ShadeMode.Gouraud;     
                    }     
        
                    if (meshRen == 0)     
                    {     
                        setFeat(meshFeatIndices);     
                        if (checkFeatPts())     
                        {     
                            meshRen = 1;     
                        }     
                    }     
        
                    device.RenderState.FillMode = FillMode.Solid;     
                             
                        for (int i = 0; i < meshMaterials.Length; i++)     
                        {     
                            device.Material = meshMaterials[i];     
                            mesh.DrawSubset(i);     
                        }     
           
                        if (meshFeaturePoints.Count > 0) //spheres to show feature points     
                        {     
                            Direct3D.Mesh sphere = Mesh.Sphere(device, 5000f, 50, 50);     
                            sphere.ComputeNormals();     
        
                            Material SphereCol = new Material();     
                            SphereCol.Ambient = Color.DarkRed;     
                            SphereCol.Diffuse = Color.Red;     
                            SphereCol.Specular = Color.White;     
        
                            Direct3D.Mesh sphere2 = Mesh.Sphere(device, 5000f, 50, 50);     
                            sphere2.ComputeNormals();     
        
                            Material SphereCol2 = new Material();     
                            SphereCol2.Ambient = Color.Yellow;     
                            SphereCol2.Diffuse = Color.Yellow;     
                            SphereCol2.Specular = Color.White;     
        
        
                            Matrix world2 = new Matrix();     
                            Matrix headMat = device.Transform.World;     
           
                            for (int i = 0; i < meshFeaturePoints.Count; i++)     
                            {     
                                CustomVertex.PositionNormalTextured pnt = (CustomVertex.PositionNormalTextured)meshFeaturePoints[i];     
                                if (i != colouredDiff)     
                                {     
                                    if (pnt.X != -1 && pnt.Y != -1 && pnt.Z != -1)     
                                    {     
                                        world2 = Matrix.Translation(pnt.X, pnt.Y, pnt.Z);     
        
                                        device.Transform.World = world2 * headMat;     
                                        device.Material = SphereCol;     
                                        sphere.DrawSubset(0);     
                                    }     
                                }     
                                else    
                                {     
                                    if (pnt.X != -1 && pnt.Y != -1 && pnt.Z != -1)     
                                    {     
                                        world2 = Matrix.Translation(pnt.X, pnt.Y, pnt.Z);     
        
                                        device.Transform.World = world2 * headMat;     
                                        device.Material = SphereCol2;     
                                        sphere2.DrawSubset(0);     
                                    }     
                                }     
                            }      
                        }     
                    }     
                         
                    device.EndScene();     
                    device.Present();     
                }     
                catch (Direct3DXException e)     
                {     
                         
                }     
        
            }     
        
     
Page 1 of 1 (1 items) Previous Next