Add entity shaders
This commit is contained in:
parent
6ac5b10b93
commit
ee384f2355
2 changed files with 61 additions and 0 deletions
13
shaders/entity.frag
Normal file
13
shaders/entity.frag
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#version 430
|
||||||
|
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec3 fragColor;
|
||||||
|
|
||||||
|
uniform sampler2D circleTexture;
|
||||||
|
|
||||||
|
out vec4 finalColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float alpha = texture(circleTexture, fragTexCoord).r;
|
||||||
|
finalColor = vec4(fragColor, alpha);
|
||||||
|
}
|
||||||
48
shaders/entity.vert
Normal file
48
shaders/entity.vert
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
#version 430
|
||||||
|
|
||||||
|
// quad corner position (-0.5 to 0.5)
|
||||||
|
layout(location = 0) in vec2 position;
|
||||||
|
layout(location = 1) in vec2 texCoord;
|
||||||
|
|
||||||
|
// entity data from SSBO
|
||||||
|
struct Entity {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
uint color;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(std430, binding = 0) readonly buffer EntityData {
|
||||||
|
Entity entities[];
|
||||||
|
};
|
||||||
|
|
||||||
|
// screen size for NDC conversion
|
||||||
|
uniform vec2 screenSize;
|
||||||
|
|
||||||
|
out vec2 fragTexCoord;
|
||||||
|
out vec3 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// get entity data from SSBO
|
||||||
|
Entity e = entities[gl_InstanceID];
|
||||||
|
|
||||||
|
// convert entity position to NDC
|
||||||
|
// entity coords are in screen pixels, convert to [-1, 1]
|
||||||
|
float ndcX = (e.x / screenSize.x) * 2.0 - 1.0;
|
||||||
|
float ndcY = (e.y / screenSize.y) * 2.0 - 1.0;
|
||||||
|
|
||||||
|
// quad size in NDC (16 pixels)
|
||||||
|
float quadSizeNdc = 16.0 / screenSize.x;
|
||||||
|
|
||||||
|
// offset by quad corner position
|
||||||
|
gl_Position = vec4(ndcX + position.x * quadSizeNdc,
|
||||||
|
ndcY + position.y * quadSizeNdc,
|
||||||
|
0.0, 1.0);
|
||||||
|
|
||||||
|
// extract RGB from packed color (0xRRGGBB)
|
||||||
|
float r = float((e.color >> 16u) & 0xFFu) / 255.0;
|
||||||
|
float g = float((e.color >> 8u) & 0xFFu) / 255.0;
|
||||||
|
float b = float(e.color & 0xFFu) / 255.0;
|
||||||
|
fragColor = vec3(r, g, b);
|
||||||
|
|
||||||
|
fragTexCoord = texCoord;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue