Beispiel #1
0
 public Color lookup(ShadingState state, IShader shader)
 {
     if (state.getNormal() == null)
     {
         return(null);
     }
     // search further
     for (Sample s = first; s != null; s = s.next)
     {
         if (s.i != state.getInstance())
         {
             continue;
         }
         if (s.s != shader)
         {
             continue;
         }
         if (state.getRay().dot(s.dx, s.dy, s.dz) < 0.999f)
         {
             continue;
         }
         if (state.getNormal().dot(s.nx, s.ny, s.nz) < 0.99f)
         {
             continue;
         }
         // we have a match
         hits++;
         return(s.c);
     }
     misses++;
     return(null);
 }
Beispiel #2
0
 private Color lookupShadingCache(ShadingState state, IShader shader)
 {
     lock (lockObj)
     {
         if (state.getNormal() == null)
         {
             return(null);
         }
         cacheLookups++;
         int        cx   = (int)(state.getRasterX() * shadingCacheResolution);
         int        cy   = (int)(state.getRasterY() * shadingCacheResolution);
         int        hash = hashfunc(cx, cy);
         CacheEntry e    = _shadingCache[hash & (_shadingCache.Length - 1)];
         if (e == null)
         {
             cacheEmptyEntryMisses++;
             return(null);
         }
         // entry maps to correct pixel
         if (e.cx == cx && e.cy == cy)
         {
             // search further
             for (Sample s = e.first; s != null; s = s.next)
             {
                 if (s.i != state.getInstance())
                 {
                     continue;
                 }
                 // if (s.prim != state.getPrimitiveID())
                 // continue;
                 if (s.s != shader)
                 {
                     continue;
                 }
                 if (state.getNormal().dot(s.nx, s.ny, s.nz) < 0.95f)
                 {
                     continue;
                 }
                 // we have a match
                 cacheHits++;
                 return(s.c);
             }
         }
         else
         {
             cacheWrongEntryMisses++;
         }
         return(null);
     }
 }
Beispiel #3
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 #4
0
 private void addShadingCache(ShadingState state, IShader shader, Color c)
 {
     lock (lockObj)
     {
         // don't cache samples with null normals
         if (state.getNormal() == null)
         {
             return;
         }
         cacheEntryAdditions++;
         int        cx = (int)(state.getRasterX() * shadingCacheResolution);
         int        cy = (int)(state.getRasterY() * shadingCacheResolution);
         int        h  = hashfunc(cx, cy) & (_shadingCache.Length - 1);
         CacheEntry e  = _shadingCache[h];
         // new entry ?
         if (e == null)
         {
             e = _shadingCache[h] = new CacheEntry();
         }
         Sample s = new Sample();
         s.i = state.getInstance();
         // s.prim = state.getPrimitiveID();
         s.s  = shader;
         s.c  = c;
         s.nx = state.getNormal().x;
         s.ny = state.getNormal().y;
         s.nz = state.getNormal().z;
         if (e.cx == cx && e.cy == cy)
         {
             // same pixel - just add to the front of the list
             s.next  = e.first;
             e.first = s;
         }
         else
         {
             // different pixel - new list
             e.cx    = cx;
             e.cy    = cy;
             s.next  = null;
             e.first = s;
         }
     }
 }
Beispiel #5
0
        public void add(ShadingState state, IShader shader, Color c)
        {
            if (state.getNormal() == null)
            {
                return;
            }
            depth++;
            Sample s = new Sample();

            s.i    = state.getInstance();
            s.s    = shader;
            s.c    = c;
            s.dx   = state.getRay().dx;
            s.dy   = state.getRay().dy;
            s.dz   = state.getRay().dz;
            s.nx   = state.getNormal().x;
            s.ny   = state.getNormal().y;
            s.nz   = state.getNormal().z;
            s.next = first;
            first  = s;
        }
Beispiel #6
0
 /**
  * Prepare the shading state for shader invocation. This also runs the
  * currently attached surface modifier.
  *
  * @param state shading state to be prepared
  */
 public void prepareShadingState(ShadingState state)
 {
     geometry.prepareShadingState(state);
     if (state.getNormal() != null && state.getGeoNormal() != null)
     {
         state.correctShadingNormal();
     }
     // run modifier if it was provided
     if (state.getModifier() != null)
     {
         state.getModifier().modify(state);
     }
 }