Bilinear interpolation for quad vertex data via geometry shader #12

Closed
embeddedt wants to merge 18 commits from geotesting into stonecutter
pull from: geotesting
10 changed files with 47 additions and 14 deletions
Showing only changes of commit 967cd5f909 - Show all commits

No files matched your search

@@ -80,9 +80,6 @@ public class DefaultChunkRenderer extends ShaderChunkRenderer {
var primitiveType = shader.getPrimitiveType();
// TODO: [VEN][GEO-NEO-AO] Remove Temorary Hack
primitiveType = GlPrimitiveType.LINES_ADJACENCY;
Iterator<ChunkRenderList> iterator = renderLists.iterator(renderPass.isReverseOrder());
this.currentRenderPass = renderPass;
@@ -7,9 +7,7 @@ import org.joml.Matrix4fc;
public interface ChunkShaderInterface {
void setupState(TerrainRenderPass pass);
default void restoreState() {}
default GlPrimitiveType getPrimitiveType() {
return GlPrimitiveType.TRIANGLES;
}
GlPrimitiveType getPrimitiveType();
void setProjectionMatrix(Matrix4fc matrix);
void setModelViewMatrix(Matrix4fc matrix);
void setRegionOffset(float x, float y, float z);
@@ -4,6 +4,8 @@ import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat3v;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformInt;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
import org.embeddedt.embeddium.impl.gl.tessellation.GlPrimitiveType;
import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.QuadPrimitiveType;
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
import org.joml.Matrix4fc;
@@ -26,6 +28,8 @@ public class DefaultChunkShaderInterface implements ChunkShaderInterface {
private final ChunkShaderTextureService textureService;
private GlPrimitiveType primitiveType;
public DefaultChunkShaderInterface(ShaderBindingContext context, ChunkShaderOptions options) {
this.uniformModelViewMatrix = context.bindUniform("u_ModelViewMatrix", GlUniformMatrix4f::new);
this.uniformProjectionMatrix = context.bindUniform("u_ProjectionMatrix", GlUniformMatrix4f::new);
@@ -49,9 +53,22 @@ public class DefaultChunkShaderInterface implements ChunkShaderInterface {
this.bindTexture(ChunkShaderTextureSlot.LIGHT);
}
if (pass.primitiveType() == QuadPrimitiveType.DIRECT) {
primitiveType = GlPrimitiveType.LINES_ADJACENCY;
} else if (pass.primitiveType() == QuadPrimitiveType.TRIANGULATED) {
primitiveType = GlPrimitiveType.TRIANGLES;
} else {
throw new IllegalArgumentException("Unknown primitive type");
}
this.fogShader.setup();
}
@Override
public GlPrimitiveType getPrimitiveType() {
return primitiveType;
}
@Deprecated(forRemoval = true) // should be handled properly in GFX instead.
private void bindTexture(ChunkShaderTextureSlot slot) {
var uniform = this.uniformTextures.get(slot);
@@ -2,12 +2,18 @@
#import <sodium:include/fog.glsl>
// TODO: [VEN][GEO-NEO-AO] Proper switching if a geo shader is used or not?
// in VS_OUT
#ifdef USE_GEOMETRY_SHADER
in GS_OUT
#else
in VS_OUT
#endif
{
#ifdef USE_GEOMETRY_SHADER
vec2 edge;
flat vec4 v_Color[4];
#else
vec4 v_Color;
#endif
vec2 v_TexCoord;
float v_MaterialMipBias;
@@ -44,12 +50,14 @@ void main() {
}
#endif
// TODO: [VEN][GEO-NEO-AO] Proper switching if a geo shader is used or not?
#ifdef USE_GEOMETRY_SHADER
vec4 c1 = mix(fs_in.v_Color[0], fs_in.v_Color[1], fs_in.edge.x);
vec4 c2 = mix(fs_in.v_Color[2], fs_in.v_Color[3], fs_in.edge.x);
vec4 m_color = mix(c1, c2, fs_in.edge.y);
#else
vec4 m_color = fs_in.v_Color;
#endif
#ifdef USE_VANILLA_COLOR_FORMAT
// Apply per-vertex color. AO shade is applied ahead of time on the CPU.
@@ -64,6 +64,7 @@ public final class StandardOptions {
public static final ResourceLocation CPU_FRAMES_AHEAD = ResourceLocationUtil.make(Celeritas.MODID, "cpu_render_ahead_limit");
public static final ResourceLocation TRANSLUCENT_FACE_SORTING = ResourceLocationUtil.make(Celeritas.MODID, "translucent_face_sorting");
public static final ResourceLocation USE_QUAD_NORMALS_FOR_LIGHTING = ResourceLocationUtil.make(Celeritas.MODID, "use_quad_normals_for_lighting");
public static final ResourceLocation USE_ENHANCED_INTERPOLATION = ResourceLocationUtil.make(Celeritas.MODID, "use_enhanced_interpolation");
public static final ResourceLocation RENDER_PASS_OPTIMIZATION = ResourceLocationUtil.make(Celeritas.MODID, "render_pass_optimization");
public static final ResourceLocation RENDER_PASS_CONSOLIDATION = ResourceLocationUtil.make(Celeritas.MODID, "render_pass_consolidation");
public static final ResourceLocation USE_FASTER_CLOUDS = ResourceLocationUtil.make(Celeritas.MODID, "use_faster_clouds");
@@ -358,6 +358,15 @@ public class SodiumGameOptionPages {
.setEnabled(!ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setId(StandardOptions.Option.USE_ENHANCED_INTERPOLATION)
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.HIGH)
.setBinding((opts, value) -> opts.quality.useEnhancedInterpolation = value, opts -> opts.quality.useEnhancedInterpolation)
.setName(ComponentUtil.translatable("celeritas.options.use_enhanced_interpolation.name"))
.setTooltip(ComponentUtil.translatable("celeritas.options.use_enhanced_interpolation.tooltip"))
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
.build());
return new OptionPage(ComponentUtil.translatable("sodium.options.pages.quality"), ImmutableList.copyOf(groups));
@@ -80,6 +80,8 @@ public class SodiumGameOptions {
@SerializedName("use_quad_normals_for_shading_v2")
public boolean useQuadNormalsForShading = true;
public boolean useEnhancedInterpolation = false;
}
public static class NotificationSettings {
@@ -40,8 +40,7 @@ public class ModernRenderPassConfigurationBuilder {
}
private static TerrainRenderPass.TerrainRenderPassBuilder builderForRenderType(RenderType chunkRenderType, ChunkVertexType vertexType) {
// TODO make primitive type configurable
return TerrainRenderPass.builder().pipelineState(new ModernRenderTypePipelineState(chunkRenderType)).vertexType(vertexType).primitiveType(QuadPrimitiveType.DIRECT);
return TerrainRenderPass.builder().pipelineState(new ModernRenderTypePipelineState(chunkRenderType)).vertexType(vertexType).primitiveType(Celeritas.options().quality.useEnhancedInterpolation ? QuadPrimitiveType.DIRECT : QuadPrimitiveType.TRIANGULATED);
}
public static RenderPassConfiguration<RenderType> build(ChunkVertexType vertexType) {
@@ -14,5 +14,7 @@
"embeddium.options.use_faster_clouds.name": "Use Faster Clouds",
"embeddium.options.use_faster_clouds.tooltip": "When enabled, Celeritas replaces vanilla cloud rendering with a less glitchy and potentially faster implementation. Disable this if mods' cloud customizations aren't visible.",
"celeritas.options.async_graph_search.name": "Async Occlusion Culling",
"celeritas.options.async_graph_search.tooltip": "Performs occlusion/frustum culling asynchronously, up to one frame behind the current camera position. This can improve frametimes, particularly at higher render distances, but at the cost of chunks popping into view if the camera is turned too aggressively."
"celeritas.options.async_graph_search.tooltip": "Performs occlusion/frustum culling asynchronously, up to one frame behind the current camera position. This can improve frametimes, particularly at higher render distances, but at the cost of chunks popping into view if the camera is turned too aggressively.",
"celeritas.options.use_enhanced_interpolation.name": "Use Enhanced Interpolation",
"celeritas.options.use_enhanced_interpolation.tooltip": "Uses custom shader-based bilinear interpolation to render block faces rather than the GPU's default interpolation. This can noticeably improve the quality of ambient occlusion shadows, but may have compatibility and/or performance issues with some drivers."
}
@@ -141,7 +141,7 @@ public class IrisChunkShaderInterface implements ChunkShaderInterface {
@Override
public GlPrimitiveType getPrimitiveType() {
return isTess ? GlPrimitiveType.PATCHES : ChunkShaderInterface.super.getPrimitiveType();
return isTess ? GlPrimitiveType.PATCHES : GlPrimitiveType.TRIANGLES;
}
@Override