<Context id="GLOWMASK">
<!-- This material does glow - output colors masked by the alpha channel -->
<VertexShader>
<InsCode code="utilityLib/vertCommon.glsl" />
<DefCode>
<![CDATA[
uniform vec3 viewer;
attribute vec2 texCoords0;
attribute vec3 normal, tangent, bitangent;
varying vec3 eyeTS;
varying vec2 texCoords;
varying vec4 pos;
void main( void )
{
// Transform tangent space basis
vec3 tsbTangent = normalize( calcWorldVec( tangent ) );
vec3 tsbBitangent = normalize( calcWorldVec( bitangent ) );
vec3 tsbNormal = normalize( calcWorldVec( normal ) );
// Calculate world space position
pos = calcWorldPos( gl_Vertex );
// Eye vector and eye vector in tangent space
eyeTS = calcTanVec( viewer - pos.xyz, tsbTangent, tsbBitangent, tsbNormal );
// Calculate texture coordinates and clip space position
texCoords = texCoords0;
gl_Position = gl_ModelViewProjectionMatrix * pos;
}
]]>
</DefCode>
</VertexShader>
<FragmentShader>
<DefCode>
<![CDATA[
uniform sampler2D tex0;
varying vec3 eyeTS;
varying vec2 texCoords;
void main( void )
{
const float plxScale = 0.03;
const float plxBias = -0.015;
// Iterative parallax mapping
vec3 newCoords = vec3( texCoords, 0 );
vec3 eye = normalize( eyeTS );
for( int i = 0; i < 4; ++i )
{
vec4 nmap = texture2D( tex0, texCoords.st );
float height = nmap.a * plxScale + plxBias;
newCoords += (height - newCoords.p) * nmap.z * eye;
}
vec4 glow = texture2D( tex0, newCoords.st ).rgba;
glow *= glow.a;
gl_FragColor = glow;
}
]]>
</DefCode>
</FragmentShader>
</Context>