wip face tinit
This commit is contained in:
@@ -2,11 +2,16 @@ package me.cortex.voxy.client.core.rendering.section.backend;
|
|||||||
|
|
||||||
|
|
||||||
import me.cortex.voxy.client.core.AbstractRenderPipeline;
|
import me.cortex.voxy.client.core.AbstractRenderPipeline;
|
||||||
|
import me.cortex.voxy.client.core.gl.shader.Shader;
|
||||||
|
import me.cortex.voxy.client.core.gl.shader.ShaderType;
|
||||||
import me.cortex.voxy.client.core.model.ModelStore;
|
import me.cortex.voxy.client.core.model.ModelStore;
|
||||||
import me.cortex.voxy.client.core.rendering.Viewport;
|
import me.cortex.voxy.client.core.rendering.Viewport;
|
||||||
import me.cortex.voxy.client.core.rendering.section.geometry.BasicSectionGeometryData;
|
import me.cortex.voxy.client.core.rendering.section.geometry.BasicSectionGeometryData;
|
||||||
import me.cortex.voxy.client.core.rendering.section.geometry.IGeometryData;
|
import me.cortex.voxy.client.core.rendering.section.geometry.IGeometryData;
|
||||||
import me.cortex.voxy.common.Logger;
|
import me.cortex.voxy.common.Logger;
|
||||||
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.world.level.dimension.DimensionType;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,4 +69,33 @@ public abstract class AbstractSectionRenderer <T extends Viewport<T>, J extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addDebug(List<String> lines) {}
|
public void addDebug(List<String> lines) {}
|
||||||
|
|
||||||
|
protected static void addDirectionalFaceTint(Shader.Builder<?> builder, ClientLevel cl) {
|
||||||
|
//TODO: generate the tinting table here and use the replacement feature
|
||||||
|
float[] tints = new float[7];
|
||||||
|
tints[6] = cl.getShade(Direction.UP, false);
|
||||||
|
for (Direction direction : Direction.values()) {
|
||||||
|
tints[direction.get3DDataValue()] = cl.getShade(direction, true);
|
||||||
|
}
|
||||||
|
if (cl.dimensionType().cardinalLightType() == DimensionType.CardinalLightType.NETHER) {
|
||||||
|
builder.define("DARKENED_TINTING");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Shader tryCompilePatchedOrNormal(Shader.Builder<?> builder, String shader, String original) {
|
||||||
|
boolean patched = shader != original;//This is the correct comparison type (reference)
|
||||||
|
try {
|
||||||
|
return builder.clone()
|
||||||
|
.defineIf("PATCHED_SHADER", patched)
|
||||||
|
.addSource(ShaderType.FRAGMENT, shader)
|
||||||
|
.compile();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
if (patched) {
|
||||||
|
Logger.error("Failed to compile shader patch, using normal pipeline to prevent errors", e);
|
||||||
|
return tryCompilePatchedOrNormal(builder, original, original);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,11 +114,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
|
|||||||
.addSource(ShaderType.VERTEX, vertex);
|
.addSource(ShaderType.VERTEX, vertex);
|
||||||
|
|
||||||
//Apply per face tinting
|
//Apply per face tinting
|
||||||
var CL = Minecraft.getInstance().level;
|
addDirectionalFaceTint(builder, Minecraft.getInstance().level);
|
||||||
if (CL.effects().constantAmbientLight()) {
|
|
||||||
builder.define("DARKENED_TINTING");
|
|
||||||
//TODO: generate the tinting table here
|
|
||||||
}
|
|
||||||
|
|
||||||
String frag = ShaderLoader.parse("voxy:lod/gl46/quads.frag");
|
String frag = ShaderLoader.parse("voxy:lod/gl46/quads.frag");
|
||||||
|
|
||||||
@@ -129,28 +125,9 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
|
|||||||
this.terrainShader = tryCompilePatchedOrNormal(builder, opaqueFrag, frag);
|
this.terrainShader = tryCompilePatchedOrNormal(builder, opaqueFrag, frag);
|
||||||
|
|
||||||
String translucentFrag = pipeline.patchTranslucentShader(this, frag);
|
String translucentFrag = pipeline.patchTranslucentShader(this, frag);
|
||||||
if (translucentFrag != null) {
|
translucentFrag = translucentFrag==null?frag:translucentFrag;
|
||||||
this.translucentTerrainShader = tryCompilePatchedOrNormal(builder, translucentFrag, frag);
|
|
||||||
} else {
|
|
||||||
this.translucentTerrainShader = this.terrainShader;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Shader tryCompilePatchedOrNormal(Shader.Builder<?> builder, String shader, String original) {
|
this.translucentTerrainShader = tryCompilePatchedOrNormal(builder.define("TRANSLUCENT"), translucentFrag, frag);
|
||||||
boolean patched = shader != original;//This is the correct comparison type (reference)
|
|
||||||
try {
|
|
||||||
return builder.clone()
|
|
||||||
.defineIf("PATCHED_SHADER", patched)
|
|
||||||
.addSource(ShaderType.FRAGMENT, shader)
|
|
||||||
.compile();
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
if (patched) {
|
|
||||||
Logger.error("Failed to compile shader patch, using normal pipeline to prevent errors", e);
|
|
||||||
return tryCompilePatchedOrNormal(builder, original, original);
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadUniformBuffer(MDICViewport viewport) {
|
private void uploadUniformBuffer(MDICViewport viewport) {
|
||||||
@@ -379,11 +356,9 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void free() {
|
public void free() {
|
||||||
if (this.terrainShader != this.translucentTerrainShader) {
|
|
||||||
this.translucentTerrainShader.free();
|
|
||||||
}
|
|
||||||
this.uniform.free();
|
this.uniform.free();
|
||||||
this.distanceCountBuffer.free();
|
this.distanceCountBuffer.free();
|
||||||
|
this.translucentTerrainShader.free();
|
||||||
this.terrainShader.free();
|
this.terrainShader.free();
|
||||||
this.commandGenShader.free();
|
this.commandGenShader.free();
|
||||||
this.cullShader.free();
|
this.cullShader.free();
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
|||||||
import me.cortex.voxy.common.Logger;
|
import me.cortex.voxy.common.Logger;
|
||||||
import net.irisshaders.iris.shaderpack.ShaderPack;
|
import net.irisshaders.iris.shaderpack.ShaderPack;
|
||||||
import net.irisshaders.iris.shaderpack.include.AbsolutePackPath;
|
import net.irisshaders.iris.shaderpack.include.AbsolutePackPath;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.lwjgl.opengl.ARBDrawBuffersBlend;
|
import org.lwjgl.opengl.ARBDrawBuffersBlend;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|||||||
Reference in New Issue
Block a user