use of org.jwildfire.base.mathlib.VecMathLib.VectorD 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;
}
use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.
the class PreWave3DWFFunc method transform.
@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
double r;
switch(axis) {
case AXIS_RADIAL:
r = sqrt(sqr(pAffineTP.x - centre_x) + sqr(pAffineTP.y - centre_y) + sqr(pAffineTP.z - centre_z));
break;
case AXIS_YZ:
r = sqrt(sqr(pAffineTP.y - centre_y) + sqr(pAffineTP.z - centre_z));
break;
case AXIS_ZX:
r = sqrt(sqr(pAffineTP.z - centre_z) + sqr(pAffineTP.x - centre_x));
break;
case AXIS_XY:
default:
r = sqrt(sqr(pAffineTP.x - centre_x) + sqr(pAffineTP.y - centre_y));
break;
}
double dl = r / wavelen;
double amplitude = pAmount;
if (fabs(damping) > SMALL_EPSILON) {
double dmp = -dl * damping;
amplitude *= exp(dmp);
}
double amp = amplitude * (double) sin(2.0 * M_PI * dl + phase);
switch(axis) {
case AXIS_RADIAL:
VectorD d = new VectorD(pAffineTP.x - centre_x, pAffineTP.y - centre_y, pAffineTP.z - centre_z);
d.normalize();
pAffineTP.x += d.x * amp;
pAffineTP.y += d.y * amp;
pAffineTP.z += d.z * amp;
break;
case AXIS_YZ:
pAffineTP.x += amp;
break;
case AXIS_ZX:
pAffineTP.y += amp;
break;
case AXIS_XY:
default:
pAffineTP.z += amp;
break;
}
}
use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.
the class YPlot3DWFFunc method transform.
@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
if (evaluator == null) {
return;
}
double randU = pContext.random();
double randV = pContext.random();
double x = _xmin + randU * _dx;
double z = _zmin + randV * _dz;
double y = evaluator.evaluate(x, z);
if (displacementMapHolder.isActive()) {
double epsx = _dx / 100.0;
double x1 = x + epsx;
double y1 = evaluator.evaluate(x1, z);
double epsz = _dz / 100.0;
double z1 = z + epsz;
double y2 = evaluator.evaluate(x, z1);
VectorD av = new VectorD(epsx, y1 - y, 0);
VectorD bv = new VectorD(0.0, y2 - y, epsz);
VectorD n = VectorD.cross(av, bv);
n.normalize();
double iu = GfxMathLib.clamp(randU * (displacementMapHolder.getDisplacementMapWidth() - 1.0), 0.0, displacementMapHolder.getDisplacementMapWidth() - 1.0);
double iv = GfxMathLib.clamp(displacementMapHolder.getDisplacementMapHeight() - 1.0 - randV * (displacementMapHolder.getDisplacementMapHeight() - 1.0), 0, displacementMapHolder.getDisplacementMapHeight() - 1.0);
int ix = (int) MathLib.trunc(iu);
int iy = (int) MathLib.trunc(iv);
double d = displacementMapHolder.calculateImageDisplacement(ix, iy, iu, iv) * _displ_amount;
pVarTP.x += pAmount * n.x * d;
pVarTP.y += pAmount * n.y * d;
pVarTP.z += pAmount * n.z * d;
}
if (direct_color > 0) {
switch(color_mode) {
case CM_X:
pVarTP.color = (x - _xmin) / _dx;
break;
case CM_Y:
pVarTP.color = (y - _ymin) / _dy;
break;
case CM_COLORMAP:
if (colorMapHolder.isActive()) {
double iu = GfxMathLib.clamp(randU * (colorMapHolder.getColorMapWidth() - 1.0), 0.0, colorMapHolder.getColorMapWidth() - 1.0);
double iv = GfxMathLib.clamp(colorMapHolder.getColorMapHeight() - 1.0 - randV * (colorMapHolder.getColorMapHeight() - 1.0), 0, colorMapHolder.getColorMapHeight() - 1.0);
int ix = (int) MathLib.trunc(iu);
int iy = (int) MathLib.trunc(iv);
colorMapHolder.applyImageColor(pVarTP, ix, iy, iu, iv);
pVarTP.color = getUVColorIdx(Tools.FTOI(pVarTP.redColor), Tools.FTOI(pVarTP.greenColor), Tools.FTOI(pVarTP.blueColor));
}
break;
case CM_XZ:
pVarTP.color = (x - _xmin) / _dx * (z - _zmin) / _dz;
break;
default:
case CM_Z:
pVarTP.color = (z - _zmin) / _dz;
break;
}
if (pVarTP.color < 0.0)
pVarTP.color = 0.0;
else if (pVarTP.color > 1.0)
pVarTP.color = 1.0;
}
pVarTP.x += pAmount * x;
pVarTP.y += pAmount * y;
pVarTP.z += pAmount * z;
}
use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.
the class DLA3DWFFunc method nodeTransform.
private VertexWithUV nodeTransform(VertexWithUV p, double preScale, double relScale, BoundingBox boundingBox, Matrix3D rotation) {
VertexWithUV res = new VertexWithUV();
double px, py, pz;
if (rotation != null) {
VectorD d = new VectorD(p.x - boundingBox.getXcentre(), p.y - boundingBox.getYcentre(), p.z - boundingBox.getZcentre());
VectorD r = Matrix3D.multiply(rotation, d);
px = r.x;
py = r.y;
pz = r.z;
} else {
px = p.x;
py = p.y;
pz = p.z;
}
res.x = (float) (px * preScale * relScale);
res.y = (float) (py * preScale * relScale);
res.z = (float) (pz * preScale * relScale);
res.u = p.u;
res.v = p.v;
return res;
}
use of org.jwildfire.base.mathlib.VecMathLib.VectorD in project JWildfire by thargor6.
the class DLA3DWFFunc method nodeTransform.
private Vertex nodeTransform(Vertex p, double preScale, double relScale, BoundingBox boundingBox, Matrix3D rotation) {
Vertex res = new Vertex();
double px, py, pz;
if (rotation != null) {
VectorD d = new VectorD(p.x - boundingBox.getXcentre(), p.y - boundingBox.getYcentre(), p.z - boundingBox.getZcentre());
VectorD r = Matrix3D.multiply(rotation, d);
px = r.x;
py = r.y;
pz = r.z;
} else {
px = p.x;
py = p.y;
pz = p.z;
}
res.x = (float) (px * preScale * relScale);
res.y = (float) (py * preScale * relScale);
res.z = (float) (pz * preScale * relScale);
return res;
}
Aggregations