Beispiel #1
0
 /**
  * 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)
 {
     if (bakingPrimitives == null)
     {
         Ray r = camera.getRay(rx, ry, imageWidth, imageHeight, lensU, lensV, time);
         return(r != null?lightServer.getRadiance(rx, ry, instance, r, istate) : 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, r, instance, lightServer);
         bakingPrimitives.prepareShadingState(state);
         if (bakingViewDependent)
         {
             state.setRay(camera.getRay(state.getPoint()));
         }
         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);
     }
 }
Beispiel #2
0
        public ShadingState traceFinalGather(ShadingState previous, Ray r, int i)
        {
            if (previous.getDiffuseDepth() >= maxDiffuseDepth)
            {
                return(null);
            }
            IntersectionState istate = previous.getIntersectionState();

            scene.trace(r, istate);
            return(istate.hit() ? ShadingState.createFinalGatherState(previous, r, i) : null);
        }
Beispiel #3
0
        public Color traceRefraction(ShadingState previous, Ray r, int i)
        {
            // limit path depth and disable caustic paths
            if (previous.getRefractionDepth() >= maxRefractionDepth || previous.getDiffuseDepth() > 0)
            {
                return(Color.BLACK);
            }
            IntersectionState istate = previous.getIntersectionState();

            scene.trace(r, istate);
            return(istate.hit() ? shadeHit(ShadingState.createRefractionBounceState(previous, r, i)) : Color.BLACK);
        }
Beispiel #4
0
            public void Run()
            {
                ByteUtil.InitByteUtil();
                IntersectionState istate = new IntersectionState();

                for (int i = start; i < end; i++)
                {
                    lock (lockObj)
                    {
                        UI.taskUpdate(server.photonCounter);
                        server.photonCounter++;
                        if (UI.taskCanceled())
                        {
                            return;
                        }
                    }

                    int qmcI = i + seed;

                    double rand = QMC.halton(0, qmcI) * histogram[histogram.Length - 1];
                    int    j    = 0;
                    while (rand >= histogram[j] && j < histogram.Length)
                    {
                        j++;
                    }
                    // make sure we didn't pick a zero-probability light
                    if (j == histogram.Length)
                    {
                        continue;
                    }

                    double  randX1 = (j == 0) ? rand / histogram[0] : (rand - histogram[j]) / (histogram[j] - histogram[j - 1]);
                    double  randY1 = QMC.halton(1, qmcI);
                    double  randX2 = QMC.halton(2, qmcI);
                    double  randY2 = QMC.halton(3, qmcI);
                    Point3  pt     = new Point3();
                    Vector3 dir    = new Vector3();
                    Color   power  = new Color();
                    server.lights[j].getPhoton(randX1, randY1, randX2, randY2, pt, dir, power);
                    power.mul(scale);
                    Ray r = new Ray(pt, dir);
                    server.scene.trace(r, istate);
                    if (istate.hit())
                    {
                        server.shadePhoton(ShadingState.createPhotonState(r, istate, qmcI, map, server), power);
                    }
                }
            }
Beispiel #5
0
 public ShadingState getRadiance(float rx, float ry, int i, Ray r, IntersectionState istate)
 {
     lock (lockObj)
     {
         scene.trace(r, istate);
         if (istate.hit())
         {
             ShadingState state = ShadingState.createState(istate, rx, ry, r, i, this);
             state.getInstance().prepareShadingState(state);
             IShader shader = getShader(state);
             if (shader == null)
             {
                 state.setResult(Color.BLACK);
                 return(state);
             }
             if (_shadingCache != null)
             {
                 Color c = lookupShadingCache(state, shader);
                 if (c != null)
                 {
                     state.setResult(c);
                     return(state);
                 }
             }
             state.setResult(shader.getRadiance(state));
             if (_shadingCache != null)
             {
                 addShadingCache(state, shader, state.getResult());
             }
             return(state);
         }
         else
         {
             return(null);
         }
     }
 }
Beispiel #6
0
 public ShadingState getRadiance(float rx, float ry, float time, int i, int d, Ray r, IntersectionState istate, ShadingCache cache)
 {
     istate.time = time;
     scene.trace(r, istate);
     if (istate.hit())
     {
         ShadingState state = ShadingState.createState(istate, rx, ry, time, r, i, d, this);
         state.getInstance().prepareShadingState(state);
         IShader shader = getShader(state);
         if (shader == null)
         {
             state.setResult(Color.BLACK);
             return(state);
         }
         if (cache != null)
         {
             Color c = cache.lookup(state, shader);
             if (c != null)
             {
                 state.setResult(c);
                 return(state);
             }
         }
         state.setResult(shader.GetRadiance(state));
         if (cache != null)
         {
             cache.add(state, shader, state.getResult());
         }
         checkNanInf(state.getResult());
         return(state);
     }
     else
     {
         return(null);
     }
 }
Beispiel #7
0
            public void Run()
            {
                ByteUtil.InitByteUtil();
                IntersectionState istate = new IntersectionState();
                for (int i = start; i < end; i++)
                {
                    lock (lockObj)
                    {
                        UI.taskUpdate(server.photonCounter);
                        server.photonCounter++;
                        if (UI.taskCanceled())
                            return;
                    }

                    int qmcI = i + seed;

                    double rand = QMC.halton(0, qmcI) * histogram[histogram.Length - 1];
                    int j = 0;
                    while (rand >= histogram[j] && j < histogram.Length)
                        j++;
                    // make sure we didn't pick a zero-probability light
                    if (j == histogram.Length)
                        continue;

                    double randX1 = (j == 0) ? rand / histogram[0] : (rand - histogram[j]) / (histogram[j] - histogram[j - 1]);
                    double randY1 = QMC.halton(1, qmcI);
                    double randX2 = QMC.halton(2, qmcI);
                    double randY2 = QMC.halton(3, qmcI);
                    Point3 pt = new Point3();
                    Vector3 dir = new Vector3();
                    Color power = new Color();
                    server.lights[j].getPhoton(randX1, randY1, randX2, randY2, pt, dir, power);
                    power.mul(scale);
                    Ray r = new Ray(pt, dir);
                    server.scene.trace(r, istate);
                    if (istate.hit())
                        server.shadePhoton(ShadingState.createPhotonState(r, istate, qmcI, map, server), power);
                }
            }
Beispiel #8
0
 public ShadingState getRadiance(float rx, float ry, float time, int i, int d, Ray r, IntersectionState istate, ShadingCache cache)
 {
     istate.time = time;
     scene.trace(r, istate);
     if (istate.hit()) {
         ShadingState state = ShadingState.createState(istate, rx, ry, time, r, i, d, this);
         state.getInstance().prepareShadingState(state);
         IShader shader = getShader(state);
         if (shader == null) {
             state.setResult(Color.BLACK);
             return state;
         }
         if (cache != null) {
             Color c = cache.lookup(state, shader);
             if (c != null) {
                 state.setResult(c);
                 return state;
             }
         }
         state.setResult(shader.GetRadiance(state));
         if (cache != null)
             cache.add(state, shader, state.getResult());
         checkNanInf(state.getResult());
         return state;
     } else
         return null;
 }
Beispiel #9
0
 public void intersect(Ray r, IntersectionState state)
 {
     float intervalMin = r.getMin();
     float intervalMax = r.getMax();
     float orgX = r.ox;
     float dirX = r.dx, invDirX = 1 / dirX;
     float t1, t2;
     t1 = (bounds.getMinimum().x - orgX) * invDirX;
     t2 = (bounds.getMaximum().x - orgX) * invDirX;
     if (invDirX > 0)
     {
         if (t1 > intervalMin)
             intervalMin = t1;
         if (t2 < intervalMax)
             intervalMax = t2;
     }
     else
     {
         if (t2 > intervalMin)
             intervalMin = t2;
         if (t1 < intervalMax)
             intervalMax = t1;
     }
     if (intervalMin > intervalMax)
         return;
     float orgY = r.oy;
     float dirY = r.dy, invDirY = 1 / dirY;
     t1 = (bounds.getMinimum().y - orgY) * invDirY;
     t2 = (bounds.getMaximum().y - orgY) * invDirY;
     if (invDirY > 0)
     {
         if (t1 > intervalMin)
             intervalMin = t1;
         if (t2 < intervalMax)
             intervalMax = t2;
     }
     else
     {
         if (t2 > intervalMin)
             intervalMin = t2;
         if (t1 < intervalMax)
             intervalMax = t1;
     }
     if (intervalMin > intervalMax)
         return;
     float orgZ = r.oz;
     float dirZ = r.dz, invDirZ = 1 / dirZ;
     t1 = (bounds.getMinimum().z - orgZ) * invDirZ;
     t2 = (bounds.getMaximum().z - orgZ) * invDirZ;
     if (invDirZ > 0)
     {
         if (t1 > intervalMin)
             intervalMin = t1;
         if (t2 < intervalMax)
             intervalMax = t2;
     }
     else
     {
         if (t2 > intervalMin)
             intervalMin = t2;
         if (t1 < intervalMax)
             intervalMax = t1;
     }
     if (intervalMin > intervalMax)
         return;
     // box is hit at [intervalMin, intervalMax]
     orgX += intervalMin * dirX;
     orgY += intervalMin * dirY;
     orgZ += intervalMin * dirZ;
     // locate starting point inside the grid
     // and set up 3D-DDA vars
     int indxX, indxY, indxZ;
     int stepX, stepY, stepZ;
     int stopX, stopY, stopZ;
     float deltaX, deltaY, deltaZ;
     float tnextX, tnextY, tnextZ;
     // stepping factors along X
     indxX = (int)((orgX - bounds.getMinimum().x) * invVoxelwx);
     if (indxX < 0)
         indxX = 0;
     else if (indxX >= nx)
         indxX = nx - 1;
     if (Math.Abs(dirX) < 1e-6f)
     {
         stepX = 0;
         stopX = indxX;
         deltaX = 0;
         tnextX = float.PositiveInfinity;
     }
     else if (dirX > 0)
     {
         stepX = 1;
         stopX = nx;
         deltaX = voxelwx * invDirX;
         tnextX = intervalMin + ((indxX + 1) * voxelwx + bounds.getMinimum().x - orgX) * invDirX;
     }
     else
     {
         stepX = -1;
         stopX = -1;
         deltaX = -voxelwx * invDirX;
         tnextX = intervalMin + (indxX * voxelwx + bounds.getMinimum().x - orgX) * invDirX;
     }
     // stepping factors along Y
     indxY = (int)((orgY - bounds.getMinimum().y) * invVoxelwy);
     if (indxY < 0)
         indxY = 0;
     else if (indxY >= ny)
         indxY = ny - 1;
     if (Math.Abs(dirY) < 1e-6f)
     {
         stepY = 0;
         stopY = indxY;
         deltaY = 0;
         tnextY = float.PositiveInfinity;
     }
     else if (dirY > 0)
     {
         stepY = 1;
         stopY = ny;
         deltaY = voxelwy * invDirY;
         tnextY = intervalMin + ((indxY + 1) * voxelwy + bounds.getMinimum().y - orgY) * invDirY;
     }
     else
     {
         stepY = -1;
         stopY = -1;
         deltaY = -voxelwy * invDirY;
         tnextY = intervalMin + (indxY * voxelwy + bounds.getMinimum().y - orgY) * invDirY;
     }
     // stepping factors along Z
     indxZ = (int)((orgZ - bounds.getMinimum().z) * invVoxelwz);
     if (indxZ < 0)
         indxZ = 0;
     else if (indxZ >= nz)
         indxZ = nz - 1;
     if (Math.Abs(dirZ) < 1e-6f)
     {
         stepZ = 0;
         stopZ = indxZ;
         deltaZ = 0;
         tnextZ = float.PositiveInfinity;
     }
     else if (dirZ > 0)
     {
         stepZ = 1;
         stopZ = nz;
         deltaZ = voxelwz * invDirZ;
         tnextZ = intervalMin + ((indxZ + 1) * voxelwz + bounds.getMinimum().z - orgZ) * invDirZ;
     }
     else
     {
         stepZ = -1;
         stopZ = -1;
         deltaZ = -voxelwz * invDirZ;
         tnextZ = intervalMin + (indxZ * voxelwz + bounds.getMinimum().z - orgZ) * invDirZ;
     }
     int cellstepX = stepX;
     int cellstepY = stepY * nx;
     int cellstepZ = stepZ * ny * nx;
     int cell = indxX + indxY * nx + indxZ * ny * nx;
     // trace through the grid
     for (; ; )
     {
         if (tnextX < tnextY && tnextX < tnextZ)
         {
             if (cells[cell] != null)
             {
                 foreach (int i in cells[cell])
                     primitives.intersectPrimitive(r, i, state);
                 if (state.hit() && (r.getMax() < tnextX && r.getMax() < intervalMax))
                     return;
             }
             intervalMin = tnextX;
             if (intervalMin > intervalMax)
                 return;
             indxX += stepX;
             if (indxX == stopX)
                 return;
             tnextX += deltaX;
             cell += cellstepX;
         }
         else if (tnextY < tnextZ)
         {
             if (cells[cell] != null)
             {
                 foreach (int i in cells[cell])
                     primitives.intersectPrimitive(r, i, state);
                 if (state.hit() && (r.getMax() < tnextY && r.getMax() < intervalMax))
                     return;
             }
             intervalMin = tnextY;
             if (intervalMin > intervalMax)
                 return;
             indxY += stepY;
             if (indxY == stopY)
                 return;
             tnextY += deltaY;
             cell += cellstepY;
         }
         else
         {
             if (cells[cell] != null)
             {
                 foreach (int i in cells[cell])
                     primitives.intersectPrimitive(r, i, state);
                 if (state.hit() && (r.getMax() < tnextZ && r.getMax() < intervalMax))
                     return;
             }
             intervalMin = tnextZ;
             if (intervalMin > intervalMax)
                 return;
             indxZ += stepZ;
             if (indxZ == stopZ)
                 return;
             tnextZ += deltaZ;
             cell += cellstepZ;
         }
     }
 }
Beispiel #10
0
 public ShadingState getRadiance(float rx, float ry, int i, Ray r, IntersectionState istate)
 {
     lock (lockObj)
     {
         scene.trace(r, istate);
         if (istate.hit())
         {
             ShadingState state = ShadingState.createState(istate, rx, ry, r, i, this);
             state.getInstance().prepareShadingState(state);
             IShader shader = getShader(state);
             if (shader == null)
             {
                 state.setResult(Color.BLACK);
                 return state;
             }
             if (_shadingCache != null)
             {
                 Color c = lookupShadingCache(state, shader);
                 if (c != null)
                 {
                     state.setResult(c);
                     return state;
                 }
             }
             state.setResult(shader.getRadiance(state));
             if (_shadingCache != null)
                 addShadingCache(state, shader, state.getResult());
             return state;
         }
         else
             return null;
     }
 }
Beispiel #11
0
 public Color traceShadow(Ray r, IntersectionState state)
 {
     trace(r, state);
     return state.hit() ? Color.WHITE : Color.BLACK;
 }
Beispiel #12
0
 /**
  * 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)
 {
     if (bakingPrimitives == null)
     {
         Ray r = camera.getRay(rx, ry, imageWidth, imageHeight, lensU, lensV, time);
         return r != null ? lightServer.getRadiance(rx, ry, instance, r, istate) : 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, r, instance, lightServer);
         bakingPrimitives.prepareShadingState(state);
         if (bakingViewDependent)
             state.setRay(camera.getRay(state.getPoint()));
         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;
     }
 }
Beispiel #13
0
 public Color traceShadow(Ray r, IntersectionState state)
 {
     state.numShadowRays++;
     trace(r, state);
     return(state.hit() ? Color.WHITE : Color.BLACK);
 }