Common and version specific shader packages #10

Merged
embeddedt merged 24 commits from mitchej123/celeritas:common-shaders-and-enhancements into stonecutter 2025-03-31 19:52:28 -04:00
160 changed files with 1118 additions and 618 deletions
Showing only changes of commit 0c672317f7 - Show all commits

No files matched your search

@@ -0,0 +1,74 @@
package com.mitchej123.glsm;
import java.util.ServiceLoader;
public interface GLStateManagerService {
GLStateManagerService GL_STATE_MANAGER = ServiceLoader.load(GLStateManagerService.class).findFirst().orElseThrow();
int glGetInteger(int pname);
String glGetString(int pname);
void glBindFramebuffer(int target, int framebuffer);
int glCheckFramebufferStatus(int target);
void glDeleteFramebuffers(int framebuffer);
int glGenFramebuffers();
int glGetProgrami(int program, int pname);
void glAttachShader(int program, int shader);
void glDeleteShader(int shader);
int glCreateShader(int type);
void glCompileShader(int shader);
int glGetShaderi(int shader, int pname);
void glUseProgram(int program);
int glCreateProgram();
void glDeleteProgram(int program);
void glLinkProgram(int program);
int glGetUniformLocation(int program, CharSequence name);
void glUniform1i(int location, int value);
int glGetAttribLocation(int program, CharSequence name);
void glBindAttribLocation(int program, int index, CharSequence name);
int glGenVertexArrays();
void glBindVertexArray(int array);
void glCopyTexSubImage2D(int target, int level, int xoffset, int yoffset, int x, int y, int width, int height);
void enableCullFace();
void disableCullFace();
void enableBlend();
void disableBlend();
void glBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
void enableDepthTest();
void disableDepthTest();
void glDepthFunc(int func);
void glDepthMask(boolean flag);
void glViewport(int x, int y, int width, int height);
void glColorMask(boolean red, boolean green, boolean blue, boolean alpha);
void glClearColor(float red, float green, float blue, float alpha);
void clear(int mask, boolean checkError); // Non-standard
int glGetTexLevelParameteri(int target, int level, int pname);
void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level);
int glGenTextures();
void glGenTextures(int[] textures);
void glDeleteTextures(int texture);
void glDeleteTextures(int[] textures);
void bindTexture(int texture); // Non-standard
void glActiveTexture(int texture);
int getActiveTexture(); // Non-standard
int glGenBuffers();
void glBindBuffer(int target, int buffer);
void glPixelStorei(int pname, int param);
}
@@ -0,0 +1,57 @@
package com.mitchej123.glsm;
import java.nio.FloatBuffer;
import java.util.ServiceLoader;
import org.joml.Matrix4f;
public interface RenderSystemService {
RenderSystemService RENDER_SYSTEM = ServiceLoader.load(RenderSystemService.class).findFirst().orElseThrow();
void glActiveTexture(int texture);
void enableCullFace();
void disableCullFace();
void enableBlend();
void disableBlend();
void enableDepthTest();
void disableDepthTest();
void depthFunc(int depthFunc);
void depthMask(boolean flag);
void glViewport(int x, int y, int width, int height);
void bindTexture(int texture); // Non-standard
void glUniform1i(int location, int value);
void glUniformMatrix3(int location, boolean transpose, FloatBuffer value);
void glUniformMatrix4(int location, boolean transpose, FloatBuffer value);
void glClearColor(float red, float green, float blue, float alpha);
// Mojang Implementations
void clear(int mask, boolean checkError); // Non-standard
void assertOnRenderThread();
void assertOnRenderThreadOrInit();
// TODO: Figure out ResourceLocation, etc
// void setShaderTexture(int shaderTexture, ResourceLocation textureId)
void setShaderTexture(int shaderTexture, int textureId);
int getShaderTexture(int shaderTexture);
void setShaderColor(float red, float green, float blue, float alpha);
float[] getShaderFogColor();
float getShaderFogStart();
float getShaderFogEnd();
Matrix4f getProjectionMatrix();
// TODO: Figure out VertexSorting type
// void setProjectionMatrix(Matrix4f projectionMatrix, VertexSorting vertexSorting)
// TODO: Figure out FogShape
// FogShape getShaderFogShape()
}
@@ -15,7 +15,6 @@ import java.nio.ByteBuffer;
import java.util.function.IntFunction;
public class IrisApiV0Impl implements IrisApi {
public static final IrisApiV0Impl INSTANCE = new IrisApiV0Impl();
private static final IrisApiV0ConfigImpl CONFIG = new IrisApiV0ConfigImpl();
@Override
@@ -1,6 +1,9 @@
package net.irisshaders.iris.compat.dh;
import com.mojang.blaze3d.systems.RenderSystem;
import java.io.IOException;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import com.seibel.distanthorizons.api.DhApi;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiFramebuffer;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiGenericObjectShaderProgram;
@@ -20,8 +23,6 @@ import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL20C;
import java.io.IOException;
public class DHCompatInternal {
public static final DHCompatInternal SHADERLESS = new DHCompatInternal(null, false);
static boolean dhEnabled;
@@ -259,7 +260,7 @@ public class DHCompatInternal {
public void copyTranslucents(int width, int height) {
if (translucentDepthDirty) {
translucentDepthDirty = false;
RenderSystem.bindTexture(depthTexNoTranslucent.getTextureId());
RENDER_SYSTEM.bindTexture(depthTexNoTranslucent.getTextureId());
dhTerrainFramebuffer.bindAsReadBuffer();
IrisRenderSystem.copyTexImage2D(GL20C.GL_TEXTURE_2D, 0, DepthBufferFormat.DEPTH32F.getGlInternalFormat(), 0, 0, width, height, 0);
} else {
@@ -1,8 +1,14 @@
package net.irisshaders.iris.compat.dh;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import com.google.common.primitives.Ints;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiGenericObjectShaderProgram;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
@@ -41,11 +47,6 @@ import org.lwjgl.opengl.GL32C;
import org.lwjgl.opengl.GL43C;
import org.lwjgl.system.MemoryStack;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgram {
// Uniforms
public final int modelViewUniform;
@@ -134,8 +135,8 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
samplers = samplerBuilder.build();
images = builder.build();
this.va = GlStateManager._glGenVertexArrays();
GlStateManager._glBindVertexArray(va);
this.va = GL_STATE_MANAGER.glGenVertexArrays();
GL_STATE_MANAGER.glBindVertexArray(va);
GL32.glVertexAttribPointer(0, 3, GL32.GL_FLOAT, false, 0, 0);
GL32.glEnableVertexAttribArray(0);
@@ -208,7 +209,7 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
matrix.get(buffer);
buffer.rewind();
RenderSystem.glUniformMatrix4(index, false, buffer);
RENDER_SYSTEM.glUniformMatrix4(index, false, buffer);
}
}
@@ -220,13 +221,13 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
matrix.get(buffer);
buffer.rewind();
RenderSystem.glUniformMatrix3(index, false, buffer);
RENDER_SYSTEM.glUniformMatrix3(index, false, buffer);
}
}
// Override ShaderProgram.bind()
public void bind(DhApiRenderParam renderParam) {
GlStateManager._glBindVertexArray(va);
GL_STATE_MANAGER.glBindVertexArray(va);
GL32C.glUseProgram(id);
if (blend != null) blend.apply();
@@ -240,7 +241,7 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
setUniform(projectionInverseUniform, toJOML(renderParam.dhModelViewMatrix).invert());
setUniform(normalMatrix3fUniform, toJOML(renderParam.dhModelViewMatrix).invert().transpose3x3(new Matrix3f()));
Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer();
IrisRenderSystem.bindTextureToUnit(TextureType.TEXTURE_2D.getGlType(), IrisSamplers.LIGHTMAP_TEXTURE_UNIT, RenderSystem.getShaderTexture(2));
IrisRenderSystem.bindTextureToUnit(TextureType.TEXTURE_2D.getGlType(), IrisSamplers.LIGHTMAP_TEXTURE_UNIT, RENDER_SYSTEM.getShaderTexture(2));
this.setUniform(this.instancedShaderProjectionModelViewMatrixUniform, toJOML(renderParam.dhProjectionMatrix).mul(toJOML(renderParam.dhModelViewMatrix)));
samplers.update();
@@ -252,7 +253,7 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
}
public void unbind() {
GlStateManager._glBindVertexArray(0);
GL_STATE_MANAGER.glBindVertexArray(0);
GL43C.glUseProgram(0);
ProgramUniforms.clearActiveUniforms();
ProgramSamplers.clearActiveSamplers();
@@ -281,8 +282,8 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
public void fillIndirectUniformData(DhApiRenderParam dhApiRenderParam, DhApiRenderableBoxGroupShading dhApiRenderableBoxGroupShading, IDhApiRenderableBoxGroup boxGroup, DhApiVec3d camPos) {
bind(dhApiRenderParam);
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(GL30C.GL_LEQUAL);
RENDER_SYSTEM.enableDepthTest();
RENDER_SYSTEM.depthFunc(GL30C.GL_LEQUAL);
this.setUniform(this.instancedShaderOffsetChunkUniform,
new DhApiVec3i(
getChunkPosFromDouble(boxGroup.getOriginBlockPos().x),
@@ -1,7 +1,13 @@
package net.irisshaders.iris.compat.dh;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import com.google.common.primitives.Ints;
import com.mojang.blaze3d.systems.RenderSystem;
import com.seibel.distanthorizons.api.DhApi;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
import net.irisshaders.iris.gl.IrisRenderSystem;
@@ -31,11 +37,6 @@ import org.lwjgl.opengl.GL32;
import org.lwjgl.opengl.GL43C;
import org.lwjgl.system.MemoryStack;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class IrisLodRenderProgram {
// Uniforms
public final int modelOffsetUniform;
@@ -179,7 +180,7 @@ public class IrisLodRenderProgram {
matrix.get(buffer);
buffer.rewind();
RenderSystem.glUniformMatrix4(index, false, buffer);
RENDER_SYSTEM.glUniformMatrix4(index, false, buffer);
}
}
@@ -191,7 +192,7 @@ public class IrisLodRenderProgram {
matrix.get(buffer);
buffer.rewind();
RenderSystem.glUniformMatrix3(index, false, buffer);
RENDER_SYSTEM.glUniformMatrix3(index, false, buffer);
}
}
@@ -220,7 +221,7 @@ public class IrisLodRenderProgram {
GL43C.glUseProgram(id);
Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer();
IrisRenderSystem.bindTextureToUnit(TextureType.TEXTURE_2D.getGlType(), IrisSamplers.LIGHTMAP_TEXTURE_UNIT, RenderSystem.getShaderTexture(2));
IrisRenderSystem.bindTextureToUnit(TextureType.TEXTURE_2D.getGlType(), IrisSamplers.LIGHTMAP_TEXTURE_UNIT, RENDER_SYSTEM.getShaderTexture(2));
setUniform(modelViewUniform, modelView);
setUniform(modelViewInverseUniform, modelView.invert(new Matrix4f()));
setUniform(projectionUniform, projection);
@@ -1,6 +1,7 @@
package net.irisshaders.iris.compat.dh;
import com.mojang.blaze3d.platform.GlStateManager;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import com.seibel.distanthorizons.api.DhApi;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogDrawMode;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass;
@@ -33,7 +34,6 @@ import net.irisshaders.iris.uniforms.CapturedRenderingState;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import org.lwjgl.opengl.GL43C;
import org.lwjgl.opengl.GL46C;
public class LodRendererEvents {
private static boolean eventHandlersBound = false;
@@ -341,7 +341,7 @@ public class LodRendererEvents {
Matrix4fc projection = CapturedRenderingState.INSTANCE.getGbufferProjection();
//float nearClip = DhApi.Delayed.renderProxy.getNearClipPlaneDistanceInBlocks(partialTicks);
//float farClip = (float) ((double) (DHCompatInternal.getDhBlockRenderDistance() + 512) * Math.sqrt(2.0));
GlStateManager._disableCull();
GL_STATE_MANAGER.disableCullFace();
//Iris.logger.info("event near clip: "+event.value.nearClipPlane+" event far clip: "+event.value.farClipPlane+
// " \niris near clip: "+nearClip+" iris far clip: "+farClip);
@@ -1,40 +1,44 @@
package net.irisshaders.iris.compat.sodium.impl.shader_overrides;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.List;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.framebuffer.GlFramebuffer;
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.irisshaders.iris.shadows.ShadowRenderingState;
import net.minecraft.client.Minecraft;
import org.embeddedt.embeddium.impl.gl.buffer.GlMutableBuffer;
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.embeddedt.embeddium.impl.gl.shader.uniform.*;
import org.embeddedt.embeddium.impl.gl.tessellation.GlPrimitiveType;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderInterface;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderOptions;
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
import org.embeddedt.embeddium.impl.util.TextureUtil;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.blending.BlendModeOverride;
import net.irisshaders.iris.gl.blending.BufferBlendOverride;
import net.irisshaders.iris.gl.framebuffer.GlFramebuffer;
import net.irisshaders.iris.gl.program.ProgramImages;
import net.irisshaders.iris.gl.program.ProgramSamplers;
import net.irisshaders.iris.gl.program.ProgramUniforms;
import net.irisshaders.iris.gl.texture.TextureType;
import net.irisshaders.iris.pipeline.SodiumTerrainPipeline;
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.irisshaders.iris.samplers.IrisSamplers;
import net.irisshaders.iris.shadows.ShadowRenderingState;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.irisshaders.iris.uniforms.custom.CustomUniforms;
import net.irisshaders.iris.vertices.ImmediateState;
import net.minecraft.client.Minecraft;
import org.embeddedt.embeddium.impl.gl.buffer.GlMutableBuffer;
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformBlock;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat3v;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix3f;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
import org.embeddedt.embeddium.impl.gl.tessellation.GlPrimitiveType;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderInterface;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderOptions;
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
import org.embeddedt.embeddium.impl.util.TextureUtil;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import org.lwjgl.opengl.GL32C;
import java.util.List;
public class IrisChunkShaderInterface implements ChunkShaderInterface {
@Nullable
private final GlUniformMatrix4f uniformModelViewMatrix;
@@ -96,14 +100,15 @@ public class IrisChunkShaderInterface implements ChunkShaderInterface {
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
// No back face culling during the shadow pass
// TODO: Hopefully this won't be necessary in the future...
RenderSystem.disableCull();
RENDER_SYSTEM.disableCullFace();
}
// See IrisSamplers#addLevelSamplers
IrisRenderSystem.bindTextureToUnit(TextureType.TEXTURE_2D.getGlType(), IrisSamplers.ALBEDO_TEXTURE_UNIT, TextureUtil.getBlockTextureId());
IrisRenderSystem.bindTextureToUnit(TextureType.TEXTURE_2D.getGlType(), IrisSamplers.LIGHTMAP_TEXTURE_UNIT, TextureUtil.getLightTextureId());
// This is what is expected by the rest of rendering state, failure to do this will cause blurry textures on particles.
GlStateManager._activeTexture(GL32C.GL_TEXTURE0 + IrisSamplers.LIGHTMAP_TEXTURE_UNIT);
GL_STATE_MANAGER.glActiveTexture(GL32C.GL_TEXTURE0 + IrisSamplers.LIGHTMAP_TEXTURE_UNIT);
GL_STATE_MANAGER.glActiveTexture(GL32C.GL_TEXTURE0 + IrisSamplers.LIGHTMAP_TEXTURE_UNIT);
CapturedRenderingState.INSTANCE.setCurrentAlphaTest(alpha);
if (blendModeOverride != null) {
Loaded 100 of 160 files, more files were not shown because too many files have changed in this diff. Show more