Another how to integrate this WebGL code to C2

For developers using the Construct 2 Javascript SDK

Post » Tue Mar 05, 2013 6:42 pm

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 http://www.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);
}      
B
11
S
5
G
3
Posts: 19
Reputation: 2,969

Post » Wed Mar 06, 2013 11:21 am

@XGDragon : I didn't add the shadow part because Matt Greer didn't go deep enough in the second part. I asked him by mail about the implementation, and he told me that when he's going to have some time, the text would be expanded.
In the meantime, I'm overworked myself (in my videogame company), so I can't start it without hints from him.
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Wed Mar 06, 2013 11:37 am

Ah alright, great to hear! Hopefully we can see on it updates soon! Thanks for the 2D lighting, it's beautiful.
B
11
S
5
G
3
Posts: 19
Reputation: 2,969


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests