From e83219ad4e0c83b3e0bfa4b355a2ab2bb4e43452 Mon Sep 17 00:00:00 2001 From: Peregrine05 <92183530+Peregrine05@users.noreply.github.com> Date: Sun, 22 Oct 2023 22:46:22 +0200 Subject: [PATCH] Remove `Anisotropy` from `Materials` tab --- .../llbit/chunky/renderer/scene/CloudLayer.java | 4 ++-- .../llbit/chunky/renderer/scene/PathTracer.java | 10 +++++----- .../llbit/chunky/ui/render/tabs/MaterialsTab.java | 15 +-------------- .../src/java/se/llbit/chunky/world/Material.java | 4 ---- .../se/llbit/chunky/world/VolumeMaterial.java | 2 ++ 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/renderer/scene/CloudLayer.java b/chunky/src/java/se/llbit/chunky/renderer/scene/CloudLayer.java index e37f3a4097..8c38e12f79 100644 --- a/chunky/src/java/se/llbit/chunky/renderer/scene/CloudLayer.java +++ b/chunky/src/java/se/llbit/chunky/renderer/scene/CloudLayer.java @@ -536,7 +536,7 @@ private void importFlatMaterial(JsonObject json) { } private void importVolumeMaterial(JsonObject json) { - volumeMaterial.emittance = json.get("emittance").floatValue(material.emittance); - volumeMaterial.anisotropy = json.get("anisotropy").floatValue(material.anisotropy); + volumeMaterial.emittance = json.get("emittance").floatValue(volumeMaterial.emittance); + volumeMaterial.anisotropy = json.get("anisotropy").floatValue(volumeMaterial.anisotropy); } } diff --git a/chunky/src/java/se/llbit/chunky/renderer/scene/PathTracer.java b/chunky/src/java/se/llbit/chunky/renderer/scene/PathTracer.java index 39e7ea7f0b..a5642ef704 100644 --- a/chunky/src/java/se/llbit/chunky/renderer/scene/PathTracer.java +++ b/chunky/src/java/se/llbit/chunky/renderer/scene/PathTracer.java @@ -141,7 +141,7 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state, boolean doMetal = pMetal > Ray.EPSILON && random.nextFloat() < pMetal; if (currentMat instanceof VolumeMaterial) { - hit |= doParticleFogReflection(ray, next, currentMat, cumulativeColor, random, state, scene); + hit |= doParticleFogReflection(ray, next, (VolumeMaterial) currentMat, cumulativeColor, random, state, scene); } else if (doMetal || (pSpecular > Ray.EPSILON && random.nextFloat() < pSpecular)) { hit |= doSpecularReflection(ray, next, cumulativeColor, doMetal, random, state, scene); } else if(random.nextFloat() < pDiffuse) { @@ -205,7 +205,7 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state, return hit; } - private static boolean doParticleFogReflection(Ray ray, Ray next, Material currentMat, Vector4 cumulativeColor, Random random, WorkerState state, Scene scene) { + private static boolean doParticleFogReflection(Ray ray, Ray next, VolumeMaterial currentMat, Vector4 cumulativeColor, Random random, WorkerState state, Scene scene) { boolean hit = false; Vector3 emittance = new Vector3(); next.set(ray); @@ -234,7 +234,7 @@ private static boolean doParticleFogReflection(Ray ray, Ray next, Material curre Vector4 attenuation = state.attenuation; if (attenuation.w > 0) { - double mult = phaseHG(cosTheta, ray.getCurrentMaterial().anisotropy) * (scene.getSunSamplingStrategy().isSunLuminosity() ? scene.sun().getLuminosityPdf() : 1); + double mult = phaseHG(cosTheta, currentMat.anisotropy) * (scene.getSunSamplingStrategy().isSunLuminosity() ? scene.sun().getLuminosityPdf() : 1); directLightR = attenuation.x * attenuation.w * mult; directLightG = attenuation.y * attenuation.w * mult; directLightB = attenuation.z * attenuation.w * mult; @@ -245,7 +245,7 @@ private static boolean doParticleFogReflection(Ray ray, Ray next, Material curre Vector3 outboundDirection = new Vector3(); double x1 = random.nextDouble(); double x2 = random.nextDouble(); - henyeyGreensteinSampleP(ray.getCurrentMaterial().anisotropy, inboundDirection, outboundDirection, x1, x2); + henyeyGreensteinSampleP(currentMat.anisotropy, inboundDirection, outboundDirection, x1, x2); next.d.set(outboundDirection); next.d.normalize(); @@ -261,7 +261,7 @@ private static boolean doParticleFogReflection(Ray ray, Ray next, Material curre Vector3 outboundDirection = new Vector3(); double x1 = random.nextDouble(); double x2 = random.nextDouble(); - henyeyGreensteinSampleP(ray.getCurrentMaterial().anisotropy, inboundDirection, outboundDirection, x1, x2); + henyeyGreensteinSampleP(currentMat.anisotropy, inboundDirection, outboundDirection, x1, x2); next.d.set(outboundDirection); next.d.normalize(); diff --git a/chunky/src/java/se/llbit/chunky/ui/render/tabs/MaterialsTab.java b/chunky/src/java/se/llbit/chunky/ui/render/tabs/MaterialsTab.java index ec87aed459..10a4e1efd6 100644 --- a/chunky/src/java/se/llbit/chunky/ui/render/tabs/MaterialsTab.java +++ b/chunky/src/java/se/llbit/chunky/ui/render/tabs/MaterialsTab.java @@ -54,7 +54,6 @@ public class MaterialsTab extends HBox implements RenderControlsTab, Initializab private final DoubleAdjuster ior = new DoubleAdjuster(); private final DoubleAdjuster perceptualSmoothness = new DoubleAdjuster(); private final DoubleAdjuster metalness = new DoubleAdjuster(); - private final DoubleAdjuster anisotropy = new DoubleAdjuster(); private final ListView listView; public MaterialsTab() { @@ -73,9 +72,6 @@ public MaterialsTab() { metalness.setName("Metalness"); metalness.setRange(0, 1); metalness.setTooltip("Metalness (texture-tinted reflectivity) of the selected material."); - anisotropy.setName("Anisotropy"); - anisotropy.setRange(-1, 1); - anisotropy.clampBoth(); ObservableList blockIds = FXCollections.observableArrayList(); blockIds.addAll(MaterialStore.collections.keySet()); blockIds.addAll(ExtraMaterials.idMap.keySet()); @@ -91,9 +87,7 @@ public MaterialsTab() { settings.setSpacing(10); settings.getChildren().addAll( new Label("Material Properties"), - emittance, specular, perceptualSmoothness, ior, metalness, anisotropy, - new Label("(set to zero to disable)\n" + - "'Anisotropy' is effective only on the 'volume_cloud' material.")); + emittance, specular, perceptualSmoothness, ior, metalness); setPadding(new Insets(10)); setSpacing(15); TextField filterField = new TextField(); @@ -122,7 +116,6 @@ private void updateSelectedMaterial(String materialName) { double iorAcc = 0; double perceptualSmoothnessAcc = 0; double metalnessAcc = 0; - double anisotropyAcc = 0; Collection blocks = MaterialStore.collections.get(materialName); for (Block block : blocks) { emAcc += block.emittance; @@ -130,14 +123,12 @@ private void updateSelectedMaterial(String materialName) { iorAcc += block.ior; perceptualSmoothnessAcc += block.getPerceptualSmoothness(); metalnessAcc += block.metalness; - anisotropyAcc += block.anisotropy; } emittance.set(emAcc / blocks.size()); specular.set(specAcc / blocks.size()); ior.set(iorAcc / blocks.size()); perceptualSmoothness.set(perceptualSmoothnessAcc / blocks.size()); metalness.set(metalnessAcc / blocks.size()); - anisotropy.set(anisotropyAcc / blocks.size()); materialExists = true; } else if (ExtraMaterials.idMap.containsKey(materialName)) { Material material = ExtraMaterials.idMap.get(materialName); @@ -147,7 +138,6 @@ private void updateSelectedMaterial(String materialName) { ior.set(material.ior); perceptualSmoothness.set(material.getPerceptualSmoothness()); metalness.set(material.metalness); - anisotropy.set(material.anisotropy); materialExists = true; } } else if (MaterialStore.blockIds.contains(materialName)) { @@ -158,7 +148,6 @@ private void updateSelectedMaterial(String materialName) { ior.set(block.ior); perceptualSmoothness.set(block.getPerceptualSmoothness()); metalness.set(block.metalness); - anisotropy.set(block.anisotropy); materialExists = true; } if (materialExists) { @@ -167,14 +156,12 @@ private void updateSelectedMaterial(String materialName) { ior.onValueChange(value -> scene.setIor(materialName, value.floatValue())); perceptualSmoothness.onValueChange(value -> scene.setPerceptualSmoothness(materialName, value.floatValue())); metalness.onValueChange(value -> scene.setMetalness(materialName, value.floatValue())); - anisotropy.onValueChange(value -> scene.setAnisotropy(materialName, value.floatValue())); } else { emittance.onValueChange(value -> {}); specular.onValueChange(value -> {}); ior.onValueChange(value -> {}); perceptualSmoothness.onValueChange(value -> {}); metalness.onValueChange(value -> {}); - anisotropy.onValueChange(value -> {}); } } diff --git a/chunky/src/java/se/llbit/chunky/world/Material.java b/chunky/src/java/se/llbit/chunky/world/Material.java index 24f064b409..572af56774 100644 --- a/chunky/src/java/se/llbit/chunky/world/Material.java +++ b/chunky/src/java/se/llbit/chunky/world/Material.java @@ -75,8 +75,6 @@ public abstract class Material { */ public float metalness = 0; - public float anisotropy = 0; - /** * Subsurface scattering property. */ @@ -106,7 +104,6 @@ public void restoreDefaults() { specular = 0; emittance = 0; roughness = 0; - anisotropy = 0; subSurfaceScattering = false; } @@ -128,7 +125,6 @@ public void loadMaterialProperties(JsonObject json) { emittance = json.get("emittance").floatValue(emittance); roughness = json.get("roughness").floatValue(roughness); metalness = json.get("metalness").floatValue(metalness); - anisotropy = json.get("anisotropy").floatValue(anisotropy); } public boolean isWater() { diff --git a/chunky/src/java/se/llbit/chunky/world/VolumeMaterial.java b/chunky/src/java/se/llbit/chunky/world/VolumeMaterial.java index fcf82668dc..41bd1e4be4 100644 --- a/chunky/src/java/se/llbit/chunky/world/VolumeMaterial.java +++ b/chunky/src/java/se/llbit/chunky/world/VolumeMaterial.java @@ -8,6 +8,8 @@ import java.util.Random; public class VolumeMaterial extends Material { + public float anisotropy = 0; + public VolumeMaterial(String name, Texture texture) { super(name, texture); }