fix emission buffer writing & fix entity shader

This commit is contained in:
MihailRis 2025-07-12 23:28:38 +03:00
parent 3f3f48eb6d
commit 2831d1c963
6 changed files with 34 additions and 18 deletions

View File

@ -12,6 +12,7 @@ in vec3 a_position;
in vec3 a_realnormal;
in vec4 a_color;
in vec4 a_modelpos;
in float a_emission;
uniform sampler2D u_texture0;
uniform samplerCube u_skybox;
@ -24,14 +25,13 @@ uniform vec3 u_sunDir;
#include <shadows>
void main() {
float shadow = calc_shadow(a_modelpos, a_realnormal, a_distance);
vec4 texColor = texture(u_texture0, a_texCoord);
float alpha = a_color.a * texColor.a;
// anyway it's any alpha-test alternative required
if (alpha < (u_alphaClip ? 0.5f : 0.15f)) {
discard;
}
f_color = a_color * texColor * shadow;
f_color = a_color * texColor;
#ifndef ADVANCED_RENDER
vec3 fogColor = texture(u_skybox, a_dir).rgb;
@ -41,5 +41,5 @@ void main() {
f_color.a = alpha;
f_position = vec4(a_position, 1.0);
f_normal = vec4(a_normal, 1.0);
f_emission = vec4(0.0);
f_emission = vec4(vec3(a_emission), 1.0);
}

View File

@ -15,6 +15,7 @@ out vec3 a_position;
out vec3 a_realnormal;
out vec4 a_color;
out vec4 a_modelpos;
out float a_emission;
uniform mat4 u_model;
uniform mat4 u_proj;
@ -31,8 +32,6 @@ uniform float u_torchlightDistance;
#include <lighting>
#include <fog>
#define SKY_LIGHT_BRIGHTNESS_COMPENSATION 0.1
void main() {
a_modelpos = u_model * vec4(v_position, 1.0);
vec3 pos3d = a_modelpos.xyz - u_cameraPos;
@ -48,13 +47,14 @@ void main() {
a_texCoord = v_texCoord;
a_dir = a_modelpos.xyz - u_cameraPos;
vec3 skyLightColor = pick_sky_color(u_skybox) + SKY_LIGHT_BRIGHTNESS_COMPENSATION;
vec3 skyLightColor = pick_sky_color(u_skybox);
a_color.rgb = max(a_color.rgb, skyLightColor.rgb * v_light.a) * v_color;
a_color.a = u_opacity;
mat4 viewmodel = u_view * u_model;
a_distance = length(viewmodel * vec4(pos3d, 0.0));
a_fog = calc_fog(length(viewmodel * vec4(pos3d * FOG_POS_SCALE, 0.0)) / 256.0);
a_emission = v_normal.w;
vec4 viewmodelpos = u_view * a_modelpos;
a_position = viewmodelpos.xyz;

View File

@ -52,5 +52,5 @@ void main() {
f_color.a = alpha;
f_position = vec4(a_position, 1.0);
f_normal = vec4(a_normal, 1.0);
f_emission = vec4(a_emission);
f_emission = vec4(vec3(a_emission), 1.0);
}

View File

@ -64,7 +64,8 @@ public:
const glm::vec2& uv,
const glm::vec4& light,
const glm::vec3& tint,
const glm::vec3& normal
const glm::vec3& normal,
float emission
) {
MainBatchVertex* buffer = this->buffer.get();
buffer[index].position = pos;
@ -79,6 +80,7 @@ public:
buffer[index].normal[0] = static_cast<uint8_t>(normal.x * 128 + 127);
buffer[index].normal[1] = static_cast<uint8_t>(normal.y * 128 + 127);
buffer[index].normal[2] = static_cast<uint8_t>(normal.z * 128 + 127);
buffer[index].normal[3] = static_cast<uint8_t>(emission * 255);
index++;
}
@ -90,7 +92,8 @@ public:
const glm::vec2& size,
const glm::vec4& light,
const glm::vec3& tint,
const UVRegion& subregion
const UVRegion& subregion,
float emission = 0.0f
) {
prepare(6);
vertex(
@ -98,21 +101,24 @@ public:
{subregion.u1, subregion.v1},
light,
tint,
normal
normal,
emission
);
vertex(
pos + right * size.x * 0.5f - up * size.y * 0.5f,
{subregion.u2, subregion.v1},
light,
tint,
normal
normal,
emission
);
vertex(
pos + right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u2, subregion.v2},
light,
tint,
normal
normal,
emission
);
vertex(
@ -120,21 +126,24 @@ public:
{subregion.u1, subregion.v1},
light,
tint,
normal
normal,
emission
);
vertex(
pos + right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u2, subregion.v2},
light,
tint,
normal
normal,
emission
);
vertex(
pos - right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u1, subregion.v2},
light,
tint,
normal
normal,
emission
);
}

View File

@ -85,7 +85,14 @@ void ModelBatch::draw(
d = glm::dot(norm, SUN_VECTOR);
d = 0.8f + d * 0.2f;
}
batch->vertex(matrix * glm::vec4(vert.coord, 1.0f), vert.uv, lights*d, tint, norm);
batch->vertex(
matrix * glm::vec4(vert.coord, 1.0f),
vert.uv,
lights * d,
tint,
norm,
mesh.lighting ? 0.0f : 1.0f
);
}
}
}

View File

@ -117,7 +117,6 @@ void ParticlesRenderer::renderParticles(const Camera& camera, float delta) {
light *= 0.9f + (particle.random % 100) * 0.001f;
}
glm::vec3 localRight = right;
glm::vec3 localUp = preset.globalUpVector ? glm::vec3(0, 1, 0) : up;
float angle = particle.angle;
@ -138,7 +137,8 @@ void ParticlesRenderer::renderParticles(const Camera& camera, float delta) {
preset.size * scale,
light,
glm::vec3(1.0f),
particle.region
particle.region,
preset.lighting ? 0.0f : 1.0f
);
if (particle.lifetime <= 0.0f) {
iter = vec.erase(iter);