Another save commit for fog fix

This commit is contained in:
coolGi
2023-07-20 21:06:07 +09:30
parent 7f51aef384
commit 675682d631
7 changed files with 67 additions and 34 deletions
@@ -79,7 +79,10 @@ public class LodRenderer
public void setupOffset(DhBlockPos pos) {
Vec3d cam = MC_RENDER.getCameraExactPosition();
shaderProgram.setModelPos(new Vec3f((float) (pos.x - cam.x), (float) (pos.y - cam.y), (float) (pos.z - cam.z)));
Vec3f modelPos = new Vec3f((float) (pos.x - cam.x), (float) (pos.y - cam.y), (float) (pos.z - cam.z));
shaderProgram.setModelPos(modelPos);
// FogShader.INSTANCE.setModelPos(modelPos);
}
public void drawVbo(GLVertexBuffer vbo) {
@@ -206,6 +209,8 @@ public class LodRenderer
if (newConfig != null) {
shaderProgram.free();
shaderProgram = new LodRenderProgram(newConfig);
// FogShader.INSTANCE.free();
// FogShader.INSTANCE = new FogShader(newConfig);
}
shaderProgram.bind();
}
@@ -252,7 +257,7 @@ public class LodRenderer
}
{
// FogShader.INSTANCE.render(partialTicks);
// DarkShader.INSTANCE.render(partialTicks);
// DarkShader.INSTANCE.render(partialTicks); // A test shader to make the world darker
}
//======================//
@@ -356,6 +361,7 @@ public class LodRenderer
isSetupComplete = false;
EVENT_LOGGER.info("Renderer Cleanup Started");
shaderProgram.free();
// FogShader.INSTANCE.free();
if (quadIBO != null) quadIBO.destroy(false);
EVENT_LOGGER.info("Renderer Cleanup Complete");
}
@@ -10,6 +10,7 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RenderUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import com.seibel.distanthorizons.coreapi.util.math.Vec3f;
import org.lwjgl.opengl.GL32;
import java.awt.*;
@@ -18,6 +19,10 @@ public class FogShader extends AbstractShaderRenderer {
public static FogShader INSTANCE = new FogShader(LodFogConfig.generateFogConfig());
private static final IVersionConstants VERSION_CONSTANTS = SingletonInjector.INSTANCE.get(IVersionConstants.class);
// public final int modelOffsetUniform;
public final int worldYOffsetUniform;
// Fog Uniforms
public final int fogColorUniform;
public final int fogScaleUniform;
@@ -27,13 +32,17 @@ public class FogShader extends AbstractShaderRenderer {
public final int fullFogModeUniform;
public FogShader(LodFogConfig fogConfig) {
// TODO & Note: This code is a bit jank, so try to update it later (preferably not using something to process the shader)
// TODO & Note: This code is a bit jank, so try to make it better later (preferably not using something to process the shader)
// This code is just a temp fix so that it looks fine for the time being
// and even with the jank soloution, i cannot get it to work
super(new ShaderProgram(
() -> Shader.loadFile("shaders/normal.vert", false, new StringBuilder()).toString(),
() -> Shader.loadFile("shaders/fog/fog.vert", false, new StringBuilder()).toString(),
() -> fogConfig.loadAndProcessFragShader("shaders/fog/fog.frag", false).toString(),
"fragColor", new String[] { "vPos", "vPosition", "color" }
"fragColor", new String[] { "vPosition", "vPos", "color" }
));
// modelOffsetUniform = this.shader.getUniformLocation("modelOffset");
worldYOffsetUniform = this.shader.getUniformLocation("worldYOffset");
// Fog uniforms
fogColorUniform = this.shader.getUniformLocation("fogColor");
fullFogModeUniform = this.shader.getUniformLocation("fullFogMode");
@@ -51,14 +60,9 @@ public class FogShader extends AbstractShaderRenderer {
int vanillaDrawDistance = MC_RENDER.getRenderDistance() * LodUtil.CHUNK_WIDTH;
// super.bind();
vanillaDrawDistance += 32; // Give it a 2 chunk boundary for near fog.
// // uniforms
// this.shader.setUniform(combinedMatUniform, combinedMatrix);
// this.shader.setUniform(mircoOffsetUniform, 0.01f); // 0.01 block offset
//
// // setUniform(skyLightUniform, skyLight);
// this.shader.setUniform(lightMapUniform, lightmapBindPoint);
//
// if (worldYOffsetUniform != -1) this.shader.setUniform(worldYOffsetUniform, (float)worldYOffset);
this.shader.setUniform(worldYOffsetUniform, (float) MC.getWrappedClientWorld().getMinHeight());
// Fog
this.shader.setUniform(fullFogModeUniform, MC_RENDER.isFogStateSpecial() ? 1 : 0);
@@ -89,4 +93,8 @@ public class FogShader extends AbstractShaderRenderer {
{
return MC_RENDER.getSpecialFogColor(partialTicks);
}
public void setModelPos(Vec3f modelPos) {
// this.shader.setUniform(modelOffsetUniform, modelPos);
}
}
@@ -192,5 +192,8 @@ public class SSAORenderer {
state.restore();
}
public void free() {
ssaoShader.free();
applyShader.free();
}
}
+17 -9
View File
@@ -1,7 +1,7 @@
in vec3 vertexWorldPos;
in float vertexYPos;
in vec2 TexCoord;
//in vec2 TexCoord;
out vec4 fragColor;
@@ -67,14 +67,22 @@ void main() {
fragColor = vec4(fogColor.r, fogColor.g, fogColor.b, mixedFogThickness);
}
if (fragColor.r != 6969.) {
fragColor = vec4(
mod(vertexWorldPos.x, 1),
mod(vertexWorldPos.y, 1),
mod(vertexWorldPos.z, 1),
1.
);
}
// Testing
// if (fragColor.r != 6969.) { // This line is so that the compiler doesnt delete the previos code
//// fragColor = vec4(
//// mod(vertexWorldPos.x, 1),
//// mod(vertexWorldPos.y, 1),
//// mod(vertexWorldPos.z, 1),
//// 1.
//// );
// fragColor = vec4(
// mod(vertexYPos, 1),
// mod(vertexYPos, 1),
// mod(vertexYPos, 1),
// 1.
// );
// }
}
@@ -0,0 +1,19 @@
#version 150 core
//uniform vec3 modelOffset;
uniform float worldYOffset;
in vec2 vPos;
in uvec4 vPosition;
out vec3 vertexWorldPos;
out float vertexYPos;
void main()
{
// vertexWorldPos = vPosition.xyz + modelOffset;
vertexYPos = vPosition.y + worldYOffset;
gl_Position = vec4(vPos, 1.0, 1.0);
}
@@ -1,17 +1,11 @@
#version 150 core
in uvec4 vPosition; // Fixme
in vec2 vPos;
out vec2 TexCoord;
out vec4 vertexColor;
out vec3 vertexWorldPos;
out float vertexYPos;
void main()
{
vertexWorldPos = vec3(vPosition.x, vPosition.y, vPosition.z); // Fixme
gl_Position = vec4(vPos, 1.0, 1.0);
TexCoord = vPos.xy * 0.5 + 0.5;
}
@@ -30,11 +30,6 @@ vec3 calcViewPosition(vec2 coords) {
vs_pos.xyz = vs_pos.xyz / vs_pos.w;
return vs_pos.xyz;
}
// The modulus function dosnt exist in GLSL so I made my own
// To speed up the mod function, this only accepts full numbers for y
float mod(float x, int y) {
return x - y * floor(x/y);
}
void main()
{