Search in sources :

Example 36 with Point3

use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.

the class ShadingState method init.

/**
 * Create objects needed for surface shading: point, normal, texture
 * coordinates and basis.
 */
public final void init() {
    p = new Point3();
    n = new Vector3();
    tex = new Point2();
    ng = new Vector3();
    basis = null;
}
Also used : Point3(org.sunflow.math.Point3) Point2(org.sunflow.math.Point2) Vector3(org.sunflow.math.Vector3)

Example 37 with Point3

use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.

the class ShadingState method getTrianglePoints.

/**
 * Get the three triangle corners in object space if the hit object is a
 * mesh, returns false otherwise.
 *
 * @param p array of 3 points
 * @return <code>true</code> if the points were read succesfully,
 * <code>false</code>otherwise
 */
public final boolean getTrianglePoints(Point3[] p) {
    PrimitiveList prims = instance.getGeometry().getPrimitiveList();
    if (prims instanceof TriangleMesh) {
        TriangleMesh m = (TriangleMesh) prims;
        m.getPoint(primitiveID, 0, p[0] = new Point3());
        m.getPoint(primitiveID, 1, p[1] = new Point3());
        m.getPoint(primitiveID, 2, p[2] = new Point3());
        return true;
    }
    return false;
}
Also used : Point3(org.sunflow.math.Point3) TriangleMesh(org.sunflow.core.primitive.TriangleMesh)

Example 38 with Point3

use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.

the class KDTree method dumpObj.

private int dumpObj(int offset, int vertOffset, int maxN, BoundingBox bounds, FileWriter file, FileWriter mtlFile) throws IOException {
    if (offset == 0) {
        file.write(String.format("mtllib %s.mtl\n", dumpPrefix));
    }
    int nextOffset = tree[offset];
    String FACE_FORMAT = "f %d %d %d %d\n";
    String VERTEX_FORMAT = "v %g %g %g\n";
    if ((nextOffset & (3 << 30)) == (3 << 30)) {
        // leaf
        int n = tree[offset + 1];
        if (n > 0) {
            // output the current voxel to the file
            Point3 min = bounds.getMinimum();
            Point3 max = bounds.getMaximum();
            file.write(String.format("o node%d\n", offset));
            file.write(String.format(VERTEX_FORMAT, max.x, max.y, min.z));
            file.write(String.format(VERTEX_FORMAT, max.x, min.y, min.z));
            file.write(String.format(VERTEX_FORMAT, min.x, min.y, min.z));
            file.write(String.format(VERTEX_FORMAT, min.x, max.y, min.z));
            file.write(String.format(VERTEX_FORMAT, max.x, max.y, max.z));
            file.write(String.format(VERTEX_FORMAT, max.x, min.y, max.z));
            file.write(String.format(VERTEX_FORMAT, min.x, min.y, max.z));
            file.write(String.format(VERTEX_FORMAT, min.x, max.y, max.z));
            int v0 = vertOffset;
            file.write(String.format("usemtl mtl%d\n", n));
            file.write("s off\n");
            file.write(String.format(FACE_FORMAT, v0 + 1, v0 + 2, v0 + 3, v0 + 4));
            file.write(String.format(FACE_FORMAT, v0 + 5, v0 + 8, v0 + 7, v0 + 6));
            file.write(String.format(FACE_FORMAT, v0 + 1, v0 + 5, v0 + 6, v0 + 2));
            file.write(String.format(FACE_FORMAT, v0 + 2, v0 + 6, v0 + 7, v0 + 3));
            file.write(String.format(FACE_FORMAT, v0 + 3, v0 + 7, v0 + 8, v0 + 4));
            file.write(String.format(FACE_FORMAT, v0 + 5, v0 + 1, v0 + 4, v0 + 8));
            vertOffset += 8;
        }
        return vertOffset;
    } else {
        // node, recurse
        int axis = nextOffset & (3 << 30), v0;
        float split = Float.intBitsToFloat(tree[offset + 1]), min, max;
        nextOffset &= ~(3 << 30);
        switch(axis) {
            case 0:
                max = bounds.getMaximum().x;
                bounds.getMaximum().x = split;
                v0 = dumpObj(nextOffset, vertOffset, maxN, bounds, file, mtlFile);
                // restore and go to other side
                bounds.getMaximum().x = max;
                min = bounds.getMinimum().x;
                bounds.getMinimum().x = split;
                v0 = dumpObj(nextOffset + 2, v0, maxN, bounds, file, mtlFile);
                bounds.getMinimum().x = min;
                break;
            case 1 << 30:
                max = bounds.getMaximum().y;
                bounds.getMaximum().y = split;
                v0 = dumpObj(nextOffset, vertOffset, maxN, bounds, file, mtlFile);
                // restore and go to other side
                bounds.getMaximum().y = max;
                min = bounds.getMinimum().y;
                bounds.getMinimum().y = split;
                v0 = dumpObj(nextOffset + 2, v0, maxN, bounds, file, mtlFile);
                bounds.getMinimum().y = min;
                break;
            case 2 << 30:
                max = bounds.getMaximum().z;
                bounds.getMaximum().z = split;
                v0 = dumpObj(nextOffset, vertOffset, maxN, bounds, file, mtlFile);
                // restore and go to other side
                bounds.getMaximum().z = max;
                min = bounds.getMinimum().z;
                bounds.getMinimum().z = split;
                v0 = dumpObj(nextOffset + 2, v0, maxN, bounds, file, mtlFile);
                // restore and go to other side
                bounds.getMinimum().z = min;
                break;
            default:
                v0 = vertOffset;
                break;
        }
        return v0;
    }
}
Also used : Point3(org.sunflow.math.Point3)

Example 39 with Point3

use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.

the class Scene method getRadiance.

/**
 * Get the radiance seen through a particular pixel
 *
 * @param istate intersection state for ray tracing
 * @param rx pixel x coordinate
 * @param ry pixel y coordinate
 * @param lensU DOF sampling variable
 * @param lensV DOF sampling variable
 * @param time motion blur sampling variable
 * @param instance QMC instance seed
 * @return a shading state for the intersected primitive, or
 * <code>null</code> if nothing is seen through the specifieFd point
 */
public ShadingState getRadiance(IntersectionState istate, float rx, float ry, double lensU, double lensV, double time, int instance, int dim, ShadingCache cache) {
    istate.numEyeRays++;
    float sceneTime = camera.getTime((float) time);
    if (bakingPrimitives == null) {
        Ray r = camera.getRay(rx, ry, imageWidth, imageHeight, lensU, lensV, sceneTime);
        return r != null ? lightServer.getRadiance(rx, ry, sceneTime, instance, dim, r, istate, cache) : null;
    } else {
        Ray r = new Ray(rx / imageWidth, ry / imageHeight, -1, 0, 0, 1);
        traceBake(r, istate);
        if (!istate.hit()) {
            return null;
        }
        ShadingState state = ShadingState.createState(istate, rx, ry, sceneTime, r, instance, dim, lightServer);
        bakingPrimitives.prepareShadingState(state);
        if (bakingViewDependent) {
            state.setRay(camera.getRay(state.getPoint(), sceneTime));
        } else {
            Point3 p = state.getPoint();
            Vector3 n = state.getNormal();
            // create a ray coming from directly above the point being
            // shaded
            Ray incoming = new Ray(p.x + n.x, p.y + n.y, p.z + n.z, -n.x, -n.y, -n.z);
            incoming.setMax(1);
            state.setRay(incoming);
        }
        lightServer.shadeBakeResult(state);
        return state;
    }
}
Also used : Point3(org.sunflow.math.Point3) Vector3(org.sunflow.math.Vector3)

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