Skip to content

Commit

Permalink
add sbuftex-sapp.glsl test shader
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Oct 8, 2024
1 parent ba11ffd commit 5688dd1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/sapp/sbuftex-sapp.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@ctype mat4 hmm_mat4

@vs vs
layout(binding=0) uniform vs_params {
mat4 mvp;
};

struct sb_vertex {
vec3 pos;
uint idx;
vec2 uv;
};

layout(binding=0) readonly buffer vertices {
sb_vertex vtx[];
};

out vec3 uv_idx;

void main() {
gl_Position = mvp * vec4(vtx[gl_VertexIndex].pos, 1.0);
// need to add a bit of wiggle room here to prevent a precision problem on NVIDIA
// down in the pixel shader
uv_idx = vec3(vtx[gl_VertexIndex].uv, float(vtx[gl_VertexIndex].idx) + 0.5);
}
@end

@fs fs
layout(binding=0) uniform texture2D tex;
layout(binding=0) uniform sampler smp;

struct sb_color {
vec4 color;
};

layout(binding=1) readonly buffer colors {
sb_color clr[];
};

in vec3 uv_idx;
out vec4 frag_color;

void main() {
uint idx = uint(uv_idx.z);
vec2 uv = uv_idx.xy;
frag_color = vec4(texture(sampler2D(tex,smp), uv).xxx, 1.0) * clr[idx].color;
}
@end

@program sbuftex vs fs

0 comments on commit 5688dd1

Please sign in to comment.