public Color getIrradiance(ShadingState state, Color diffuseReflectance) { if (samples <= 0) return Color.BLACK; // compute new sample Color irr = Color.black(); OrthoNormalBasis onb = state.getBasis(); Vector3 w = new Vector3(); int n = state.getDiffuseDepth() == 0 ? samples : 1; for (int i = 0; i < n; i++) { float xi = (float)state.getRandom(i, 0, n); float xj = (float)state.getRandom(i, 1, n); float phi = (float)(xi * 2 * Math.PI); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(xj); float cosTheta = (float)Math.Sqrt(1.0f - xj); w.x = cosPhi * sinTheta; w.y = sinPhi * sinTheta; w.z = cosTheta; onb.transform(w); ShadingState temp = state.traceFinalGather(new Ray(state.getPoint(), w), i); if (temp != null) { temp.getInstance().prepareShadingState(temp); if (temp.getShader() != null) irr.add(temp.getShader().getRadiance(temp)); } } irr.mul((float)Math.PI / n); return irr; }
public Color getIrradiance(ShadingState state, Color diffuseReflectance) { if (samples <= 0) { return(Color.BLACK); } // compute new sample Color irr = Color.black(); OrthoNormalBasis onb = state.getBasis(); Vector3 w = new Vector3(); int n = state.getDiffuseDepth() == 0 ? samples : 1; for (int i = 0; i < n; i++) { float xi = (float)state.getRandom(i, 0, n); float xj = (float)state.getRandom(i, 1, n); float phi = (float)(xi * 2 * Math.PI); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(xj); float cosTheta = (float)Math.Sqrt(1.0f - xj); w.x = cosPhi * sinTheta; w.y = sinPhi * sinTheta; w.z = cosTheta; onb.transform(w); ShadingState temp = state.traceFinalGather(new Ray(state.getPoint(), w), i); if (temp != null) { temp.getInstance().prepareShadingState(temp); if (temp.getShader() != null) { irr.add(temp.getShader().getRadiance(temp)); } } } irr.mul((float)Math.PI / n); return(irr); }
public Color getIrradiance(ShadingState state, Color diffuseReflectance) { float b = (float)Math.PI * c / diffuseReflectance.getMax(); Color irr = Color.black(); Point3 p = state.getPoint(); Vector3 n = state.getNormal(); int set = (int)(state.getRandom(0, 1, 1) * numSets); foreach (PointLight vpl in virtualLights[set]) { Ray r = new Ray(p, vpl.p); float dotNlD = -(r.dx * vpl.n.x + r.dy * vpl.n.y + r.dz * vpl.n.z); float dotND = r.dx * n.x + r.dy * n.y + r.dz * n.z; if (dotNlD > 0 && dotND > 0) { float r2 = r.getMax() * r.getMax(); Color opacity = state.traceShadow(r); Color power = Color.blend(vpl.power, Color.BLACK, opacity); float g = (dotND * dotNlD) / r2; irr.madd(0.25f * Math.Min(g, b), power); } } // bias compensation int nb = (state.getDiffuseDepth() == 0 || numBias <= 0) ? numBias : 1; if (nb <= 0) { return(irr); } OrthoNormalBasis onb = state.getBasis(); Vector3 w = new Vector3(); float scale = (float)Math.PI / nb; for (int i = 0; i < nb; i++) { float xi = (float)state.getRandom(i, 0, nb); float xj = (float)state.getRandom(i, 1, nb); float phi = (float)(xi * 2 * Math.PI); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(xj); float cosTheta = (float)Math.Sqrt(1.0f - xj); w.x = cosPhi * sinTheta; w.y = sinPhi * sinTheta; w.z = cosTheta; onb.transform(w); Ray r = new Ray(state.getPoint(), w); r.setMax((float)Math.Sqrt(cosTheta / b)); ShadingState temp = state.traceFinalGather(r, i); if (temp != null) { temp.getInstance().prepareShadingState(temp); if (temp.getShader() != null) { float dist = temp.getRay().getMax(); float r2 = dist * dist; float cosThetaY = -Vector3.dot(w, temp.getNormal()); if (cosThetaY > 0) { float g = (cosTheta * cosThetaY) / r2; // was this path accounted for yet? if (g > b) { irr.madd(scale * (g - b) / g, temp.getShader().GetRadiance(temp)); } } } } } return(irr); }
public Color getIrradiance(ShadingState state, Color diffuseReflectance) { if (samples <= 0) return Color.BLACK; if (state.getDiffuseDepth() > 0) { // do simple path tracing for additional bounces (single ray) float xi = (float)state.getRandom(0, 0, 1); float xj = (float)state.getRandom(0, 1, 1); float phi = (float)(xi * 2 * Math.PI); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(xj); float cosTheta = (float)Math.Sqrt(1.0f - xj); Vector3 w = new Vector3(); w.x = cosPhi * sinTheta; w.y = sinPhi * sinTheta; w.z = cosTheta; OrthoNormalBasis onb = state.getBasis(); onb.transform(w); Ray r = new Ray(state.getPoint(), w); ShadingState temp = state.traceFinalGather(r, 0); return temp != null ? getGlobalRadiance(temp).copy().mul((float)Math.PI) : Color.BLACK; } //rwl.readLock().lockwoot();//fixme Color irr; lock(lockObj) irr = getIrradiance(state.getPoint(), state.getNormal()); //rwl.readLock().unlock(); if (irr == null) { // compute new sample irr = Color.black(); OrthoNormalBasis onb = state.getBasis(); float invR = 0; float minR = float.PositiveInfinity; Vector3 w = new Vector3(); for (int i = 0; i < samples; i++) { float xi = (float)state.getRandom(i, 0, samples); float xj = (float)state.getRandom(i, 1, samples); float phi = (float)(xi * 2 * Math.PI); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(xj); float cosTheta = (float)Math.Sqrt(1.0f - xj); w.x = cosPhi * sinTheta; w.y = sinPhi * sinTheta; w.z = cosTheta; onb.transform(w); Ray r = new Ray(state.getPoint(), w); ShadingState temp = state.traceFinalGather(r, i); if (temp != null) { minR = Math.Min(r.getMax(), minR); invR += 1.0f / r.getMax(); temp.getInstance().prepareShadingState(temp); irr.add(getGlobalRadiance(temp)); } } irr.mul((float)Math.PI / samples); invR = samples / invR; //rwl.writeLock().lockwoot();//fixme lock(lockObj) insert(state.getPoint(), state.getNormal(), invR, irr); //rwl.writeLock().unlock(); // view irr-cache points // irr = Color.YELLOW.copy().mul(1e6f); } return irr; }
public Color getIrradiance(ShadingState state, Color diffuseReflectance) { if (samples <= 0) { return(Color.BLACK); } if (state.getDiffuseDepth() > 0) { // do simple path tracing for additional bounces (single ray) float xi = (float)state.getRandom(0, 0, 1); float xj = (float)state.getRandom(0, 1, 1); float phi = (float)(xi * 2 * Math.PI); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(xj); float cosTheta = (float)Math.Sqrt(1.0f - xj); Vector3 w = new Vector3(); w.x = cosPhi * sinTheta; w.y = sinPhi * sinTheta; w.z = cosTheta; OrthoNormalBasis onb = state.getBasis(); onb.transform(w); Ray r = new Ray(state.getPoint(), w); ShadingState temp = state.traceFinalGather(r, 0); return(temp != null?getGlobalRadiance(temp).copy().mul((float)Math.PI) : Color.BLACK); } //rwl.readLock().lockwoot();//fixme Color irr; lock (lockObj) irr = getIrradiance(state.getPoint(), state.getNormal()); //rwl.readLock().unlock(); if (irr == null) { // compute new sample irr = Color.black(); OrthoNormalBasis onb = state.getBasis(); float invR = 0; float minR = float.PositiveInfinity; Vector3 w = new Vector3(); for (int i = 0; i < samples; i++) { float xi = (float)state.getRandom(i, 0, samples); float xj = (float)state.getRandom(i, 1, samples); float phi = (float)(xi * 2 * Math.PI); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(xj); float cosTheta = (float)Math.Sqrt(1.0f - xj); w.x = cosPhi * sinTheta; w.y = sinPhi * sinTheta; w.z = cosTheta; onb.transform(w); Ray r = new Ray(state.getPoint(), w); ShadingState temp = state.traceFinalGather(r, i); if (temp != null) { minR = Math.Min(r.getMax(), minR); invR += 1.0f / r.getMax(); temp.getInstance().prepareShadingState(temp); irr.add(getGlobalRadiance(temp)); } } irr.mul((float)Math.PI / samples); invR = samples / invR; //rwl.writeLock().lockwoot();//fixme lock (lockObj) insert(state.getPoint(), state.getNormal(), invR, irr); //rwl.writeLock().unlock(); // view irr-cache points // irr = Color.YELLOW.copy().mul(1e6f); } return(irr); }
public Color getIrradiance(ShadingState state, Color diffuseReflectance) { float b = (float)Math.PI * c / diffuseReflectance.getMax(); Color irr = Color.black(); Point3 p = state.getPoint(); Vector3 n = state.getNormal(); int set = (int)(state.getRandom(0, 1, 1) * numSets); foreach (PointLight vpl in virtualLights[set]) { Ray r = new Ray(p, vpl.p); float dotNlD = -(r.dx * vpl.n.x + r.dy * vpl.n.y + r.dz * vpl.n.z); float dotND = r.dx * n.x + r.dy * n.y + r.dz * n.z; if (dotNlD > 0 && dotND > 0) { float r2 = r.getMax() * r.getMax(); Color opacity = state.traceShadow(r); Color power = Color.blend(vpl.power, Color.BLACK, opacity); float g = (dotND * dotNlD) / r2; irr.madd(0.25f * Math.Min(g, b), power); } } // bias compensation int nb = (state.getDiffuseDepth() == 0 || numBias <= 0) ? numBias : 1; if (nb <= 0) return irr; OrthoNormalBasis onb = state.getBasis(); Vector3 w = new Vector3(); float scale = (float)Math.PI / nb; for (int i = 0; i < nb; i++) { float xi = (float)state.getRandom(i, 0, nb); float xj = (float)state.getRandom(i, 1, nb); float phi = (float)(xi * 2 * Math.PI); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(xj); float cosTheta = (float)Math.Sqrt(1.0f - xj); w.x = cosPhi * sinTheta; w.y = sinPhi * sinTheta; w.z = cosTheta; onb.transform(w); Ray r = new Ray(state.getPoint(), w); r.setMax((float)Math.Sqrt(cosTheta / b)); ShadingState temp = state.traceFinalGather(r, i); if (temp != null) { temp.getInstance().prepareShadingState(temp); if (temp.getShader() != null) { float dist = temp.getRay().getMax(); float r2 = dist * dist; float cosThetaY = -Vector3.dot(w, temp.getNormal()); if (cosThetaY > 0) { float g = (cosTheta * cosThetaY) / r2; // was this path accounted for yet? if (g > b) irr.madd(scale * (g - b) / g, temp.getShader().getRadiance(temp)); } } } } return irr; }