shader / slab transparency behavior

Jun 27, 2013 at 8:13am

shader / slab transparency behavior

FORUM -

Been banging my head against this one for a couple of days so I figured it’s time to buck up and ask –

I’ve got a simple shader that creates an alpha-blended circle (soft circle goes from param-defined color in the center to transparent at the edges).

I’m using that shader on a slab and getting the color param just fine but no alpha. I was able to confirm the alpha is calculated properly by testing the shader with calculated alpha on all channels (commented line in the shader below).

I know it’s something simple in my implementation that’s preventing alpha from being used but I’m at a loss where to look next.

Any help would be appreciated.

Thanks,

N

FRAG SHADER

varying vec4 vertexPosition;
uniform vec4 circleColor;
uniform float intensity;
uniform float circleSizeModifier;

void main()
{
vec4 center = vec4(0.0,0.0,0.0,0.0);

vec4 position = vec4(vertexPosition.x, vertexPosition.y * .75, vertexPosition.z, vertexPosition.a);
float alpha = distance(position.xy, center.xy);
alpha = alpha * circleSizeModifier;
alpha = pow(alpha , intensity);

alpha = pow(alpha ,-1.0);

gl_FragColor = vec4(circleColor.x, circleColor.y, circleColor.z, alpha * circleColor.a);

// gl_FragColor = vec4(alpha, alpha, alpha, alpha * circleColor.a);

}

VERT SHADER
varying vec4 vertexPosition;

void main()
{

gl_Position = ftransform();
vertexPosition = gl_Position;

}

JXS

<jittershader name="gradShader">
<param name="circleColor" type="vec4" default="0.0 0.3 1.0 1.0" />
<param name="intensity" type="float" default="1.65" />
<param name="circleSizeModifier" type="float" default="4.0" />
<language name="glsl" version="1.0">
<bind param="circleColor" program="fp" />
<bind param="intensity" program="fp" />
<bind param="circleSizeModifier" program="fp" />
<program name="vp" type="vertex" source="gradShader.vs.glsl" />
<program name="fp" type="fragment" source="gradShader.fs.glsl" />
</language>
</jittershader>

TEST PATCH

<code>

– Pasted Max Patch, click to expand. –

</code>

#254271
Jun 27, 2013 at 8:45am

to enable transparency on any opengl object, you must set @depth_enable 0 and @blend_enable 1 (there’s some exceptions, but not relevant in your case).
you then control the layering order with the @layer attribute.

generally, opaque objects are drawn first and transparent objects last.

#254273
Jun 27, 2013 at 12:15pm

BOOM Rob strikes again!

Thanks Rob!!

#254300

You must be logged in to reply to this topic.