Jump to content


Re: Managed DirectX, Shadows


1 reply to this topic

#1 Dharshi

    New Member

  • Members
  • Pip
  • 1 posts

Posted 29 February 2008 - 01:17 PM

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

#2 vdf22

    New Member

  • Members
  • PipPip
  • 20 posts

Posted 29 February 2008 - 10: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users