clamp and srcOriginStart / srcOriginEnd

0 favourites
  • 3 posts
  • Ashley

    I think I have found out the reason I was having an issue with using clamp(uv, srcOriginStart, srcOriginEnd) when a predraw was being done with an effect (e.g. <100% opacity or an effect stack.) In this case srcOriginEnd.y was less than srcOriginStart.y. The clamp still worked fine on MacOS Chrome, however, it worked differently on iOS. It looks like it's because the glsl clamp function is being implemented differently on different platforms (OS/browser/GPU/driver.)

    Here's an example and discussion:

    shadertoy.com/view/Ms33R4

    I get different results in iOS/Safari/iPhone and MacOS/Chrome/Radeon.

    So, for cross-platform and predraw / non-predraw compatibility, I will probably use this method:

     #define clampX(x,a,b) min(max(x,min(a,b)),max(a,b))
    

    From the discussion on shadertoy (from my experience, iOS also does the OpenGL spec version.)

    It seems like it's implemented in a few different ways (guessed based on how you described them):

    #define clamp(x,a,b) min(max(x,a),b) //OpenGL spec (3 gradients, 2nd black)

    #define clamp(x,a,b) max(min(x,b),a) //Linux (2 white bars in the middle)

    #define clamp(x,a,b) min(max(x,min(a,b)),max(a,b)) //Windows (4 gradients)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It looks like a WebGL or GPU driver bug. You should probably report it to Google and any other browser vendors where it reproduces.

  • The buggy versions that do not follow the spec actually make it possible to use clamp(uv, srcOriginStart, srcOriginEnd) in the C3 predraw case.

    The versions that follow the WebGL spec do not work with the C3 predraw case where srcOriginStart.y > srcOriginEnd.y. The webgl spec is: min(max(x, minVal), maxVal).

    So, if the bugs were fixed to match the OpenGL spec, then clamp(uv, srcOriginStart, srcOriginEnd) could not be used with C3 in the predraw case on any platform.

    I think to handle the variable C3 behavior between predraw and no predraw, clamp and platform variance, for effect distortions where vTex is changed, I will use must predraw and also my own definition of clamp.

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