Using Pode's sprite lighting effect, the same article continues on creating shadow effects. I was wondering why Pode didn't expand to this too, and more importantly, if its possible to get this code to work in C2? I tried it myself but all I got were either bugs or just no effect.
From mattgreer.org/post/4dynamicLightingShadows
________________________________________________________________________
#ifdef GL_ES
precision highp float;
#endif
vec2 extrude(vec2 other, float angle, float length) {
float x = length * cos(angle);
float y = length * sin(angle);
return vec2(other.x + x, other.y + y);
}
float getHeightAt(vec2 texCoord, float xyAngle, float distance,
sampler2D heightMap) {
vec2 newTexCoord = extrude(texCoord, xyAngle, distance);
return texture2D(heightMap, newTexCoord).r;
}
float getTraceHeight(float height, float zAngle, float distance) {
return distance * tan(zAngle) + height;
}
bool isInShadow(float xyAngle, float zAngle, sampler2D heightMap,
vec2 texCoord, float step) {
float distance;
float height;
float otherHeight;
float traceHeight;
height = texture2D(heightMap, texCoord).r;
for(int i = 0; i < 100; ++i) {
distance = step * float(i);
otherHeight = getHeightAt(texCoord, xyAngle, distance, heightMap);
if(otherHeight > height) {
traceHeight = getTraceHeight(height, zAngle, distance);
if(traceHeight <= otherHeight) {
return true;
}
}
}
return false;
}
varying vec2 vTextureCoord;
uniform sampler2D uHeightMap;
uniform float uXYAngle;
uniform float uZAngle;
uniform int uMaxShadowSteps;
uniform float uTexStep;
void main(void) {
float alpha = 0.0;
if(isInShadow(uXYAngle, uZAngle, uHeightMap, uMaxShadowSteps,
vTextureCoord, uTexStep)) {
alpha = 0.5;
}
gl_FragColor = vec4(0, 0, 0, alpha);
}