Help! D3DTA_DIFFUSE died!

Started by
9 comments, last by Nypyren 21 years, 7 months ago
I''m trying to color-modulate a greyscale texture to a certain color by modulating TEXTURE with DIFFUSE: device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); // texture device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); But the result is all black, even though my vertex diffuse are all 0xFFFFFFFF. I try SELECTARG2 to get only the diffuse, and it''s pitch black again. I use SELECTARG1 to get only the texture, and it displays the texture fine (but obviously not modulated) I''m using a directional light, FVF is diffuse, xyz, normal, tex1 My memcpy works... Vertexbuffer works (otherwise how would the texture coords be correct?) alphablend is enabled... the transparent places are correct... This is seriously aggrivating.
Advertisement
Remember that if you enable lighting, Direct3D don't use diffuse color in your VERTEX structure any more, but the material properties. So to tell D3D that he must use diffuse value of your vertex structure, try this:

device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1 );

(although I'm not sure it will work)

[edited by - HiddenInBSP on September 1, 2002 6:12:53 AM]
I tried your code... everything behaves the same (DIFFUSE pretends to be black)

I TOTALLY disabled lighting... normals, lights, vertex format...

texturing still works, diffuse does not.


The strange part is that when I have lighting enabled, and I spin the light''s direction around, the texture stays the same brightness...
If this helps any:

vertex format flags:

#define FVF_CUSTOMVERTEX (D3DFVF_DIFFUSE | D3DFVF_NORMAL | D3DFVF_XYZ | D3DFVF_TEX1)


vertex buffer is using the following:
CUSTOMVERTEX cv[4] = { {-0.5, -0.5, 0.0, 0.0, 0.0, -1.0, 0xFFFFFF00, 0.0, 0.0},
{ 0.5, -0.5, 0.0, 0.0, 0.0, -1.0, 0xFFFF00FF, 1.0, 0.0},
{-0.5, 0.5, 0.0, 0.0, 0.0, -1.0, 0xFF00FFFF, 0.0, 1.0},
{ 0.5, 0.5, 0.0, 0.0, 0.0, -1.0, 0xFFFFFFFF, 1.0, 1.0} };

// It''s a square with a texture in it.

this is my "SetRenderStates()" function:

{
device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); // texture
device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

device->SetRenderState(D3DRS_ZENABLE, true);
device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
}

This is my render primitive function:
{
device->SetIndices(iBuffer, 0);
device->SetTexture(0, texture);
device->SetVertexShader(FVF_CUSTOMVERTEX);
device->SetStreamSource(0, vBuffer, sizeof(CUSTOMVERTEX));

if (D3D_OK != device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, numVerts, 0, numTris))
throw "BUNK";
}


I checked the vertex buffer by locking, dumping to memory and printing to file, unlocking... the data is perfect.

I''ve done this before in DirectX 8.0, worked great, but now I''m using 8.1, and I suspect that I''m forgetting something like a RenderState or some feces.
** hot off the press **

Using TFACTOR and MODULATE with 0xFFFF0000 (red) as the texture factor WILL turn the texture entirely red, but I need per-vertex color.
I think you will have to define material properties, or if you want you can put:
device->SetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1 );
If it don''t work, I think your data are corrupts...
Can you post your CUSTOM_VERTEX declaration?
typedef struct
{
float x, y, z;
float nx, ny, nz;
DWORD color;
float u, v; // texture coords
} CUSTOMVERTEX;


Here''s my plan... I''m going to start a new project from scratch and try to get the Tutorial with the spinning triangle working again...

Hopefully that will help me figure it out
You''re my official hero!

device->SetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1 );

It fixed my problems!


I guess the issue was that with 8.0 I didn''t need to mess with materials, and 8.1 I have to.
Ok, it seems good, but the solution that I've given you is not really a "good" solution (although it works), cause if your vertices emit color, they can't be correctly affected by other lights (So if you want to add other light effects, in the future, maybe it will suck)...
I think there is a problem with your light...
And to light correctly your vertices, you can try this:

//The ambient reflection is defined by Diffuse member of VERTEX
//structure
Device->SetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1 );

//Put a white and bright ambient light
Device->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB( 255, 255, 255 ) );

If it works (I'm not sure), so use this instead of using emissive material...

[edited by - HiddenInBSP on September 2, 2002 6:37:28 AM]

This topic is closed to new replies.

Advertisement