Sign in to follow this  

transparent in shader

This topic is 4092 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

im trying to render a textured quad and where the texture is black it should be transparent... but of rsome reason it doesnt get transparent.. doesnt amttter if i put 0 in hte alpha channel right away... do u have to something more than putting the alpha value in the fragment shader to get a transparent object?
void main()
{

	
	vec3 texcolor = texture2D(tex0, gl_TexCoord[0].st).rgb;

	gl_FragColor = vec4(texcolor.r, texcolor.g, texcolor.b, any(texcolor));	
}


Share this post


Link to post
Share on other sites
use the clip instruction in the shader, negative values will make the pixel transparent by rejecting it

or set the renderstates of alphablend and alphatest to support ur alpha.

Share this post


Link to post
Share on other sites
Quote:
Original post by rapso
use the clip instruction in the shader, negative values will make the pixel transparent by rejecting it

or set the renderstates of alphablend and alphatest to support ur alpha.


how wouldi use the clip instruction? did some googling but it didnt return anything

Share this post


Link to post
Share on other sites
You have to enable blending. Otherwise the fragment shader just replaces the appropriate pixel in the frame buffer with the new color without ever taking the alpha value into account.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragon_Strike
Quote:
Original post by rapso
use the clip instruction in the shader, negative values will make the pixel transparent by rejecting it

or set the renderstates of alphablend and alphatest to support ur alpha.


how wouldi use the clip instruction? did some googling but it didnt return anything


e.g.

clip(texcolor.a<treshold?-1.f:1.f);

if the alpha is below the treshold u want, the pixel is rejected/completely transparent.

Share this post


Link to post
Share on other sites
Isn't clip an HLSL thing? In GLSL you can

discard;

Which will discard the current fragment.

(Edit: This is of course if you want to do something like alpha testing, i.e. your output is either 100% opaque or 100% clear. If you want true translucency you will want to enable alpha blending, as Expandable said.)

Share this post


Link to post
Share on other sites
Quote:
Original post by lancekt
Isn't clip an HLSL thing? In GLSL you can

discard;

yes, but he did not mentioned what he's using.
Quote:
as Expandable said.)
as I said as well ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragon_Strike
ive solved it.. .. how would i do fragment clipping using GLSL?


maybe the way lancekt said, with discard?

Share this post


Link to post
Share on other sites

This topic is 4092 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this