Sign in to follow this  

lightning

This topic is 4358 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

i just made some "experiments" with DirectX Fixed Function Lightning. for educational purposes i ordered the textureState0 to select the texture color and dont use the vertex diffuse color: device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorOperation = TextureOperation.SelectArg1; if u start the application with these settings, then there is no lightning calculation is the scene (the scene looks normal, like if u have set lightning to false) now i have the following assumption: DirectX stores the result of the lightning stage in the diffuse color of the vertices. (anf if u set lighting to true and texturestate0.colorArgument1=Diffuse and textureState0.colorArgument2=TextureColor the object is textured AND lit correctly) is my assumption correct?

Share this post


Link to post
Share on other sites
Pretty close. It doesn't store the diffuse color in the vertex information. It uses the diffuse color from the vertex and the normals for that vertex to create a modulated version of the diffuse color (light). When lighting is enabled, you get that modulated (lit) version of diffuse color. When it's disabled, you get the diffuse value directly from the vertex information.

Chris

Share this post


Link to post
Share on other sites
after the lightning state the (original) diffuse color is replaced by the result of the lightning stage, isnt it? then i would understand that if i set the states to the default settings:
device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
device.TextureState[0].ColorArgument2 = TextureArgument.TextureColor;
device.TextureState[0].ColorOperation = TextureOperation.Modulate;

everything is lot correctly. the diffuse color (which is just the normal color if u set lightning to false or the result of the lightning stage if u set lightning=true) is modulated with the texture.

Share this post


Link to post
Share on other sites
When lighting is off, the colors come straight from the colors stored in the vertex and the texture. When lighting is on, those values are still used but they are modified by the light and its position (or angle).

When lighting is off you still use the "diffuse" color. In this case, it is not actually the "diffuse" (as in diffuse reflection) color. That is just the name of the slot that is used. Its the same for the "tex coord" slots -- they aren't always used for texture coordinates.

BTW, the word is lighting, not lightning. Lightning is the electrical discharges you see in the sky during a storm.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBolton
When lighting is off, the colors come straight from the colors stored in the vertex and the texture. When lighting is on, those values are still used but they are modified by the light and its position (or angle).

U say that the diffuse color AND the texture are modified (lit) by the lighing stage. but i think thats not correct. i think ONLY the diffuse color is modified by the lighing pipeline, cause if i just use the textureColor in the first textureStage (like i did in my first posting) the scenes textures arent lit (even if lighing is on).


Quote:

BTW, the word is lighting, not lightning. Lightning is the electrical discharges you see in the sky during a storm.

sorry for that mistake

Share this post


Link to post
Share on other sites
The inputs to the texture unit are the vertex colors that are output from the lighting pipeline. Obviously if you disable lighting, the diffuse and specular colors will come directly from the vertex data (or use the defaults if the colors don't exist in the vertex). The texture colors aren't used by the lighting pipeline at all.

If you want to play around and try to learn what the fixed-function lighting pipeline does when you set the various render states, check out IDirect3DDevice9::ProcessVertices.

Share this post


Link to post
Share on other sites
If the original diffuse color in the vertex information is used in the lighting calculation, then replaced with the new value, after several frames, all of your vertex information would contain pure white vertex diffuse values. Hence the reason it's not done that way. The vertex information is retained to keep you from having to reload it every frame.

Default Case without materials: The diffuse color in the vertex is modulated by the lighting values and a new color is stored in a register. The texture color is then modulated by this new color.

You can change the source color used for the diffuse lighting calculations with a call to SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, ...). It can be a material, the vertex diffuse color, or the vertex specular color.

Share this post


Link to post
Share on other sites
thanks to all of u guys. this forum is awesome! i guess now i got it. i try to summarise now (please correct me if something is still wrong):

// Example1
// In this 3 Lines i wont see any lighting, cause the result of the lighing stage // is stored in a register (or temporarly place) which is accessible by //DiffuseColor. In this 3 lines i just use the texturecolor and so i dont use the //lighing result and dont get any lighting.
device.RenderState.Lightning = true;
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;

// Example2
// this time i get lighting. the result of the lighing equatation is stored
// in Diffuse
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
device.TextureState[0].ColorOperation = TextureOperation.Modulate;

i really hope this is all correct now:-)

Share this post


Link to post
Share on other sites

This topic is 4358 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this