Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Pipo DeClown


This topic is 5905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

k, I know 3 color values for ambient(or diffuse blabla too?) 1) Light 2) Material 3) When you do SetRenderState( D3DRS_AMBIENT , ... ) So what do you see and are they all being used?

Share this post

Link to post
Share on other sites
Oh sorry,
uhm, when you create light, you set the colors.
when you create material, you set the colors.
so which one is used, or are they combined?
and there is also a RenderState for ambient, which makes 3 ambient lights.

Share this post

Link to post
Share on other sites
Ah, okay.

Well, in real life, when something is a certain colour, it is because the object reflects that color light to your eyes, and absorbs all the other colors. White objects reflect all light to your eyes, red objects only reflect red light to your eyes and absorbs all the other colours, and black objects absorb all light, so no light will be sent to your eyes.

The same is true in DirectX. DX lights can emit three colours of light: Red, Green, and Blue. (you can of course mix them for more colours). When you set a material, you set which color it reflects, and how much of it. So if I set a material with r=1.0 g=0.0 b=1.0, it will reflect all red and blue lights, but no green light. If I then shine on it with a white light-source (r=1.0 g=1.0 b=1.0), it will reflect the red light and the blue light, and do nothing with the green light, making the object look purple.
If the light source contained only red light, it would reflect that red light, and make the object appear red. The same goes for blue.
If you set a green light on it, however, the object will appear black, because it doesn''t do anything with green light.

So, in short: Light colors define what color your light will be, and material colors define what color light your object will reflect back to the camera. In essence, material colors define what color a material will look like.

Note that you have to tell materials which color they reflect for every type of light, so you have to define what color ambient light they reflect, what colour diffuse light, etc.

The AMBIENT renderstate sets ambient light. This can be thought of as the light that is -always- there, even when all your directional-, point- and spotlights are turned off. There is usually always a certain amount of light in a room, illuminating all polygons an equal amount. This is the ambient light. It is usually set to some gray-ish colour so that your scene doesn''t appear pitch black where there is no light.

Share this post

Link to post
Share on other sites

REDLIGHT -> material( r=255 , g=0 , b=0 )-> Red reflection.

REDLIGHT -> material( r=0 , g=255 , b=0 )-> No reflection.

Is this true?
And why is in Direct3D the max colorvalue 1.0f?

Share this post

Link to post
Share on other sites

Why it is 1.0f? Probably because there''s a huge range of values between 0.0f and 1.0f. They could''ve made it a char, but then you''d only have 255 different light levels. Still, you''d think an unsigned long int (which, like float, is also 4 bytes), which gives a range between 0 and 4,294,967,95 would be enough.

I guess it''s just easier to think of 0.0 as off and 1.0 as on. It''s easier to think about. If I want half light, I set 0.5. If I want a quarter of the full light, I set 0.25. It''s just thinking in percentages.

Share this post

Link to post
Share on other sites
Useful properties of normalised floats:

0*0 = 0
0*1 = 0
1*0 = 0
1*1 = 1

compare 1*1 with 255*255. 1*1 preserves the value. Inside graphics hardware 0-255 is still treated as 0-1 (or more precisely what is essentially a divide takes place)

0*aValue = 0
1*aValue = aValue
-1*aValue = -aValue
255*aValue = not aValue, not 255
-255*aValue = not -aValue, not -255

Consider the range you get if you take a reciprocal: 1/aValue


In the context of per pixel operations etc, thinking in terms of 0-1 is handy.

Simon O''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!