How to access texelFetch (and other GLSL shader functions)

Hi there

I’m a noob messing with shaders so I apologise if I’m missing something huge.

I’m trying to implement the GLSL 3.0 ES helper function ‘texelFetch’ to no avail. I’ve tried setting the version (at the top of the shader file) to 300 es but that starts throwing all kinds of definition errors.

I see here in a WebGL2.0 update, that PlayCanvas advises against using certain reserved names as variables, such as texelFetch.

Does anyone know how to access these advanced methods in PlayCanvas shader files?

Thanks!

Code for those interested:

Vertex:


attribute vec3 a_position;
attribute vec2 a_texCoord0;

uniform mat4 matrix_model;
uniform mat4 matrix_viewProjection;

varying vec2 v_texCoords;

void main()
{
	v_texCoords = a_texCoord0;
    gl_Position = matrix_viewProjection * matrix_model * vec4(a_position, 1);
}

Fragment:

varying vec2 v_texCoords;

uniform sampler2D u_texture;

mat3 sx = mat3( 
    1.0, 2.0, 1.0, 
    0.0, 0.0, 0.0, 
   -1.0, -2.0, -1.0 
);
mat3 sy = mat3( 
    1.0, 0.0, -1.0, 
    2.0, 0.0, -2.0, 
    1.0, 0.0, -1.0 
);

void main()
{
    vec3 diffuse = texture2D(u_texture, v_texCoords.st).rgb;
    mat3 I;
    for (int i=0; i<3; i++) {
        for (int j=0; j<3; j++) {
            vec3 sample  = texelFetch(u_texture, ivec2(gl_FragCoord) + ivec2(i-1,j-1), 0 ).rgb;
            I[i][j] = length(sample); 
        }
    }

    float gx = dot(sx[0], I[0]) + dot(sx[1], I[1]) + dot(sx[2], I[2]); 
    float gy = dot(sy[0], I[0]) + dot(sy[1], I[1]) + dot(sy[2], I[2]);

    float g = sqrt(pow(gx, 2.0)+pow(gy, 2.0));
    gl_FragColor = vec4(diffuse - vec3(g), 1.0);
}

One for @Mr_F perhaps?

Thanks for replying, @dave.

Mr_F has already helped here: WebGL 2.0 and Engine release notes v0.207 [22.02.16]

I will post results once I test it!