Skip to content

Commit

Permalink
Remove Anisotropy from Materials tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Peregrine05 committed Oct 22, 2023
1 parent b7b1121 commit e83219a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 5 additions & 5 deletions chunky/src/java/se/llbit/chunky/renderer/scene/PathTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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();

Expand Down
15 changes: 1 addition & 14 deletions chunky/src/java/se/llbit/chunky/ui/render/tabs/MaterialsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> listView;

public MaterialsTab() {
Expand All @@ -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<String> blockIds = FXCollections.observableArrayList();
blockIds.addAll(MaterialStore.collections.keySet());
blockIds.addAll(ExtraMaterials.idMap.keySet());
Expand All @@ -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();
Expand Down Expand Up @@ -122,22 +116,19 @@ private void updateSelectedMaterial(String materialName) {
double iorAcc = 0;
double perceptualSmoothnessAcc = 0;
double metalnessAcc = 0;
double anisotropyAcc = 0;
Collection<Block> blocks = MaterialStore.collections.get(materialName);
for (Block block : blocks) {
emAcc += block.emittance;
specAcc += block.specular;
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);
Expand All @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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 -> {});
}
}

Expand Down
4 changes: 0 additions & 4 deletions chunky/src/java/se/llbit/chunky/world/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public abstract class Material {
*/
public float metalness = 0;

public float anisotropy = 0;

/**
* Subsurface scattering property.
*/
Expand Down Expand Up @@ -106,7 +104,6 @@ public void restoreDefaults() {
specular = 0;
emittance = 0;
roughness = 0;
anisotropy = 0;
subSurfaceScattering = false;
}

Expand All @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions chunky/src/java/se/llbit/chunky/world/VolumeMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e83219a

Please sign in to comment.