Archived

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

Lighting with multitexturing

This topic is 5650 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''m not crystal clear on exactly what multitexturing encapsulates, but lets just say that it means applying different textures to the different texture stages so that the pixels go through several textures before rendered. I have a question- how do you apply lighting when using more then one texture? This is the code for my second texture stage-


	g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
	g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	g_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);


 
And when I render it with setting one texture to texture stage 0 and a different texture to texture stage 1, it has no lighting. But this is the weird part. When I change MODULATE in the above code to MODULATE2X (bit shifting or whatever) the lighting works! I don''t understand the application of the lighting when using more then one texture in one render pass.

Share this post


Link to post
Share on other sites

Say you had the following:

SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);

SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);


That would do:

OUTrgb = (TEX0rgb * DIFFUSErgb) * TEX1rgb

OUTrgb is the colour which gets passed on to the rendering/blending stage.

TEX0rgb is the colour for the texture set at stage 0

TEX1rgb is the colour for the texture set at stage 1

DIFFUSErgb is the diffuse vertex colour - which if you''re using lighting and have a vertex format with a normal in will come from the D3D lighting engine.

I posted a reply to someone here last week which explained what happens during the multitexture cascade - it might be of use to you.





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

Share this post


Link to post
Share on other sites
Ok, I knew that except for the the diffuse coming from the lighting engine part. That equation is basically what I've simplified mine down to, but I'm still getting no lighting with it. If what you are saying is right, I should be getting lighting because of the diffuse component. So how come there's no lighting when I use the structure that you just stated?
And what confuses me even more, how come I get lighting when I use MODULATE2X?

Edit: I'll look for that thread, thanks

[edited by - okonomiyaki on June 25, 2002 1:16:21 PM]

Share this post


Link to post
Share on other sites
Are you sure the lighting just isn't very weak? by using MODULATE2X you're doubling the effect of lighting in stage 0, so that when you do your second multiplication in stage 2, the lighting effect is still strong enough to be visible (theres a darkening kind of effect with using MODULATE which is due to the math). Try lowering ambient light levels and increasing the strength of you light when using just MODULATE to test to see if you really do have lighting or weither its just a weak effect. Perhapes an easier test would be to just lower the strength of your lights to almost nothing. If you really have no lighting effect, then the brightness of your model shouldn't change at all and still remain visible dispite the low light. Also make sure you're using D3DTA_CURRENT in your 2nd stage so that you're passing the diffuse lighting value on to stage 2. Thats about the only things i can think of Hope it helps.


[edited by - Merick on June 25, 2002 2:21:24 PM]

Share this post


Link to post
Share on other sites
I''m pretty sure the lighting isn''t just weak, even when I set the ambient lighting very low (black) and turn lighting on/off I see basically no difference. I''ll just use MODULATE2X. Maybe the lighting is just sooo light that it doesn''t seem there. Or, I''ve discovered that this sucky graphics card (Voodoo 3) is doing some REALLY weird things with multitexturing. I''ll wait until I get a Geforce 4 until I ask any more questions!
Thanks!

Share this post


Link to post
Share on other sites