use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class GlobalPhotonMap method store.
@Override
public void store(ShadingState state, Vector3 dir, Color power, Color diffuse) {
Photon p = new Photon(state.getPoint(), state.getNormal(), dir, power, diffuse);
synchronized (this) {
storedPhotons++;
photonList.add(p);
bounds.include(new Point3(p.x, p.y, p.z));
maxPower = Math.max(maxPower, power.getMax());
}
}
use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class CausticPhotonMap method getSamples.
@Override
public void getSamples(ShadingState state) {
if (storedPhotons == 0) {
return;
}
NearestPhotons np = new NearestPhotons(state.getPoint(), gatherNum, gatherRadius * gatherRadius);
locatePhotons(np);
if (np.found < 8) {
return;
}
Point3 ppos = new Point3();
Vector3 pdir = new Vector3();
Vector3 pvec = new Vector3();
float invArea = 1.0f / ((float) Math.PI * np.dist2[0]);
float maxNDist = np.dist2[0] * 0.05f;
float f2r2 = 1.0f / (filterValue * filterValue * np.dist2[0]);
float fInv = 1.0f / (1.0f - 2.0f / (3.0f * filterValue));
for (int i = 1; i <= np.found; i++) {
Photon phot = np.index[i];
Vector3.decode(phot.dir, pdir);
float cos = -Vector3.dot(pdir, state.getNormal());
if (cos > 0.001) {
ppos.set(phot.x, phot.y, phot.z);
Point3.sub(ppos, state.getPoint(), pvec);
float pcos = Vector3.dot(pvec, state.getNormal());
if ((pcos < maxNDist) && (pcos > -maxNDist)) {
LightSample sample = new LightSample();
sample.setShadowRay(new Ray(state.getPoint(), pdir.negate()));
sample.setRadiance(new Color().setRGBE(np.index[i].power).mul(invArea / cos), Color.BLACK);
sample.getDiffuseRadiance().mul((1.0f - (float) Math.sqrt(np.dist2[i] * f2r2)) * fInv);
state.addSample(sample);
}
}
}
}
use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class GridPhotonMap method store.
@Override
public void store(ShadingState state, Vector3 dir, Color power, Color diffuse) {
// don't store on the wrong side of a surface
if (Vector3.dot(state.getNormal(), dir) > 0) {
return;
}
Point3 pt = state.getPoint();
// outside grid bounds ?
if (!bounds.contains(pt)) {
return;
}
Vector3 ext = bounds.getExtents();
int ix = (int) (((pt.x - bounds.getMinimum().x) * nx) / ext.x);
int iy = (int) (((pt.y - bounds.getMinimum().y) * ny) / ext.y);
int iz = (int) (((pt.z - bounds.getMinimum().z) * nz) / ext.z);
ix = MathUtils.clamp(ix, 0, nx - 1);
iy = MathUtils.clamp(iy, 0, ny - 1);
iz = MathUtils.clamp(iz, 0, nz - 1);
int id = ix + iy * nx + iz * nx * ny;
synchronized (this) {
int hid = id % cellHash.length;
PhotonGroup g = cellHash[hid];
PhotonGroup last = null;
boolean hasID = false;
while (g != null) {
if (g.id == id) {
hasID = true;
if (Vector3.dot(state.getNormal(), g.normal) > NORMAL_THRESHOLD) {
break;
}
}
last = g;
g = g.next;
}
if (g == null) {
g = new PhotonGroup(id, state.getNormal());
if (last == null) {
cellHash[hid] = g;
} else {
last.next = g;
}
if (!hasID) {
// we have not seen this ID before
hashSize++;
// resize hash if we have grown too large
if (hashSize > cellHash.length) {
growPhotonHash();
}
}
}
g.count++;
g.flux.add(power);
g.diffuse.add(diffuse);
numStoredPhotons++;
}
}
use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class BanchoffSurface method prepareShadingState.
@Override
public void prepareShadingState(ShadingState state) {
state.init();
state.getRay().getPoint(state.getPoint());
Instance parent = state.getInstance();
Point3 n = state.transformWorldToObject(state.getPoint());
state.getNormal().set(n.x * (2 * n.x * n.x - 1), n.y * (2 * n.y * n.y - 1), n.z * (2 * n.z * n.z - 1));
state.getNormal().normalize();
state.setShader(parent.getShader(0));
state.setModifier(parent.getModifier(0));
// into world space
Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
state.getNormal().set(worldNormal);
state.getNormal().normalize();
state.getGeoNormal().set(state.getNormal());
// create basis in world space
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
}
use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class CornellBox method update.
@Override
public boolean update(ParameterList pl, SunflowAPI api) {
Point3 corner0 = pl.getPoint("corner0", null);
Point3 corner1 = pl.getPoint("corner1", null);
if (corner0 != null && corner1 != null) {
updateGeometry(corner0, corner1);
}
// shader colors
left = pl.getColor("leftColor", left);
right = pl.getColor("rightColor", right);
top = pl.getColor("topColor", top);
bottom = pl.getColor("bottomColor", bottom);
back = pl.getColor("backColor", back);
// light
radiance = pl.getColor("radiance", radiance);
samples = pl.getInt("samples", samples);
return true;
}
Aggregations