# Coloring with Normal Maps

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

## Recommended Posts

I swear this is the last one :) My rendering engine allows objects to define a diffuse and ambient color. There is also a global directional light diffuse. The result is pretty much objectambient + ( objectdiffuse * lightdiffuse * brightness). I'm starting to realize now that once diffuse is used up in the vertex format to output data to the dot product 3 routine, no coloring at all is possible. Not light diffuse, not object ambience, and not object diffuse. Or at least it appears that way. This is how I have the texture stages lined up:
SetTextureState( 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3 );
SetTextureState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

SetTextureState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
SetTextureState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
The dot product stage uses the diffuse color that my vertex shader outputs. I've tried making it rely on the specular color instead, but then diffuse is completely ignored - it has no effect on the color or lighting (which makes sense of course). Is there any way to sneak another D3DTA_DIFFUSE value in here somewhere if I replace the current with D3DTA_SPECULAR? If I'm doing something completely dumb, please point that out as well. Anyone know how to get color into this setup? Do I have to add another texture stage to do so? [Edited by - Kest on September 9, 2005 7:26:37 PM]

##### Share on other sites
I did a presentation that covers this subject at the 2002 gdc d3d tutorial day.

http://developer.nvidia.com/object/gdc_practicalperpixel.html

##### Share on other sites
Wow, I've learned a lot from that. Thanks much.

One thing that has me puzzled is this last but very important bit that you have at the end of the L.N + ambient routines:

Source Blend mode
SrcColor*SrcAlpha

I realize we want to mutliply the end result color and alpha. But I can't seem to figure out how to do that. I'm pretty tired, so it's very possible I'm asking very dumb questions.

Another part that I'm not completely sure about is where you set tfactor.a as the second alpha arg. You have tfactor.a (holding ambience, which I totally get), but D3DTA_TFACTOR needs set as the alpha operand, correct? As in Direct3D would only use the alpha part of the argument, since it's an alpha arg? Otherwise, I'm not sure how to set just the alpha component of t-factor.

Thanks again for your help. Any info regarding the source blend mode would be great :)

##### Share on other sites
I think I figured it out. You meant this setup, right?

SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );

It appears to be working. Very cool :)

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 24
• 52