• Advertisement
Sign in to follow this  

can 'SetTextureStageState' be used with pixel shader

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

In pixel shader:

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


Edited by belfegor

Share this post


Link to post
Share on other sites

 

In pixel shader:

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


 

yeah, pixel shader is so convenient

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement