From 23d7c547c52f323833703f806c8d311c29dfa5af Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Sun, 29 Oct 2023 17:26:43 +0100 Subject: [PATCH] Fix compatibility with recent snapshots due to water shaders being refactored. (#42) --- .../chunky/denoiser/ChunkyCompatHelper.java | 27 ++++++++++++++++++- .../chunky/denoiser/NormalRenderer.java | 2 +- src/main/resources/plugin.json | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/lemaik/chunky/denoiser/ChunkyCompatHelper.java b/src/main/java/de/lemaik/chunky/denoiser/ChunkyCompatHelper.java index dd49836..7acd608 100644 --- a/src/main/java/de/lemaik/chunky/denoiser/ChunkyCompatHelper.java +++ b/src/main/java/de/lemaik/chunky/denoiser/ChunkyCompatHelper.java @@ -22,7 +22,7 @@ private static Method getMethod(Class className, String methodName, Class. try { return className.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { - throw new RuntimeException("Could not invoke " + methodName + " on class " + className.getName(), e); + throw new RuntimeException("Could not get method " + methodName + " of class " + className.getName(), e); } } @@ -64,4 +64,29 @@ public static void doWaterDisplacement(Ray ray) { } } } + + public static class Scene { + private static Method stillWaterEnabled; + + private static Class stillWaterShader; + + static { + try { + stillWaterEnabled = se.llbit.chunky.renderer.scene.Scene.class.getDeclaredMethod("stillWaterEnabled"); + } catch (NoSuchMethodException e) { + stillWaterShader = ChunkyCompatHelper.getClass("se.llbit.chunky.renderer.scene.StillWaterShader"); + } + } + + public static boolean isStillWaterEnabled(se.llbit.chunky.renderer.scene.Scene scene) { + if (stillWaterEnabled != null) { + try { + return (boolean) stillWaterEnabled.invoke(scene); + } catch (InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException("Could not invoke stillWaterEnabled()", e); + } + } + return stillWaterShader.isInstance(scene.getCurrentWaterShader()); + } + } } diff --git a/src/main/java/de/lemaik/chunky/denoiser/NormalRenderer.java b/src/main/java/de/lemaik/chunky/denoiser/NormalRenderer.java index 4d7b05b..d2ac912 100644 --- a/src/main/java/de/lemaik/chunky/denoiser/NormalRenderer.java +++ b/src/main/java/de/lemaik/chunky/denoiser/NormalRenderer.java @@ -29,7 +29,7 @@ private static class NormalTracer implements RayTracer { public void trace(Scene scene, WorkerState state) { Ray ray = state.ray; if (PreviewRayTracer.nextIntersection(scene, ray)) { - if (BetterRenderManager.NORMAL_WATER_DISPLACEMENT && !scene.stillWaterEnabled() + if (BetterRenderManager.NORMAL_WATER_DISPLACEMENT && !ChunkyCompatHelper.Scene.isStillWaterEnabled(scene) && ray.getCurrentMaterial().isWater()) { ChunkyCompatHelper.Water.doWaterDisplacement(ray); } diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json index 6733c73..aabbb8a 100644 --- a/src/main/resources/plugin.json +++ b/src/main/resources/plugin.json @@ -2,7 +2,7 @@ "name": "DenoiserPlugin", "author": "leMaik", "main": "de.lemaik.chunky.denoiser.DenoiserPlugin", - "version": "0.4.1", + "version": "0.4.2", "targetVersion": "2.4.0", "description": "Renders normal and albedo maps to pfm files for use with denoisers." }