can 'SetTextureStageState' be used with pixel shader

Started by
6 comments, last by tcige 10 years, 10 months ago

i test if using pixel shader, SetTextureStageState has no effect

so how to use the texture's alpha value in pixel shader, i can not find any instruction

Advertisement

I think that SetTextureStageState is FFP thing and it won't work with shaders.


...so how to use the texture's alpha value in pixel shader.

You must set some render states to enable alpha blending.

Look here for example.

To set alpha blending based on texture alpha channel you could do this:

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

Like belfegor mention. In DirectX9 some of the render state still works while others no longer do anything once you use shaders.

Pixel shaders completely replace the old SetTextureStageState calls; see http://msdn.microsoft.com/en-us/library/windows/desktop/bb944006%28v=vs.85%29.aspx#Pixel_Shader_Basics

If you want to set a specific alpha value for use in a shader you either send it as a shader constant or pass it through from the vertex shader as a color attribute.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I think that SetTextureStageState is FFP thing and it won't work with shaders.


...so how to use the texture's alpha value in pixel shader.

You must set some render states to enable alpha blending.

Look here for example.

To set alpha blending based on texture alpha channel you could do this:


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

i mean D3DTSS_ALPHAOP, how pixel shader gets texture's alpha

Pixel shaders completely replace the old SetTextureStageState calls; see http://msdn.microsoft.com/en-us/library/windows/desktop/bb944006%28v=vs.85%29.aspx#Pixel_Shader_Basics

If you want to set a specific alpha value for use in a shader you either send it as a shader constant or pass it through from the vertex shader as a color attribute.

i want to get the picture's alpha channel value

In pixel shader:


float4 textureColor = tex2D( samp, texCoord );
float alpha = textureColor.a; 


In pixel shader:


float4 textureColor = tex2D( samp, texCoord );
float alpha = textureColor.a; 


yeah, pixel shader is so convenient

This topic is closed to new replies.

Advertisement