diff --git a/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/vertex/builder/ChunkMeshBufferBuilder.java b/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/vertex/builder/ChunkMeshBufferBuilder.java index 8218dfd67..e4dd0c449 100644 --- a/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/vertex/builder/ChunkMeshBufferBuilder.java +++ b/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/vertex/builder/ChunkMeshBufferBuilder.java @@ -32,7 +32,9 @@ public class ChunkMeshBufferBuilder { } public void push(ChunkVertexEncoder.Vertex[] vertices, Material material) { - postprocessVertices(vertices); + if (this.encoder.supportsBilinearCorrection()) { + postprocessVertices(vertices); + } var vertexStart = this.count * this.stride; var vertexSize = vertices.length * this.stride; diff --git a/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/vertex/format/ChunkVertexEncoder.java b/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/vertex/format/ChunkVertexEncoder.java index a9e32974e..1ac31f58d 100644 --- a/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/vertex/format/ChunkVertexEncoder.java +++ b/common/src/main/java/org/embeddedt/embeddium/impl/render/chunk/vertex/format/ChunkVertexEncoder.java @@ -5,6 +5,10 @@ import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material; public interface ChunkVertexEncoder { long write(long ptr, Material material, Vertex vertex, int sectionIndex); + default boolean supportsBilinearCorrection() { + return true; + } + class Vertex { public float x; public float y; diff --git a/common/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.fsh b/common/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.fsh index 82ba3bd72..99e67f640 100644 --- a/common/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.fsh +++ b/common/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.fsh @@ -5,7 +5,6 @@ in vec4 v_Color; in vec4 v_RdhFactor; in vec2 v_QuadCoord; -in vec3 v_LightColor; in vec2 v_TexCoord; #if defined(USE_FOG) && defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0 @@ -61,11 +60,10 @@ void main() { vec4 m_color = v_Color; // Apply correction factor to make the resulting color very close to what true bilinear interpolation would obtain + // min(x, y) * (1 - max(x, y)) == min(x, y) - (x * y) float correctionWeight = min(v_QuadCoord.x, v_QuadCoord.y) - * (1.0 - max(v_QuadCoord.x, v_QuadCoord.y)); - vec4 correction = v_RdhFactor * correctionWeight; - correction.rgb *= v_LightColor; - m_color += correction; + - (v_QuadCoord.x * v_QuadCoord.y); + m_color += v_RdhFactor * correctionWeight; #ifdef USE_VANILLA_COLOR_FORMAT // Apply per-vertex color. AO shade is applied ahead of time on the CPU. @@ -97,4 +95,4 @@ void main() { #else fragColor = diffuseColor; #endif -} \ No newline at end of file +} diff --git a/common/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.vsh b/common/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.vsh index 980aff6c9..8d502d516 100644 --- a/common/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.vsh +++ b/common/src/main/resources/assets/sodium/shaders/blocks/block_layer_opaque.vsh @@ -8,7 +8,6 @@ out vec4 v_Color; out vec4 v_RdhFactor; out vec2 v_QuadCoord; -out vec3 v_LightColor; out vec2 v_TexCoord; #if defined(USE_FOG) && defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0 @@ -61,15 +60,15 @@ void main() { gl_Position = u_ProjectionMatrix * u_ModelViewMatrix * vec4(position, 1.0); // Add the light color to the vertex color, and pass the texture coordinates to the fragment shader + v_RdhFactor = _vert_rdh_factor * 2.0; #ifdef CELERITAS_NO_LIGHTMAP v_Color = _vert_color; - v_LightColor = vec3(1.0); #else vec4 lightColor = _sample_lightmap(u_LightTex, _vert_tex_light_coord); v_Color = _vert_color * lightColor; - v_LightColor = lightColor.rgb; + v_RdhFactor.rgb *= lightColor.rgb; #endif - v_RdhFactor = _vert_rdh_factor * 2.0; + int corner = gl_VertexID & 3; v_QuadCoord = vec2(corner >= 2 ? 1.0 : 0.0, corner == 1 || corner == 2 ? 1.0 : 0.0); diff --git a/modern/src/main/shaders_java/net/irisshaders/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java b/modern/src/main/shaders_java/net/irisshaders/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java index ab2c42c6d..593dba30e 100644 --- a/modern/src/main/shaders_java/net/irisshaders/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java +++ b/modern/src/main/shaders_java/net/irisshaders/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java @@ -144,6 +144,11 @@ public class XHFPTerrainVertex implements ChunkVertexEncoder, ContextAwareChunkV this.ignoreMidBlock = false; } + @Override + public boolean supportsBilinearCorrection() { + return false; + } + @Override public long write(long ptr, Material material, Vertex vertex, int chunkId) { @@ -151,6 +156,7 @@ public class XHFPTerrainVertex implements ChunkVertexEncoder, ContextAwareChunkV vSum += vertex.v; vertexCount++; + vertex.rdhFactor = 0; this.baseEncoder.write(ptr, material, vertex, chunkId); MemoryUtil.memPutShort(ptr + MC_ENTITY_OFFSET + 2, renderType);