D3D lightmapping

Started by
2 comments, last by amish1234 20 years, 10 months ago
I want to render triangles that have a color and lightmap. When I try this the triangle turns out black. Actually, 2 vertices are black and one is red. The red gets brighter when I change
 D3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);  
to
D3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);  
and even brighter when I use MODULATE4X. The color I set for each vertex is green. Here's my code:

//defining the FVF:

#define D3DFVF_TRANSFORMEDLIGHTMAPVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_DIFFUSE)


   
//my struct:

struct TransformedLightMapVertex
{
	FLOAT x, y, z, rhw, tu, tv;
	DWORD color;
};


   
//rendering code:

D3DDevice->SetFVF(D3DFVF_TRANSFORMEDLIGHTMAPVERTEX);
D3DDevice->SetTexture(0, lightmap);
D3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
D3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
D3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
D3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); //when I change this to modulate2x or modulate4x the red gets brighter

   D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, &LightMapVertices[0], sizeof(TransformedLightMapVertex));
I'm guessing I'm just not using the correct flags in my calls to SetTextureStageState. The texture I'm using for my lightmap is a plain white bitmap. Proceeding on a brutal rampage is the obvious choice. [edited by - amish1234 on July 2, 2003 6:33:42 PM]
___________________________________________________________Where to find the intensity (Updated Dec 28, 2004)Member of UBAAG (Unban aftermath Association of Gamedev)
Advertisement
For FVF vertices, diffuse color comes after texture coordinates (check "Vertex Formats" in the SDK docs, in Programming Guide->Getting Started with Direct3D)

So, change your struct to:
struct TransformedLightMapVertex{    FLOAT x, y, z, rhw;    DWORD color;    FLOAT tu, tv;};


Also, make sure you set the operations for stage 1 to DISABLE for both color and alpha, after you fix your struct.

Peace,
Muhammad Haggag

quote:Original post by Coder
Also, make sure you set the operations for stage 1 to DISABLE for both color and alpha, after you fix your struct.


Don't you mean stage 0? Since I am only using 1 texture, isn't the texture on stage 0? Or is my color on stage 0 and my texture on stage 1?


Edit: this works after I fixed my struct. I didn't disable alpha or texture. Everything is on stage 0, it's just that the color is ARG1 and the texture is ARG2.

Thanx.


[edited by - amish1234 on July 2, 2003 7:33:47 PM]
___________________________________________________________Where to find the intensity (Updated Dec 28, 2004)Member of UBAAG (Unban aftermath Association of Gamedev)
You''re using stage 0, and stage 0 only. That''s why I''m saying you should disable stage 1 by setting both COLOROP and ALPHAOP for stage 1 to D3DTOP_DISABLE. Why? Because you shouldn''t rely on default values. You could very easily add code - later - that would utilize the 2nd stage before your lightmap code, which would mess things up.

Conclusion: Always disable the 1st stage you don''t use

Peace,
Muhammad Haggag

This topic is closed to new replies.

Advertisement