public static ShadingState createDiffuseBounceState(ShadingState previous, Ray r, int i) { ShadingState s = new ShadingState(previous, previous.istate, r, i, 2); s.diffuseDepth++; return(s); }
public static ShadingState createRefractionBounceState(ShadingState previous, Ray r, int i) { ShadingState s = new ShadingState(previous, previous.istate, r, i, 2); s.refractionDepth++; return(s); }
public void initCausticSamples(ShadingState state) { if (causticPhotonMap != null) { causticPhotonMap.getSamples(state); } }
public void initLightSamples(ShadingState state) { foreach (LightSource l in lights) { l.getSamples(state); } }
public Color shadeHit(ShadingState state) { state.getInstance().prepareShadingState(state); IShader shader = getShader(state); return((shader != null) ? shader.GetRadiance(state) : Color.BLACK); }
/** * Trace the shadow ray, attenuating the sample's color by the opacity of * intersected objects. * * @param state shading state representing the point to be shaded */ public void traceShadow(ShadingState state) { Color opacity = state.traceShadow(shadowRay); Color.blend(ldiff, Color.BLACK, opacity, ldiff); Color.blend(lspec, Color.BLACK, opacity, lspec); }
/** * 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); } }
public Color getGlobalRadiance(ShadingState state) { if (giEngine == null) { return(Color.BLACK); } return(giEngine.getGlobalRadiance(state)); }
public static ShadingState createPhotonState(Ray r, IntersectionState istate, int i, PhotonStore map, LightServer server) { ShadingState s = new ShadingState(null, istate, r, i, 4); s.server = server; s.map = map; return(s); }
public static ShadingState createFinalGatherState(ShadingState state, Ray r, int i) { ShadingState finalGatherState = new ShadingState(state, state.istate, r, i, 2); finalGatherState.diffuseDepth++; finalGatherState.includeLights = false; finalGatherState.includeSpecular = false; return(finalGatherState); }
public Color getIrradiance(ShadingState state, Color diffuseReflectance) { // no gi engine, or we have already exceeded number of available bounces if (giEngine == null || state.getDiffuseDepth() >= maxDiffuseDepth) { return(Color.BLACK); } return(giEngine.getIrradiance(state, diffuseReflectance)); }
public static ShadingState createState(IntersectionState istate, float rx, float ry, Ray r, int i, LightServer server) { ShadingState s = new ShadingState(null, istate, r, i, 4); s.server = server; s.rx = rx; s.ry = ry; return(s); }
public static ShadingState createGlossyBounceState(ShadingState previous, Ray r, int i) { ShadingState s = new ShadingState(previous, previous.istate, r, i, 2); s.includeLights = false; s.includeSpecular = false; s.reflectionDepth++; return(s); }
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); }
void shadePhoton(ShadingState state, Color power) { state.getInstance().prepareShadingState(state); IShader shader = getPhotonShader(state); // scatter photon if (shader != null) { shader.scatterPhoton(state, power); } }
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); }
public void shadeBakeResult(ShadingState state) { IShader shader = getShader(state); if (shader != null) { state.setResult(shader.getRadiance(state)); } else { state.setResult(Color.BLACK); } }
/** * 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); } }
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); } }
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); } } }
public void traceRefractionPhoton(ShadingState previous, Ray r, Color power) { if (previous.getRefractionDepth() >= maxRefractionDepth) { return; } IntersectionState istate = previous.getIntersectionState(); scene.trace(r, istate); if (previous.getIntersectionState().hit()) { // create a new shading context ShadingState state = ShadingState.createRefractionBounceState(previous, r, 0); shadePhoton(state, power); } }
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; } } }
private ShadingState(ShadingState previous, IntersectionState istate, Ray r, int i, int d) { this.r = r; this.istate = istate; this.i = i; this.d = d; time = istate.time; instance = istate.instance; // local copy primitiveID = istate.id; hitU = istate.u; hitV = istate.v; hitW = istate.w; // get matrices for current time o2w = instance.getObjectToWorld(time); w2o = instance.getWorldToObject(time); if (previous == null) { diffuseDepth = 0; reflectionDepth = 0; refractionDepth = 0; } else { diffuseDepth = previous.diffuseDepth; reflectionDepth = previous.reflectionDepth; refractionDepth = previous.refractionDepth; server = previous.server; map = previous.map; rx = previous.rx; ry = previous.ry; this.i += previous.i; this.d += previous.d; } behind = false; cosND = float.NaN; includeLights = includeSpecular = true; qmcD0I = QMC.halton(this.d, this.i); qmcD1I = QMC.halton(this.d + 1, this.i); result = null; bias = 0.001f; }
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; }
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); } } }
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); } }
private IShader getShader(ShadingState state) { return(shaderOverride != null ? shaderOverride : state.getShader()); }
private IShader getPhotonShader(ShadingState state) { return((shaderOverride != null && shaderOverridePhotons) ? shaderOverride : state.getShader()); }
public void prepareShadingState(ShadingState state) { primitives.prepareShadingState(state); }
public void prepareShadingState(ShadingState state) { state.getInstance().prepareShadingState(state); }