Another how to integrate this WebGL code to C2

0 favourites
  • 3 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • 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);

    }

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ah alright, great to hear! Hopefully we can see on it updates soon! Thanks for the 2D lighting, it's beautiful.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)