PDA

View Full Version : Re: Managed DirectX, Shadows


Dharshi
02-29-2008, 05:17 AM
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.TriangleLi st, 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

vdf22
02-29-2008, 02:40 PM
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.