Hello,
I am just getting into writing shaders and I really can't seem to figure out why this doesn't work... (I'm sure some of you may notice it is a modification of setcolor fx bundled with construct 2)
All I want to do is invert the alpha without messing with anything else, but that's not what happens. It works fine on one object but when you layer the objects or have different colored backgrounds it stops working:
/////////////////////////////////////////////////////////
// Flip Alpha effect
varying mediump vec2 vTex;
uniform lowp sampler2D samplerFront;
uniform lowp float red;
uniform lowp float green;
uniform lowp float blue;
void main(void)
{
lowp float a = texture2D(samplerFront, vTex).a;
lowp float r = texture2D(samplerFront, vTex).r;
lowp float g = texture2D(samplerFront, vTex).g;
lowp float b = texture2D(samplerFront, vTex).b;
gl_FragColor = vec4(r,g,b,1.0-a);
}
<?xml version="1.0" encoding="UTF-8" ?>
<c2effect>
<!-- About -->
<id>flipalpha</id> <!-- Never change the ID. Change the name instead -->
<name>Flip Alpha</name>
<category>Alpha</category>
<description>Invert Alpha Channel</description>
<author>Ruskul</author>
<!-- Settings -->
<!-- Extend the bounding box for effect processing by a number of pixels to show the edges
of effects which go beyond the object edges, e.g. blur and warp. -->
<extend-box-horizontal>0</extend-box-horizontal>
<extend-box-vertical>0</extend-box-vertical>
<!-- Set to true if the background is sampled (samplerBack is referenced at all in the shader) -->
<blends-background>false</blends-background>
<!-- Set to true if the background is not sampled at 1:1 with the foreground (e.g. the
background texture co-ordinates are modified in some way by the shader, as done
by Glass and Lens) -->
<cross-sampling>false</cross-sampling>
<!-- Set to true if the effect changes over time, e.g. Noise or Warp effects. -->
<animated>false</animated>
<!-- Parameters -->
<parameters>
<param>
<name>Red</name>
<description>Red level to set, from 0 to 100.</description>
<type>percent</type>
<initial>1</initial>
<uniform>red</uniform>
</param>
<param>
<name>Green</name>
<description>Green level to set, from 0 to 100.</description>
<type>percent</type>
<initial>0</initial>
<uniform>green</uniform>
</param>
<param>
<name>Blue</name>
<description>Blue level to set, from 0 to 100.</description>
<type>percent</type>
<initial>0</initial>
<uniform>blue</uniform>
</param>
</parameters>
</c2effect>