add emission gbuffer attachment

This commit is contained in:
MihailRis
2025-07-12 21:09:23 +03:00
parent 8a3306ed41
commit 5ec9f14021
12 changed files with 101 additions and 31 deletions
+23 -16
View File
@@ -39,9 +39,13 @@ BlocksRenderer::~BlocksRenderer() {
/// Basic vertex add method
void BlocksRenderer::vertex(
const glm::vec3& coord, float u, float v, const glm::vec4& light, const glm::vec3& normal
const glm::vec3& coord,
float u,
float v,
const glm::vec4& light,
const glm::vec3& normal,
float emission
) {
vertexBuffer[vertexCount].position = coord;
vertexBuffer[vertexCount].uv = {u,v};
@@ -49,11 +53,13 @@ void BlocksRenderer::vertex(
vertexBuffer[vertexCount].normal[0] = static_cast<uint8_t>(normal.r * 127 + 128);
vertexBuffer[vertexCount].normal[1] = static_cast<uint8_t>(normal.g * 127 + 128);
vertexBuffer[vertexCount].normal[2] = static_cast<uint8_t>(normal.b * 127 + 128);
vertexBuffer[vertexCount].normal[3] = static_cast<uint8_t>(emission * 255);
vertexBuffer[vertexCount].color[0] = static_cast<uint8_t>(light.r * 255);
vertexBuffer[vertexCount].color[1] = static_cast<uint8_t>(light.g * 255);
vertexBuffer[vertexCount].color[2] = static_cast<uint8_t>(light.b * 255);
vertexBuffer[vertexCount].color[3] = static_cast<uint8_t>(light.a * 255);
vertexCount++;
}
@@ -86,10 +92,10 @@ void BlocksRenderer::face(
auto Y = axisY * h;
auto Z = axisZ * d;
float s = 0.5f;
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, lights[0] * tint, axisZ);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, lights[1] * tint, axisZ);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, lights[2] * tint, axisZ);
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, lights[3] * tint, axisZ);
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, lights[0] * tint, axisZ, 0);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, lights[1] * tint, axisZ, 0);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, lights[2] * tint, axisZ, 0);
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, lights[3] * tint, axisZ, 0);
index(0, 1, 3, 1, 2, 3);
}
@@ -107,7 +113,7 @@ void BlocksRenderer::vertexAO(
axisX,
axisY
);
vertex(coord, u, v, light * tint, axisZ);
vertex(coord, u, v, light * tint, axisZ, 0.0f);
}
void BlocksRenderer::faceAO(
@@ -140,10 +146,10 @@ void BlocksRenderer::faceAO(
} else {
auto axisZ = glm::normalize(Z);
glm::vec4 tint(1.0f);
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, axisZ);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint, axisZ);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint, axisZ);
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, tint, axisZ);
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, axisZ, 1);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint, axisZ, 1);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint, axisZ, 1);
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, tint, axisZ, 1);
}
index(0, 1, 2, 0, 2, 3);
}
@@ -168,10 +174,10 @@ void BlocksRenderer::face(
d = (1.0f - DIRECTIONAL_LIGHT_FACTOR) + d * DIRECTIONAL_LIGHT_FACTOR;
tint *= d;
}
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, Z);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint, Z);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint, Z);
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, tint, Z);
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, Z, lights ? 0 : 1);
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint, Z, lights ? 0 : 1);
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint, Z, lights ? 0 : 1);
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, tint, Z, lights ? 0 : 1);
index(0, 1, 2, 0, 2, 3);
}
@@ -345,7 +351,8 @@ void BlocksRenderer::blockCustomModel(
vertex.uv.x,
vertex.uv.y,
glm::vec4(d, d, d, d) * aoColor,
n
n,
0.0f
);
indexBuffer[indexCount++] = vertexOffset++;
}