transparent in shader

Started by
7 comments, last by rapso 17 years, 6 months ago
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));	
}


Advertisement
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.
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
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.
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.
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.)
Orin Tresnjak | Graphics ProgrammerBethesda Game StudiosStandard Disclaimer: My posts represent my opinions and not those of Bethesda/Zenimax, etc.
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 ;)

ive solved it.. .. how would i do fragment clipping using GLSL?
Quote:Original post by Dragon_Strike
ive solved it.. .. how would i do fragment clipping using GLSL?


maybe the way lancekt said, with discard?

This topic is closed to new replies.

Advertisement