Skip to content

Commit

Permalink
Fix compatibility with recent snapshots due to water shaders being re…
Browse files Browse the repository at this point in the history
…factored. (#42)
  • Loading branch information
leMaik authored Oct 29, 2023
1 parent 3c57920 commit 23d7c54
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/main/java/de/lemaik/chunky/denoiser/ChunkyCompatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

0 comments on commit 23d7c54

Please sign in to comment.