Shader giving error output

Godot Version

4.4.1

Question

Hi! I found a cool shadow shader and added it to my game, but it gives me the error Index amount (16) must be a multiple of the amount of indices required by the render primitive (3) and i don’t understand what it is trying to say. The shader is assigned to a shader material inside a polygon2D

shader_type canvas_item;
render_mode unshaded;

uniform vec4 color : source_color; 
uniform float angle : hint_range(0,360); 
uniform float max_dist : hint_range(0,1000) = 100; 
uniform sampler2D gradientTexture;

vec4 get_gradient_color(float position) { 
    return texture(gradientTexture, vec2(position, 0.5)); 
}

void fragment() { 
    float ang_rad = angle * PI / 180.0;
    vec2 dir = vec2(sin(ang_rad),cos(ang_rad)); 
    vec2 at = screen_uv_to_sdf(SCREEN_UV); 
    float accum = 0.0;
    while(accum < max_dist) {
        float d = texture_sdf(at);
        accum+=d;
        if (d < 0.01) {
            break;
        }
        at += d * dir;
    }
    float alpha = 1.0-min(1.0,accum/max_dist);
    
    // the gradient controls the falloff of the shadow
    alpha = get_gradient_color(alpha).r;
    
    COLOR = vec4(color.rgb,alpha * color.a);
}

This is where i got the shader

I don’t know what i did but i managed to fix it

1 Like

FWIW, the error is telling you that you have something has primitives that require 3 values, and you have 16 values in the set, so there’s an orphan value at the end:

 0 - primitive 0, index 0
 1 - primitive 0, index 1
 2 - primitive 0, index 2
 3 - primitive 1, index 0
 4 - primitive 1, index 1
 5 - primitive 1, index 2
 6 - primitive 2, index 0
 7 - primitive 2, index 1
 8 - primitive 2, index 2
 9 - primitive 3, index 0
10 - primitive 3, index 1
11 - primitive 3, index 2
12 - primitive 4, index 0
13 - primitive 4, index 1
14 - primitive 4, index 2
15 - primitive 5, index 0 -- MISSING indices 1 and 2!?!

Primitive 5 is missing two of the required indices, which probably actually means it was junk that was accidentally appended, though it could also mean the list was truncated.

If you have something like this, the number of indices should be an integer multiple of the number of primitives. The error message is perhaps a bit confusingly worded, but that’s what it’s trying to tell you; the number of indices is not a clean multiple of the number of indices per primitive, so the end of the list either doesn’t have enough information, or has too much.

1 Like

Alright, thank you!