-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |