D3D lights

Started by
7 comments, last by Fuzztrek 21 years, 6 months ago
Hello All, For some reason, every time I create a light, I need to enable ambient lighting. I don''t know why, is this a common problem, or is it supposed ot be that way? I don''t have to set the ambient light to anything, I just need to "enable" it i guess. very odd. ¬_¬
Advertisement
bump
er.. bump again.

¬_¬
<br><br><br>- Light in the real world hits a surface and the level of illumination is decided by the angle the light hits the surface (L.N) and how much light is absorbed by the surface (the D3D material). This is roughly what is modelled by the D3D lighting system<br><br>- However in the real world, any light which hasn''t been absorbed reflects off the surface and hits other surfaces in the scene until all the energy in the light is gone or something occludes it (shadow etc). This is what is what''s modelled by radiosity and ray tracing.<br><br>- &#79;n top of the pure absorb/reflect stuff, there are also environmental effects &#111;n what happens to the light caused by the substances it''s travelling through.<br><br>- Since D3D (and OpenGL) doesn''t do radiosity, ray-tracing or model environmental effects you need to "emulate" the contribution to the objects facing away from the light which would normally be seen. That''s what AMBIENT is for - for hacking around the fact that you can''t model the real world properly in realtime yet*.<br><br>- What do you mean by "enable" ambient lighting? <br>If you mean setting the ambient render state to ''a value'' then that doesn''t enable/disable it, it purely sets the value for it.<br><br>- What''ve you got your material settings set to?<br>The diffuse value determines how much of the light to vertex contribution makes it through to the final vertex.<br>The ambient value determines how much of the ambient light level (and colour) goes through to the final vertex.<br><br>- What type of lights are you using? If it''s spotlights or point lights, make sure your attenuation and range are set to something sensible.<br><br>[*]<br><br>–<br>Simon O''Connor<br>Creative Asylum Ltd<br><A HREF="http://www.creative-asylum.com">www.creative-asylum.com</A>

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Hello! thanks for responding!!

I only bump posts when they are near hitting the second page, I figure that if i post again, i''ll get flaimed for double posting . Sorry though.

Ah, I see here what you mean. Yes, thats what I meant by enabling it. Just setting it to a value.. anything. But I don''t understand why I havn''t found any tutorials that tell me to turn on ambient lighting? I don''t even think that the SDK tutorials tell me too. And even in the examples i''ve downloaded they don''t turn it on.

Just to clarify, it is the SetRenderState(D3DRS_AMBIENT, D3DCOLOR_RGBA(0, 0, 0, 255) that I need to set, not the ambient color in the light structure. Currently I am using a spot light.

Thanks again!

¬_¬
If you need ambient light, then either your lights are broken or your drivers are broken. Maybe you should try with other light types first, to narrow down the problem. Also ensure you have a pure white material set, to keep things simple.

S1CA - what are ''sensible'' values for attenuation? The docs are very obtuse on this. Nowhere could I find a ''reasonable'' value or set of values, just a formula which means nothing to me.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
Fuzztrek:

1) Try setting the diffuse member of your *MATERIAL* (e.g. D3DMATERIAL8, device->SetMaterial() etc) to 1,1,1 to specify that the material of the polygons in the scene reflects all the light which hits it.
Also set the ambient member of the material to 1,1,1

2) Try turning on the D3DRS_NORMALIZENORMALS renderstate. If that helps stuff then either the normals on your vertices are screwed up or your transformation matrices contain scales or skews.

3) You do have normals in your vertex format don''t you? If the _only_ lighting contribution is coming from the ambient colour, then either the normals coming through to the lighting calcs, the light object or some related thing is problematic.



Kylotan:

1) First probably best to mention what attenuation is. The light starts out at its source with a certain amount of power (intensity) - as you get further away from the source the intensity in the real world decreases since it travels through things which absorb some of that energy.

2) For realtime stuff modelling that would be expensive so again another hack/approximation: attenuation.

3) The parameters really just define a curve which describes what happens to the intensity over distance. Get a graphing calculator or use a graph program to draw a graph and you''ll get a better idea:

Along the X axis, have distance, say from 0 to 1000
The Y axis is "intensity", say from 0 to 100

I is the initial intensity, set it to 100
a, b, c are the attenuation coefficients you pass to D3D

A = (a + (b*X) + (c*(X^2)))
P = I * A

P is the point you plot on the graph for every X
X is really the distance outward from the light.


The graph you see should give you a better idea about what happens to the light intensity over distance. You could even colour the graph based on P so you see the light get darker with distance.


As for sensible values, try starting with the ones in the lighting sample in the SDK, plug those into the graph and play around with them to see what they do to the graph and the real D3D light (it''d be a nice app for someone with a bit of time on their hands to write - a light properties experiment/demo prog).


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Hey there..

I have a standard x file in my scene. The x file is textured, I created it in 3DS max and exported it using the plugin. I have D3DRS_NORMALIZENORMALS enabled.

The color of my light object IS comming through, if I turn down the ambient lighting color. Example, I can turn the ambient render state to about 2, 2, 2, and the color of my light comes through. However, if i set the ambient render state to 255, 0, 255, the ambient render state color comes through.

¬_¬
It sounds like your code is working fine, just set up with some bad parameters somewhere.


1) Try one of the .X files from the SDK to be 100% sure nothing went wrong with the export - NORMALIZENORMALS will fix non unit normals but won''t fix totally malformed ones.


2) Spotlights are obviously very directional and depending on their cone settings usually only light a very small area. There''s a chance that the contribution from the light is actually correct - i.e. the object is just on the edges or far range of the cone (frustum) of the spotlight.


3) Try changing the light type to a point light so that the light effectively gives off light in all directions. If the object suddenly becomes lit, then the above is true - the object is on the edge of the light.


4) What exactly do you have set for the members of your D3DLIGHT8 structure for the light ?

a. Try setting Range to sqrtf(FLT_MAX);

b. Set falloff to 1.0 This determines how the light gets darker toward the outside of the cone.

c. To set constant attenuation over distance (in case the light is falling off too early), set it to 1,0,0

d. Make sure theta and phi are between 0 and PI

e. AND make sure theta<=phi

f. Set the diffuse colour to 1,1,1 for pure white


5) What exactly are the members for your D3DMATERIAL8 structure set to ?:

a. Try 1,1,1 for diffuse and ambient

b. And 0,0,0 for specular and emissive

c. Set the power to 0 (it''s only used to control the exponent of specular calculations).


6) You have done a IDirect3DDevice8::SetMaterial before rendering havent you ?

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement