Re: Managed DirectX, Shadows

Cfdd4e12a6bbe25456129cd9c1c26970
0
Dharshi 101 Feb 29, 2008 at 13:17

hi all,

Now I am working on Loading the 3d object using Directx in C#. I want ot produce shadow for my 3d object. I have used the following code

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, 1.0f, 0);
            device.BeginScene();

            device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 0.3f, 1000f);
            device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 30), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

            device.VertexFormat = CustomVertex.PositionTextured.Format;
            device.SetTexture(0, texture);
            device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, vertices);

            device.RenderState.Lighting = false;
            device.RenderState.CullMode = Cull.None;
            device.Lights[0].Type = LightType.Directional;
            device.Lights[0].Diffuse = Color.LightBlue;
            device.Lights[0].Position = new Vector3(6, 0, -6);
            device.Lights[0].Direction = new Vector3(0, -10, 50);
            device.Lights[0].Enabled = true;

            device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 0.3f, 1000f);
            device.Transform.View = Matrix.LookAtLH(new Vector3(0, 10, 30), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

            Plane plne = new Plane();
            plne.A = 0;
            plne.B = 0;
            plne.C = 10;
            plne.D = 1000;
         
            LoadMesh("C:\\Directx\\airplane.x");

            device.Transform.World = Matrix.Translation(1, 5, 12);          

            DrawMesh(angle3 / (float)Math.PI, angle3 / (float)Math.PI * 2.0f, angle3 / (float)Math.PI / 4.0f, 0f, 0f, 0f);
            device.Transform.World.Shadow(new Vector4(5, 10, 15, 1), plne);
            
            device.EndScene();
            device.Present();
            this.Invalidate();

But no shadow i am getting. Could any of you point where i have done mistake please?

Thanks in Advance,
Dharshi

1 Reply

Please log in or register to post a reply.

2f202c9f415522f43d07a9f6b77f0527
0
vdf22 101 Feb 29, 2008 at 22:40

The Matrix.Shadow method doesn’t actually draw the shadow, you still need to use a shader to do the drawing. Matrix.Shadow just makes a matrix that flattens an object to a plane, so you don’t have to do all the math yourself.