2D rendering (big feature)

This commit is contained in:
Halbear 2026-08-14 22:22:03 +01:00
parent 6d7ea4ebc5
commit 5a05b9d65e
21 changed files with 1075 additions and 22 deletions

View file

@ -0,0 +1,25 @@
#version 450
const int MAX_TEXTURES = 128;
const float GAMMA_CONST = 0.4545;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
layout(push_constant) uniform pc {
layout(offset = 24) uint textureIndex;
} push_constants;
layout(set = 1, binding = 0) uniform sampler2D spriteTextures[MAX_TEXTURES];
vec4 gamma(vec4 color){
return color = vec4(pow(color.rgb,vec3(GAMMA_CONST)),color.a);
}
void main() {
vec4 tex = texture(spriteTextures[push_constants.textureIndex], inUV);
outColor = gamma(tex);
if (outColor.a <= 0.09) {
discard;
}
}

View file

@ -0,0 +1,19 @@
#version 450
const int MAX_TEXTURES = 128;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
layout(push_constant) uniform pc {
layout(offset = 24) uint textureIndex;
} push_constants;
layout(set = 1, binding = 0) uniform sampler2D spriteTextures[MAX_TEXTURES];
void main() {
vec4 tex = texture(spriteTextures[push_constants.textureIndex], inUV);
outColor = tex;
if(outColor.a >= 0.9 || outColor.a <= 0.001){discard;}
}

View file

@ -0,0 +1,36 @@
#version 450
layout(location = 0) in vec2 inPos;
layout(location = 1) in vec2 inUV;
layout(location = 0) out vec2 outUV;
layout(push_constant) uniform pc {
vec2 modelSize;
vec2 position;
vec2 screenSize;
} push_constants;
layout(set = 0, binding = 0) uniform ViewUniform{
vec2 camPos;
vec2 camScale;
} viewUniform;
void main() {
vec2 ScaledPos = inPos * push_constants.modelSize;
vec2 worldPos = push_constants.position + ScaledPos;
worldPos += viewUniform.camPos;
vec2 ndc = vec2(
(worldPos.x / push_constants.screenSize.x) * 2.0 - 1.0,
(worldPos.y / push_constants.screenSize.y) * 2.0 - 1.0
);
ndc.y = -ndc.y;
gl_Position = vec4(ndc * viewUniform.camScale, 0.0, 1.0);
outUV = vec2(inUV.x, 1 - inUV.y);
}

View file

@ -153,5 +153,5 @@ void main() {
outFragColor = vec4(albedo,1.0f);
return;
}
// outFragColor = vec4(normal, 1.0f);
}