slightly faster bilinear interpolation #33
No files matched your search
+3
-1
@@ -32,7 +32,9 @@ public class ChunkMeshBufferBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void push(ChunkVertexEncoder.Vertex[] vertices, Material material) {
|
public void push(ChunkVertexEncoder.Vertex[] vertices, Material material) {
|
||||||
postprocessVertices(vertices);
|
if (this.encoder.supportsBilinearCorrection()) {
|
||||||
|
postprocessVertices(vertices);
|
||||||
|
}
|
||||||
|
|
||||||
var vertexStart = this.count * this.stride;
|
var vertexStart = this.count * this.stride;
|
||||||
var vertexSize = vertices.length * this.stride;
|
var vertexSize = vertices.length * this.stride;
|
||||||
|
|||||||
+4
@@ -5,6 +5,10 @@ import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
|||||||
public interface ChunkVertexEncoder {
|
public interface ChunkVertexEncoder {
|
||||||
long write(long ptr, Material material, Vertex vertex, int sectionIndex);
|
long write(long ptr, Material material, Vertex vertex, int sectionIndex);
|
||||||
|
|
||||||
|
default boolean supportsBilinearCorrection() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
class Vertex {
|
class Vertex {
|
||||||
public float x;
|
public float x;
|
||||||
public float y;
|
public float y;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
in vec4 v_Color;
|
in vec4 v_Color;
|
||||||
in vec4 v_RdhFactor;
|
in vec4 v_RdhFactor;
|
||||||
in vec2 v_QuadCoord;
|
in vec2 v_QuadCoord;
|
||||||
in vec3 v_LightColor;
|
|
||||||
in vec2 v_TexCoord;
|
in vec2 v_TexCoord;
|
||||||
|
|
||||||
#if defined(USE_FOG) && defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0
|
#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;
|
vec4 m_color = v_Color;
|
||||||
// Apply correction factor to make the resulting color very close to what true bilinear interpolation would obtain
|
// 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)
|
float correctionWeight = min(v_QuadCoord.x, v_QuadCoord.y)
|
||||||
* (1.0 - max(v_QuadCoord.x, v_QuadCoord.y));
|
- (v_QuadCoord.x * v_QuadCoord.y);
|
||||||
vec4 correction = v_RdhFactor * correctionWeight;
|
m_color += v_RdhFactor * correctionWeight;
|
||||||
correction.rgb *= v_LightColor;
|
|
||||||
m_color += correction;
|
|
||||||
|
|
||||||
#ifdef USE_VANILLA_COLOR_FORMAT
|
#ifdef USE_VANILLA_COLOR_FORMAT
|
||||||
// Apply per-vertex color. AO shade is applied ahead of time on the CPU.
|
// Apply per-vertex color. AO shade is applied ahead of time on the CPU.
|
||||||
@@ -97,4 +95,4 @@ void main() {
|
|||||||
#else
|
#else
|
||||||
fragColor = diffuseColor;
|
fragColor = diffuseColor;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
out vec4 v_Color;
|
out vec4 v_Color;
|
||||||
out vec4 v_RdhFactor;
|
out vec4 v_RdhFactor;
|
||||||
out vec2 v_QuadCoord;
|
out vec2 v_QuadCoord;
|
||||||
out vec3 v_LightColor;
|
|
||||||
out vec2 v_TexCoord;
|
out vec2 v_TexCoord;
|
||||||
|
|
||||||
#if defined(USE_FOG) && defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0
|
#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);
|
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
|
// 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
|
#ifdef CELERITAS_NO_LIGHTMAP
|
||||||
v_Color = _vert_color;
|
v_Color = _vert_color;
|
||||||
v_LightColor = vec3(1.0);
|
|
||||||
#else
|
#else
|
||||||
vec4 lightColor = _sample_lightmap(u_LightTex, _vert_tex_light_coord);
|
vec4 lightColor = _sample_lightmap(u_LightTex, _vert_tex_light_coord);
|
||||||
v_Color = _vert_color * lightColor;
|
v_Color = _vert_color * lightColor;
|
||||||
v_LightColor = lightColor.rgb;
|
v_RdhFactor.rgb *= lightColor.rgb;
|
||||||
#endif
|
#endif
|
||||||
v_RdhFactor = _vert_rdh_factor * 2.0;
|
|
||||||
int corner = gl_VertexID & 3;
|
int corner = gl_VertexID & 3;
|
||||||
v_QuadCoord = vec2(corner >= 2 ? 1.0 : 0.0,
|
v_QuadCoord = vec2(corner >= 2 ? 1.0 : 0.0,
|
||||||
corner == 1 || corner == 2 ? 1.0 : 0.0);
|
corner == 1 || corner == 2 ? 1.0 : 0.0);
|
||||||
|
|||||||
+6
@@ -144,6 +144,11 @@ public class XHFPTerrainVertex implements ChunkVertexEncoder, ContextAwareChunkV
|
|||||||
this.ignoreMidBlock = false;
|
this.ignoreMidBlock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsBilinearCorrection() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long write(long ptr,
|
public long write(long ptr,
|
||||||
Material material, Vertex vertex, int chunkId) {
|
Material material, Vertex vertex, int chunkId) {
|
||||||
@@ -151,6 +156,7 @@ public class XHFPTerrainVertex implements ChunkVertexEncoder, ContextAwareChunkV
|
|||||||
vSum += vertex.v;
|
vSum += vertex.v;
|
||||||
vertexCount++;
|
vertexCount++;
|
||||||
|
|
||||||
|
vertex.rdhFactor = 0;
|
||||||
this.baseEncoder.write(ptr, material, vertex, chunkId);
|
this.baseEncoder.write(ptr, material, vertex, chunkId);
|
||||||
|
|
||||||
MemoryUtil.memPutShort(ptr + MC_ENTITY_OFFSET + 2, renderType);
|
MemoryUtil.memPutShort(ptr + MC_ENTITY_OFFSET + 2, renderType);
|
||||||
|
|||||||
Reference in new issue
Block a user