Search in sources :

Example 16 with Point3

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());
    }
}
Also used : Point3(org.sunflow.math.Point3)

Example 17 with Point3

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);
            }
        }
    }
}
Also used : Point3(org.sunflow.math.Point3) LightSample(org.sunflow.core.LightSample) Color(org.sunflow.image.Color) Vector3(org.sunflow.math.Vector3) Ray(org.sunflow.core.Ray)

Example 18 with Point3

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++;
    }
}
Also used : Point3(org.sunflow.math.Point3) Vector3(org.sunflow.math.Vector3)

Example 19 with Point3

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()));
}
Also used : Point3(org.sunflow.math.Point3) Instance(org.sunflow.core.Instance) Vector3(org.sunflow.math.Vector3)

Example 20 with Point3

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;
}
Also used : Point3(org.sunflow.math.Point3)

Aggregations

Point3 (org.sunflow.math.Point3)39 Vector3 (org.sunflow.math.Vector3)27 Instance (org.sunflow.core.Instance)9 Color (org.sunflow.image.Color)7 Ray (org.sunflow.core.Ray)5 LightSample (org.sunflow.core.LightSample)4 TriangleMesh (org.sunflow.core.primitive.TriangleMesh)3 ParameterList (org.sunflow.core.ParameterList)2 Matrix4 (org.sunflow.math.Matrix4)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 FloatBuffer (java.nio.FloatBuffer)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 PrimitiveList (org.sunflow.core.PrimitiveList)1 SceneParser (org.sunflow.core.SceneParser)1 ShadingState (org.sunflow.core.ShadingState)1 QuadMesh (org.sunflow.core.primitive.QuadMesh)1 BoundingBox (org.sunflow.math.BoundingBox)1