All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bladecoder.engine.shading.floor.fragment.glsl Maven / Gradle / Ivy

There is a newer version: 4.3.1
Show newest version
// 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;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy