From d5fcdfb8c288bf079fbf082cd96c8cb3ba600bfc Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Wed, 1 Apr 2020 15:59:03 +0200 Subject: [PATCH] Fix ODS rendering in 1.15 --- .../render/capturer/ODSFrameCapturer.java | 12 +++++++++++- .../assets/replaymod/shader/ods.frag | 19 +++++++++++++++---- .../assets/replaymod/shader/ods.vert | 10 +++++++++- versions/common.gradle | 11 +++++++++++ 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/replaymod/render/capturer/ODSFrameCapturer.java b/src/main/java/com/replaymod/render/capturer/ODSFrameCapturer.java index c1f1affc..363f5d81 100644 --- a/src/main/java/com/replaymod/render/capturer/ODSFrameCapturer.java +++ b/src/main/java/com/replaymod/render/capturer/ODSFrameCapturer.java @@ -80,13 +80,23 @@ public class ODSFrameCapturer implements FrameCapturer { private void bindProgram() { shaderProgram.use(); setTexture("texture", 0); + //#if MC>=11500 + //$$ setTexture("overlay", 1); + //$$ setTexture("lightMap", 2); + //#else setTexture("lightMap", 1); + //#endif renderStateEvents = new EventRegistrations(); Program.Uniform[] texture2DUniforms = new Program.Uniform[]{ shaderProgram.getUniformVariable("textureEnabled"), + //#if MC>=11500 + //$$ shaderProgram.getUniformVariable("overlayEnabled"), + //$$ shaderProgram.getUniformVariable("lightMapEnabled"), + //#else shaderProgram.getUniformVariable("lightMapEnabled"), - shaderProgram.getUniformVariable("hurtTextureEnabled") + shaderProgram.getUniformVariable("overlayEnabled"), + //#endif }; renderStateEvents.on(Texture2DStateCallback.EVENT, (id, enabled) -> { if (id >= 0 && id < texture2DUniforms.length) { diff --git a/src/main/resources/assets/replaymod/shader/ods.frag b/src/main/resources/assets/replaymod/shader/ods.frag index ef46047b..77d66645 100644 --- a/src/main/resources/assets/replaymod/shader/ods.frag +++ b/src/main/resources/assets/replaymod/shader/ods.frag @@ -4,13 +4,19 @@ varying vec4 vertColor; varying vec4 textureCoord; varying vec4 lightMapCoord; +//#if MC>=11500 +//$$ varying vec4 overlayCoords; +//#endif uniform sampler2D texture; uniform sampler2D lightMap; +//#if MC>=11500 +//$$ uniform sampler2D overlay; +//#endif uniform bool textureEnabled; uniform bool lightMapEnabled; -uniform bool hurtTextureEnabled; +uniform bool overlayEnabled; uniform bool fogEnabled; void main() { @@ -18,12 +24,17 @@ void main() { if (textureEnabled) { color *= texture2D(texture, textureCoord.st); } + if (overlayEnabled) { + //#if MC>=11500 + //$$ vec4 c = texture2D(overlay, overlayCoords.st); + //$$ color = vec4(mix(c.rgb, color.rgb, c.a), color.a); + //#else + color = vec4(mix(color.rgb, vec3(1, 0, 0), 0.3), color.a); + //#endif + } if (lightMapEnabled) { color *= texture2D(lightMap, lightMapCoord.st); } - if (hurtTextureEnabled) { - color = vec4(mix(color.rgb, vec3(1, 0, 0), 0.3), color.a); - } if (fogEnabled) { color.rgb = mix(color.rgb, gl_Fog.color.rgb, clamp((gl_FogFragCoord - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0)); } diff --git a/src/main/resources/assets/replaymod/shader/ods.vert b/src/main/resources/assets/replaymod/shader/ods.vert index 18912c3e..11f3fd66 100644 --- a/src/main/resources/assets/replaymod/shader/ods.vert +++ b/src/main/resources/assets/replaymod/shader/ods.vert @@ -5,6 +5,9 @@ varying float vertId; varying vec4 textureCoord; varying vec4 lightMapCoord; +//#if MC>=11500 +//$$ varying vec4 overlayCoords; +//#endif uniform bool leftEye; uniform int direction; @@ -66,7 +69,12 @@ void main() { // Misc. textureCoord = gl_TextureMatrix[0] * gl_MultiTexCoord0; - lightMapCoord = gl_TextureMatrix[1] * gl_MultiTexCoord1; + //#if MC>=11500 + //$$ overlayCoords = gl_TextureMatrix[1] * gl_MultiTexCoord1; + //$$ lightMapCoord = gl_TextureMatrix[2] * gl_MultiTexCoord2; + //#else + lightMapCoord = gl_TextureMatrix[1] * gl_MultiTexCoord1; + //#endif vertColor = gl_Color; gl_FogFragCoord = sqrt(position.x * position.x + position.y * position.y + position.z * position.z); } \ No newline at end of file diff --git a/versions/common.gradle b/versions/common.gradle index 3bf29ffa..7edccc6f 100644 --- a/versions/common.gradle +++ b/versions/common.gradle @@ -1,3 +1,5 @@ +import com.replaymod.gradle.preprocess.PreprocessTask + buildscript { def mcVersion def (major, minor, patch) = project.name.tokenize('-')[0].tokenize('.') @@ -88,6 +90,15 @@ apply plugin: 'com.replaymod.preprocess' preprocess { vars.put("MC", project.mcVersion) vars.put("FABRIC", project.fabric ? 1 : 0) + + keywords.set([ + ".java": PreprocessTask.DEFAULT_KEYWORDS, + ".json": PreprocessTask.DEFAULT_KEYWORDS, + ".mcmeta": PreprocessTask.DEFAULT_KEYWORDS, + ".cfg": PreprocessTask.CFG_KEYWORDS, + ".vert": PreprocessTask.DEFAULT_KEYWORDS, + ".frag": PreprocessTask.DEFAULT_KEYWORDS, + ]) } def mcVersionStr = "${(int)(mcVersion/10000)}.${(int)(mcVersion/100)%100}" + (mcVersion%100==0 ? '' : ".${mcVersion%100}")