Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


can 'SetTextureStageState' be used with pixel shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 tcige   Members   -  Reputation: 206

Like
0Likes
Like

Posted 16 June 2013 - 09:35 AM

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



Sponsor:

#2 belfegor   Crossbones+   -  Reputation: 2722

Like
1Likes
Like

Posted 16 June 2013 - 10:47 AM

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);


#3 BornToCode   Members   -  Reputation: 949

Like
0Likes
Like

Posted 16 June 2013 - 10:51 AM

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



#4 mhagain   Crossbones+   -  Reputation: 8282

Like
0Likes
Like

Posted 16 June 2013 - 10:56 AM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 tcige   Members   -  Reputation: 206

Like
0Likes
Like

Posted 16 June 2013 - 11:02 AM

 

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



#6 tcige   Members   -  Reputation: 206

Like
0Likes
Like

Posted 16 June 2013 - 11:04 AM

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



#7 belfegor   Crossbones+   -  Reputation: 2722

Like
2Likes
Like

Posted 16 June 2013 - 11:39 AM

In pixel shader:

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



Edited by belfegor, 16 June 2013 - 11:44 AM.


#8 tcige   Members   -  Reputation: 206

Like
1Likes
Like

Posted 16 June 2013 - 12:45 PM

 

In pixel shader:

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


 

yeah, pixel shader is so convenient






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS