com.bladecoder.engine.shading.floor.fragment.glsl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blade-engine Show documentation
Show all versions of blade-engine Show documentation
Classic point and click adventure game engine
// VERTEX SHADER TO DRAW THE SHADOW ON THE FLOOR
// DRAWS THE SEMITRANSPARENT SHADOW AND SETS THE PIXEL TRANSPARENT WHEN NO SHADOW
// TODO: SET SHADOW ALPHA AS PARAM
#ifdef GL_ES
#define LOWP lowp
#define MED mediump
#define HIGH highp
precision mediump float;
#else
#define MED
#define LOWP
#define HIGH
#endif
uniform sampler2D u_shadowTexture;
uniform float u_shadowPCFOffset;
varying vec3 v_shadowMapUv;
float getShadowness(vec2 offset)
{
const vec4 bitShifts = vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0);
return step(v_shadowMapUv.z, dot(texture2D(u_shadowTexture, v_shadowMapUv.xy + offset), bitShifts));//+(1.0/255.0));
}
float getShadow()
{
return (//getShadowness(vec2(0,0)) +
getShadowness(vec2(u_shadowPCFOffset, u_shadowPCFOffset)) +
getShadowness(vec2(-u_shadowPCFOffset, u_shadowPCFOffset)) +
getShadowness(vec2(u_shadowPCFOffset, -u_shadowPCFOffset)) +
getShadowness(vec2(-u_shadowPCFOffset, -u_shadowPCFOffset))) * 0.25;
}
void main() {
gl_FragColor.rgb = vec3(0.0,0.0,0.0);
gl_FragColor.a = (1.0 - getShadow()) * 0.2;
}