Setting Color and Alpha Channel

Started by
11 comments, last by Medo Mex 10 years, 11 months ago

I don't have much experience with shaders, so I will need alittle more help here.

You said I should multiply IN.color with the texture color in Pixel Shader, how? should I use mul?


float4 VolumeLinePS( TOutputVertex IN ) : COLOR
{
          float4 blendFactor = IN.blend;
          float4 c0 = tex2D( textureSampler, IN.tex0 );
          float4 c1 = tex2D( textureSampler, IN.tex1 );
          return lerp( c0, c1, blendFactor );
}

BTW, I'm not getting assertion failure or any runtime complain.

EDIT:

I tried the following vertex structure:


struct TVertex
{
D3DXVECTOR3 pos;
D3DXVECTOR3 otherPos;
DWORD color;
D3DXVECTOR4 texOffset;
D3DXVECTOR3 thickness;
static const DWORD FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE |
D3DFVF_TEX2 | // D3DFVF_TEX2 specifies we have two sets of texture coordinates.
D3DFVF_TEXCOORDSIZE4(0) | // This specifies that the first (0th) tex coord set has size 4 floats.
D3DFVF_TEXCOORDSIZE3(1); // Specifies that second tex coord set has size 2 floats.
};

Now, I can see the lines, but I don't see the diffuse color applied, maybe I have to change the Pixel Shader code?

Advertisement

float4 VolumeLinePS( TOutputVertex IN ) : COLOR
{
          float4 blendFactor = IN.blend;
          float4 c0 = tex2D( textureSampler, IN.tex0 );
          float4 c1 = tex2D( textureSampler, IN.tex1 );
          return lerp( c0, c1, blendFactor ) * IN.color;
}

Regarding a per-vertex tint, you would do it like the above ^^^.

But of course you need to add color to your TOutputVertex:


struct TOutputVertex
{
float4 hPos : POSITION;
float blend : COLOR0;
float4 color : COLOR1;
float4 tex0 : TEXCOORD0;
float4 tex1 : TEXCOORD1;
};

.. and pass it through in your vertex shader, e.g.



OUT.color = IN.color;

If you're already having problems getting things to show up though, I wouldn't bother with a tint until you have everything else working.

@phil_t: Nice! Now I got it to work with the diffuse color and I see that the color changed, however the alpha channel is not working.


// Getting different color but the alpha channel is not getting affected
vrts[0].color = D3DCOLOR_RGBA(255, 0, 255, 1);
vrts[1].color = D3DCOLOR_RGBA(255, 0, 255, 1);
vrts[2].color = D3DCOLOR_RGBA(255, 0, 255, 1);
vrts[3].color = D3DCOLOR_RGBA(255, 0, 255, 1);

I also want to say that the alpha channel is not getting affected only when I use D3DBLEND_ONE:

device->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_ONE );
device->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
device->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD );

This topic is closed to new replies.

Advertisement