use of org.jwildfire.base.mathlib.VecMathLib.RGBColorD in project JWildfire by thargor6.
the class LogDensityFilter method addSolidColors.
private boolean addSolidColors(LogDensityPoint dest, RasterPoint rp, double colorScale) {
if (solidRendering && rp.hasNormals) {
LightViewCalculator lightViewCalculator = raster.getLightViewCalculator();
double avgVisibility;
if (rp.hasShadows) {
avgVisibility = 0.0;
int shadowCount = 0;
for (int i = 0; i < rp.visibility.length; i++) {
avgVisibility += rp.visibility[i];
shadowCount++;
}
if (shadowCount > 0) {
avgVisibility /= (double) shadowCount;
} else {
avgVisibility = 1.0;
}
} else {
avgVisibility = 1.0;
}
RGBColorD rawColor;
MaterialSettings material = flame.getSolidRenderSettings().getInterpolatedMaterial(rp.material);
if (material == null) {
RGBColorD bgColor = new RGBColorD(dest.bgRed, dest.bgGreen, dest.bgBlue, 1.0 / VecMathLib.COLORSCL);
double visibility = 0.0;
for (int i = 0; i < flame.getSolidRenderSettings().getLights().size(); i++) {
DistantLight light = flame.getSolidRenderSettings().getLights().get(i);
visibility += light.isCastShadows() && rp.hasShadows ? rp.visibility[i] : avgVisibility;
}
visibility = GfxMathLib.clamp(visibility);
rawColor = new RGBColorD(bgColor, visibility);
} else {
double aoInt = Tools.limitValue(flame.getSolidRenderSettings().getAoIntensity(), 0.0, 4.0);
boolean withSSAO = flame.getSolidRenderSettings().isAoEnabled();
double ambientIntensity = Math.max(0.0, withSSAO ? (material.getAmbient() - rp.ao * aoInt) : material.getAmbient());
double aoDiffuseInfluence = flame.getSolidRenderSettings().getAoAffectDiffuse();
double diffuseIntensity = Math.max(0.0, withSSAO ? (material.getDiffuse() - rp.ao * aoInt * aoDiffuseInfluence) : material.getDiffuse());
double specularIntensity = material.getPhong();
SimpleImage reflectionMap = null;
if (material.getReflMapIntensity() > MathLib.EPSILON && material.getReflMapFilename() != null && material.getReflMapFilename().length() > 0) {
try {
reflectionMap = (SimpleImage) RessourceManager.getImage(material.getReflMapFilename());
} catch (Exception e) {
material.setReflMapFilename(null);
e.printStackTrace();
}
}
RGBColorD objColor = new RGBColorD(rp.solidRed * logScaleCalculator.getBalanceRed(), rp.solidGreen * logScaleCalculator.getBalanceGreen(), rp.solidBlue * logScaleCalculator.getBalanceBlue(), 1.0 / VecMathLib.COLORSCL);
rawColor = new RGBColorD(objColor, ambientIntensity * avgVisibility);
VectorD normal = new VectorD(rp.nx, rp.ny, rp.nz);
VectorD viewDir = new VectorD(0.0, 0.0, 1.0);
for (int i = 0; i < flame.getSolidRenderSettings().getLights().size(); i++) {
DistantLight light = flame.getSolidRenderSettings().getLights().get(i);
VectorD lightDir = lightViewCalculator.getLightDir()[i];
double visibility = light.isCastShadows() && rp.hasShadows ? rp.visibility[i] : avgVisibility;
double cosa = VectorD.dot(lightDir, normal);
if (cosa > MathLib.EPSILON) {
double diffResponse = material.getLightDiffFunc().evaluate(cosa);
rawColor.addFrom(light.getRed() + objColor.r * ambientIntensity / 3.0, light.getGreen() + objColor.g * ambientIntensity / 3.0, light.getBlue() + objColor.b * ambientIntensity / 3.0, visibility * diffResponse * diffuseIntensity * light.getIntensity());
}
if (specularIntensity > MathLib.EPSILON) {
VectorD r = VectorD.reflect(lightDir, normal);
double vr = VectorD.dot(viewDir, r);
if (vr < MathLib.EPSILON) {
double specularResponse = MathLib.pow(material.getLightDiffFunc().evaluate(-vr), material.getPhongSize());
rawColor.addFrom(material.getPhongRed(), material.getPhongGreen(), material.getPhongBlue(), visibility * specularResponse * specularIntensity * light.getIntensity());
}
}
// http://www.reindelsoftware.com/Documents/Mapping/Mapping.html
if (reflectionMap != null) {
double reflectionMapIntensity = Math.max(0.0, withSSAO ? (material.getReflMapIntensity() - rp.ao * aoInt * aoDiffuseInfluence) : material.getReflMapIntensity());
VectorD r = VectorD.reflect(viewDir, normal);
UVPairD uv;
switch(material.getReflectionMapping()) {
case SPHERICAL:
uv = UVPairD.sphericalOpenGlMapping(r);
break;
case BLINN_NEWELL:
default:
uv = UVPairD.sphericalBlinnNewellLatitudeMapping(r);
break;
}
RGBColorD reflMapColor = uv.getColorFromMap(reflectionMap);
rawColor.addFrom(reflMapColor.r * logScaleCalculator.getBalanceRed(), reflMapColor.g * logScaleCalculator.getBalanceGreen(), reflMapColor.b * logScaleCalculator.getBalanceBlue(), visibility * reflectionMapIntensity);
}
}
}
dest.solidRed += rawColor.r * colorScale * VecMathLib.COLORSCL;
dest.solidGreen += rawColor.g * colorScale * VecMathLib.COLORSCL;
dest.solidBlue += rawColor.b * colorScale * VecMathLib.COLORSCL;
dest.hasSolidColors = true;
return true;
}
return false;
}
Aggregations