Why don't lights work in MDX?

Started by
2 comments, last by Sr_Guapo 17 years, 11 months ago
Working on a C# program (cloth simulation). Lights don't work right in MDX!!! This is really pissing me off. Here's an screenshot: Anyone have any ideas? Here's the relevant renderstates:

cloth.mesh.material.AmbientColor = new ColorValue(255,0,0);
            cloth.mesh.material.DiffuseColor = new ColorValue(255, 0, 0);
            s.material.EmissiveColor = new ColorValue(0, 0, 0);
            s.material.SpecularColor = new ColorValue(0, 0, 0);
            
            cloth.scene = scene;

            device.Lights[0].Type = LightType.Point;
            device.Lights[0].Direction = new Vector3(1, 1, 0);
            device.Lights[0].Position = new Vector3(0, 50, 0);
            device.Lights[0].Range = 55;
            device.Lights[0].AmbientColor = new ColorValue(0,0,0);
            device.Lights[0].DiffuseColor = new ColorValue(55, 55, 55);
            device.Lights[0].SpecularColor = new ColorValue(0, 0, 0);
            device.Lights[0].Enabled = true;
            device.Lights[0].Update();
            

            
            device.RenderState.Ambient =  Color.Black;
            device.RenderState.ShadeMode = ShadeMode.Gouraud;
            updateCamera();


PS: anyone know how to make it stop zfighting? :D:D Thx all
Advertisement
First off,
Lights do work and it's all in the way you set it up and how you understand them that makes them work.

Pointers to some Point lights.
1. Point lights don't have any single direction
2. Point lights are affected by range and attenuation

Simple setup to a point light
Device.Lights[0].Type = LightType.Point;Device.Lights[0].Position = new Vector3(0.0f, 0.0f, -10.0f);Device.Lights[0].Attenuation1 = 0.5f;Device.Lights[0].Range = 100.0f;Device.Lights[0].Enabled = true;


ZFighting can be resolved by creating a Depth Buffer and appropriately setting your near and far clipping planes of your projection matrix. Usually the approach taken is creating a AutoDepthStencilBuffer

PresentParams.AutoDepthStencilFormat = DepthFormat.D24S8;PresentParams.EnableAutoDepthStencil = true;//Now you should also create/define simple view and projection matrices for your devicedevice.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, 1.0f, 1.0f, 1000.0f);device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 10.0f, -50.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));


That shoule about cover it.

I hope this helps.
Take care.

[Edited by - Armadon on May 7, 2006 2:18:06 PM]
I went ahead and changed to shaders because i wanted perpixel lighting anyway :D :D MDX is pretty nice for prototyping code fast...

But to reply: zfighting is not "fixed by using a zbuffer". I'm talking about the stuff you get when you have decals on polygons, except non planer. zbuffer just orders things correctly. turning on a zbuffer won't fix zfighting.
Quote:Original post by risingdragon3
I went ahead and changed to shaders because i wanted perpixel lighting anyway :D :D MDX is pretty nice for prototyping code fast...

But to reply: zfighting is not "fixed by using a zbuffer". I'm talking about the stuff you get when you have decals on polygons, except non planer. zbuffer just orders things correctly. turning on a zbuffer won't fix zfighting.


Z-fighting is when the increments in the depth buffer are larger than the increments between objects. This can be caused by a variety of things including:

- Too little precision in the depth buffer
- Too large of a gap in the near and far planes
- Too small of a distance between objects

How are you trying to place the decals? You are going to have to offset them slightly in order for them the show correctly.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute

This topic is closed to new replies.

Advertisement