This commit is contained in:
2025-01-02 05:15:16 +03:00
parent 3c66a65b40
commit ac00eb18a9
96 changed files with 384134 additions and 230 deletions

View File

@@ -11,7 +11,7 @@ layout (location = 3) in int aTextureId;
layout (location = 4) in mat4 aModelMatrix;
layout (location = 0) out vec2 oUV;
layout (location = 1) out int oTextureId;
layout (location = 1) flat out int oTextureId;
layout (location = 2) out vec3 oNormal;
void main()
@@ -35,7 +35,7 @@ layout (location = 0) out vec4 FragColor;
void main()
{
vec3 lightColor = vec3(iUV, 0);
vec3 lightColor = vec3(1);
FragColor = vec4(lightColor, 1.0);
if (iTextureId >= 0)
FragColor *= texture(uTexture[iTextureId], iUV);

View File

@@ -12,7 +12,7 @@ layout (location = 4) in mat4 aModel;
layout (location = 0) out vec4 oColor;
layout (location = 1) out vec2 oUV;
layout (location = 2) out int oTextureId;
layout (location = 2) flat out int oTextureId;
void main()
{

View File

@@ -0,0 +1,61 @@
// #type vertex
#version 460 core
uniform mat4 u_Projection;
uniform mat4 u_View;
layout (location = 0) in vec4 a_Position;
layout (location = 1) in vec2 a_UV;
layout (location = 2) in vec4 a_Color;
layout (location = 3) in int a_AtlasId;
layout (location = 4) in vec2 a_UnitRange;
layout (location = 5) in mat4 a_Model;
layout (location = 0) out vec4 o_Color;
layout (location = 1) out vec2 o_UV;
layout (location = 2) flat out int o_AtlasId;
layout (location = 3) flat out vec2 o_UnitRange;
void main()
{
o_Color = a_Color;
o_UV = a_UV;
o_AtlasId = a_AtlasId;
o_UnitRange = a_UnitRange;
gl_Position = u_Projection * u_View * a_Model * a_Position;
}
// #type fragment
#version 460 core
uniform sampler2D u_Atlas[16];
layout (location = 0) in vec4 i_Color;
layout (location = 1) in vec2 i_UV;
layout (location = 2) flat in int i_AtlasId;
layout (location = 3) flat in vec2 i_UnitRange;
layout (location = 0) out vec4 FragColor;
float median(float r, float g, float b) {
return max(min(r, g), min(max(r, g), b));
}
float screenPxRange() {
vec2 screenTexSize = vec2(1.0) / fwidth(i_UV);
return max(0.5 * dot(i_UnitRange, screenTexSize), 1.0);
}
void main()
{
vec3 msd = texture(u_Atlas[i_AtlasId], i_UV).rgb;
float sd = median(msd.r, msd.g, msd.b);
float screenPxDistance = screenPxRange() * (sd - 0.5);
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
// this is a temporary solution for TODO: fix depth test self discard on overlap
if (opacity == 0.0) {
discard;
}
FragColor = mix(vec4(0), i_Color, opacity);
}