prosperon/shaders/sprite_ssbo.cg

58 lines
724 B
Plaintext

@vs vs
in vec3 a_pos;
in vec2 a_uv;
out vec2 uv;
out vec4 shade;
vec3 pos;
struct sprite {
mat4 model;
vec4 rect;
vec4 shade;
};
readonly buffer ssbo {
sprite sprites[];
};
uniform mat4 vp;
uniform float baseinstance;
void main()
{
sprite s = sprites[int(baseinstance)+gl_InstanceIndex];
pos = a_pos;
uv = a_uv;
uv = (uv*s.rect.zw)+s.rect.xy;
gl_Position = vp * s.model * vec4(pos, 1.0);
shade = s.shade;
}
@end
@fs fs
in vec2 uv;
in vec4 shade;
out vec4 color;
texture2D diffuse;
@sampler_type smp nonfiltering
sampler smp;
void frag()
{
color = texture(sampler2D(diffuse,smp), uv);
color *= shade;
if (color.a == 0.0) discard;
}
void main()
{
frag();
}
@end
@program sprite vs fs