0 votes

I'm having trouble with texelFetch in one of my shaders:

texelfetch shader problem

I'm shading 12 square MeshInstances aranged in a kind of ring, each of which has 16x16 vertices (in the image you can see two of those "rings", an outer and an inner one). I'm using texelFetch to access a texture that contains a pixel for each vertex. The relevant part of the fragment shader is shown below (the rest of the shader doesn't do much; it just converts the VERTEX coordinates into coordinates for texture lookup).

texpos is a vec2 containing integral values for each axis ranging from 0 - 62 (actually, 1 - 62); these coordinates are all valid; otherwise we'd see bright yellow texels. It's calculated in the vertex shader and passed to the fragment shader using 'varying flat'. mymap is a sampler2D that refers to the colorful texture you see in the upper left corner of the above image (size 63x63 pixels).

vec3 texel_albedo(vec2 texpos) {
    ivec2 ipos = ivec2(texpos);
    if (ipos.x < 0 || ipos.x > 62 || ipos.y < 0 || ipos.y > 62) {
       // show yellow when trying to read a texel 
       // that's outside the texture
       return vec3(1.0, 1.0, 0.0);
    } else {
       vec4 col = texelFetch(mymap, ipos, 0);
       if (col.r * col.g * col.b == 0.0) {
           // show pink when 0 is read (shouldn't happen) 
           return vec3(1.0, 0.0, 1.0);
       } else {
           return vec3(col.r, col.g, col.b);

This shader produces pink glitches (1) at the right and bottom edges and also some other color errors in the middle on the left (2), but only when seen from certain angles. See short video for a demo of the problem.

The glitches only appear when I run the code on an integrated Intel UHD 630 graphics chip on Linux; they don't manifest themselves on a GTX 1060; nor do they manifest themselves on a slightly different Intel UHD 630 on Windows.

I can't explain the phenomenon. The texture coordinates are valid and stable, they don't depend on the view angle etc, so it seems like texelFetch actually yields wrong results in Godot v3.2.1stable.

Can anyone shed some light on this? Am I making a really stupid mistake? Is this a Godot problem, or an actual graphics driver bug? Is anyone else having trouble using texelFetch, maybe limited to Intel integrated graphics chips under Linux?

asked Jun 4 in Engine by archeron (26 points)
edited Jun 4 by archeron

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.