oomek / attractplus

Attract-Mode Plus
GNU General Public License v3.0
49 stars 16 forks source link

Missing image breaks vertex shaders #64

Closed Chadnaut closed 1 month ago

Chadnaut commented 7 months ago

When an image fails to load (ie: no file) all subsequent object vertices change order. This makes it impossible to use vertex shaders that rely on vertex order.

Normal: [tl, bl, tr, br] Broken: [br, tl, bl, tr]

Successfully adding another object appears to fix the broken ordering. It seems something isn't getting cleaned up after a failed load.

layout.nut

// local bad_img = fe.add_image("bad_name.png");
// local fix1 = fe.add_artwork("snap", 0, 0, 50, 50);
// local fix2 = fe.add_text("Maybe", 0, 0, 400, 50); // AM, not AM+
// local fix3 = fe.add_text("LongerText", 0, 0, 400, 50);

local img = fe.add_artwork("snap", 50, 50, 400, 400);
img.shader = fe.add_shader(Shader.VertexAndFragment, "shader.vert", "shader.frag");

shader.frag

#version 120
uniform sampler2D texture;
void main() {
    gl_FragColor = gl_Color * vec4(1,0,0,1);
}

shader.vert

#version 120
#extension GL_EXT_gpu_shader4 : require
void main() {
    vec2[4] offset = vec2[](vec2(0,50), vec2(50,0), vec2(-50,0), vec2(0,-50));
    gl_Position = gl_ModelViewProjectionMatrix * (gl_Vertex + vec4(offset[gl_VertexID % 4], 0.0, 0.0));
    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
    gl_FrontColor = gl_Color;
}

Attract-Mode Plus v3.0.8, Attract-Mode v2.7.0

Chadnaut commented 1 month ago

This issue appears to affect certain hardware and/or drivers:

oomek commented 1 month ago

Closing for now