theHollow Posted January 4, 2005 Posted January 4, 2005 (edited) Lighting problems Hi there I have problems adding lights on my project. I have created a simple cube with different colors on the different sides. Very simple. And it works very well if I have set D3Ddev.RenderState.Lighting = False (my Direct3D device is called D3Ddev). So I tried to set the Renderstate.Lighting to true. As expected, my object became black. So I added this: D3Ddev.Lights(0).Type = LightType.Directional D3Ddev.Lights(0).Diffuse = Color.White D3Ddev.Lights(0).Direction = New Vector3(0.0F, 0.0F, 1.0F) D3Ddev.Lights(0).Update() ' Commit() D3Ddev.Lights(0).Enabled = True But it still don't work. I believe I have misunderstood something, and that I must apply the light to something or...I don't know. I have noticed that the D3Ddev.DeviceCaps.MaxActiveLights = 0. Can anyone help me? I have VB.NET and DirectX 9c (december 2004). Does anyone have a VB.NET project that I can look at? - theHollow Split from http://www.xtremedotnettalk.com/showthread.php?t=72399 Edited January 4, 2005 by theHollow Quote
theHollow Posted January 4, 2005 Author Posted January 4, 2005 Ah... I have found out that I have to use PositionNormalColored instead of PositionColored. If anyone can tell me why, and maybe the differences between PositionNormalColored and PositionColored? I don't quite understand all the parameters of PositionNormalColored. Still learning :rolleyes: - theHollow Quote
Administrators PlausiblyDamp Posted January 5, 2005 Administrators Posted January 5, 2005 IIRC PositionNormalColored tells directx how to handle the light hitting the surface (reflection etc) clicky is probably worth a read as it makes a lot more sense than my explanation. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ThePentiumGuy Posted January 5, 2005 Posted January 5, 2005 The Normal (aka rhw) parameter is the perpendicular direction in which you want the light to hit it at. Err.. ok, here: What�s going on here is that Direct3D is using something called the surface normal to calculate how light interacts with an object. The word �normal� in this context has nothing to do with being ordinary. Rather, it�s a mathematical term that means �a vector that�s perpendicular to something�. So a surface normal is a vector that points straight out of the surface. In the case of our sphere, the surface normal always points straight out from the center of the sphere, but for more complex objects, this wouldn�t necessarily be the case. Pictures help explain better than word, so I've attached an image. Explanation for the image. Diagram A: Our object + our light (blue) Diagram B: The direction of our Normal, it's the perpendicular direction away from the vertex. Diagram C: What happens is (it's hard to tell from the diagram), the light is reflected from the vertex in that direction (remember, when an object is a certain color, that's its ability to reflect that color.... hint: think Chlorophyll. A plant isn't really green, it appears to be green because Chlorophyll reflects the color green). Therefore, the light is reflected in that direction. It's sort of hard to explain - you really need to play around with it to understand it. Change the direction of the normal and you'll see that the object is ... heh... lighted differently. Here's one thing - look at diagram B. What if those arrows went the other direction? (To the right). Then the object would appear black (silhouette effect). Jus tplay around like I said before, it helps a lot more. Edit: whoops, I forgot to attach the image: -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
DrunkenHyena Posted January 6, 2005 Posted January 6, 2005 The Normal (aka rhw) parameter is the perpendicular direction in which you want the light to hit it at. Err.. ok, here: The normal is NOT the same as the rhw and is not even vaguely related. Rhw is the fourth component of a screen space vertex (Transformed). Quote
ThePentiumGuy Posted January 6, 2005 Posted January 6, 2005 Oh yeah. Sorry I must have mixed a few things up. Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.