I'm getting "Definition for "void main()" not found." error when using this shader code

I’m getting “Definition for “void main()” not found.” error when using this shader code.

    struct LocalConstants {
    mat4                    view_projection_matrix;

    float                   time;
    float                   sprite_size;
    float                   alpha_threshold;
    uint                    filter_type;

    vec4                    screen_size;

    float                   filter_width;
    float                   camera_scale;
    float                   texels_per_pixel;
    uint                    premultiplied;
};

layout (std140, binding=0)
uniform Local{
    LocalConstants  locals;
};

// The default size, in pixels, of the antialiasing filter. The default is 1.0 for a mathematically perfect
// antialias. But if you want, you can increase this to 1.5, 2.0, 3.0 and such to force a bigger antialias zone
// than normal, using more screen pixels.
float SMOOTH_SIZE = locals.filter_width;
float _HALF_SMOOTH = SMOOTH_SIZE / 2.0;

#if defined VERTEX
layout (location = 0) in vec4 position;
layout (location = 1) in vec4 uv_size_offset;
layout (location = 2) in vec2 size;

layout (location = 0) out vec2 uv;

layout (binding = 1) uniform sampler2D albedo;

// Per vertex positions and uvs of a quad
vec3 positions[6]       = vec3[6]( vec3(-0.5,-0.5,0), vec3(0.5,-0.5,0), vec3(0.5, 0.5, 0), vec3(0.5, 0.5, 0), vec3(-0.5,0.5,0), vec3(-0.5,-0.5,0) );
vec2 uvs[6]             = vec2[6]( vec2(0.0, 1.0),    vec2(1.0, 1.0),   vec2(1.0, 0.0), vec2(1.0, 0.0), vec2(0.0, 0.0), vec2(0.0, 1.0) );

void main() {

    ivec2 texture_size = textureSize(albedo, 0);

    const uint vertex_index = gl_VertexID % 6;

    uv = uvs[vertex_index] * uv_size_offset.xy + uv_size_offset.zw;

    vec4 world_position = vec4( vec2(positions[ vertex_index ].xy * size * locals.sprite_size), 0, 1 );
    world_position.xyz += vec3(position.xy * locals.sprite_size, position.z);

    gl_Position = locals.view_projection_matrix * world_position;
}
    #endif // VERTEX

I don’t get this error when I use “ShaderProgram.pedantic = false;” but “shaderProgram.isCompiled()” still returns false.

and of course when I do “batch.setShader(shaderProgram)” the batch doesn’t work correctly

Try any spv compiler, below is an example and binaries are available too

Also if you don’t define VERTEX there is main defined

1 Like