1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package org.sunflow.core.shader;
import org.sunflow.SunflowAPI;
import org.sunflow.core.ParameterList;
import org.sunflow.core.Shader;
import org.sunflow.core.ShadingState;
import org.sunflow.image.Color;
public class AmbientOcclusionShader implements Shader {
private Color bright;
private Color dark;
private int samples;
private float maxDist;
public AmbientOcclusionShader() {
bright = Color.WHITE;
dark = Color.BLACK;
samples = 32;
maxDist = Float.POSITIVE_INFINITY;
}
public AmbientOcclusionShader(Color c, float d) {
this();
bright = c;
maxDist = d;
}
public boolean update(ParameterList pl, SunflowAPI api) {
bright = pl.getColor("bright", bright);
dark = pl.getColor("dark", dark);
samples = pl.getInt("samples", samples);
maxDist = pl.getFloat("maxdist", maxDist);
if (maxDist <= 0)
maxDist = Float.POSITIVE_INFINITY;
return true;
}
public Color getBrightColor(ShadingState state) {
return bright;
}
public Color getRadiance(ShadingState state) {
return state.occlusion(samples, maxDist, getBrightColor(state), dark);
}
public void scatterPhoton(ShadingState state, Color power) {
}
// EP : Added transparency management
public boolean isOpaque() {
return true;
}
public Color getOpacity(ShadingState state) {
return null;
}
// EP : End of modification
}
|