public Color GetRadiance(ShadingState state) { // make sure we are on the right side of the material state.faceforward(); // direct lighting state.initLightSamples(); state.initCausticSamples(); Color d = getDiffuse(state); Color lr = state.diffuse(d); if (!state.includeSpecular) return lr; if (glossyness == 0) { float cos = state.getCosND(); float dn = 2 * cos; Vector3 refDir = new Vector3(); refDir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x; refDir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y; refDir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z; Ray refRay = new Ray(state.getPoint(), refDir); // compute Fresnel term cos = 1 - cos; float cos2 = cos * cos; float cos5 = cos2 * cos2 * cos; Color spec = getSpecular(state); Color ret = Color.white(); ret.sub(spec); ret.mul(cos5); ret.add(spec); return lr.add(ret.mul(state.traceReflection(refRay, 0))); } else return lr.add(state.specularPhong(getSpecular(state), 2 / glossyness, numSamples)); }
public Color GetRadiance(ShadingState state) { // don't use these - gather lights for sphere of directions // gather lights state.initLightSamples(); state.initCausticSamples(); Vector3 v = state.getRay().getDirection(); v.negate(); Vector3 h = new Vector3(); Vector3 t = state.getBasis().transform(new Vector3(0, 1, 0)); Color diff = Color.black(); Color spec = Color.black(); foreach (LightSample ls in state) { Vector3 l = ls.getShadowRay().getDirection(); float dotTL = Vector3.dot(t, l); float sinTL = (float)Math.Sqrt(1 - dotTL * dotTL); // float dotVL = Vector3.dot(v, l); diff.madd(sinTL, ls.getDiffuseRadiance()); Vector3.add(v, l, h); h.normalize(); float dotTH = Vector3.dot(t, h); float sinTH = (float)Math.Sqrt(1 - dotTH * dotTH); float s = (float)Math.Pow(sinTH, 10.0f); spec.madd(s, ls.getSpecularRadiance()); } Color c = Color.add(diff, spec, new Color()); // transparency return(Color.blend(c, state.traceTransparency(), state.getV(), new Color())); }
public Color getRadiance(ShadingState state) { // don't use these - gather lights for sphere of directions // gather lights state.initLightSamples(); state.initCausticSamples(); Vector3 v = state.getRay().getDirection(); v.negate(); Vector3 h = new Vector3(); Vector3 t = state.getBasis().transform(new Vector3(0, 1, 0)); Color diff = Color.black(); Color spec = Color.black(); foreach (LightSample ls in state) { Vector3 l = ls.getShadowRay().getDirection(); float dotTL = Vector3.dot(t, l); float sinTL = (float)Math.Sqrt(1 - dotTL * dotTL); // float dotVL = Vector3.dot(v, l); diff.madd(sinTL, ls.getDiffuseRadiance()); Vector3.add(v, l, h); h.normalize(); float dotTH = Vector3.dot(t, h); float sinTH = (float)Math.Sqrt(1 - dotTH * dotTH); float s = (float)Math.Pow(sinTH, 10.0f); spec.madd(s, ls.getSpecularRadiance()); } Color c = Color.add(diff, spec, new Color()); // transparency return Color.blend(c, state.traceTransparency(), state.getV(), new Color()); }
public Color getRadiance(ShadingState state) { // make sure we are on the right side of the material state.faceforward(); // setup lighting state.initLightSamples(); state.initCausticSamples(); return(state.diffuse(getDiffuse(state))); }
public Color getRadiance(ShadingState state) { // make sure we are on the right side of the material state.faceforward(); // setup lighting state.initLightSamples(); state.initCausticSamples(); return state.diffuse(getDiffuse(state)); }
public Color getRadiance(ShadingState state) { // make sure we are on the right side of the material state.faceforward(); // setup lighting state.initLightSamples(); state.initCausticSamples(); // execute shader return(state.diffuse(getDiffuse(state)).add(state.specularPhong(spec, power, numRays))); }
public Color getRadiance(ShadingState state) { // make sure we are on the right side of the material state.faceforward(); // setup lighting state.initLightSamples(); state.initCausticSamples(); // execute shader return state.diffuse(getDiffuse(state)).add(state.specularPhong(spec, power, numRays)); }
public Color GetRadiance(ShadingState state) { if (state.getNormal() == null) { // if this shader has been applied to an infinite instance because of shader overrides // run the default shader, otherwise, just shade black return(state.getShader() != this ? state.getShader().GetRadiance(state) : Color.BLACK); } // make sure we are on the right side of the material state.faceforward(); // setup lighting state.initLightSamples(); state.initCausticSamples(); return(state.diffuse(Color.GRAY)); }
public Color GetRadiance(ShadingState state) { if (state.getNormal() == null) { // if this shader has been applied to an infinite instance because of shader overrides // run the default shader, otherwise, just shade black return state.getShader() != this ? state.getShader().GetRadiance(state) : Color.BLACK; } // make sure we are on the right side of the material state.faceforward(); // setup lighting state.initLightSamples(); state.initCausticSamples(); return state.diffuse(Color.GRAY); }
public Color GetRadiance(ShadingState state) { int side = state.getPrimitiveID(); Color kd = null; switch (side) { case 0: kd = left; break; case 1: kd = right; break; case 3: kd = back; break; case 4: kd = bottom; break; case 5: float lx = state.getPoint().x; float ly = state.getPoint().y; if (lx >= lxmin && lx < lxmax && ly >= lymin && ly < lymax && state.getRay().dz > 0) { return(state.includeLights ? radiance : Color.BLACK); } kd = top; break; default: Debug.Assert(false); break; } // make sure we are on the right side of the material state.faceforward(); // setup lighting state.initLightSamples(); state.initCausticSamples(); return(state.diffuse(kd)); }
public Color GetRadiance(ShadingState state) { // make sure we are on the right side of the material state.faceforward(); // direct lighting state.initLightSamples(); state.initCausticSamples(); Color d = getDiffuse(state); Color lr = state.diffuse(d); if (!state.includeSpecular) { return(lr); } if (glossyness == 0) { float cos = state.getCosND(); float dn = 2 * cos; Vector3 refDir = new Vector3(); refDir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x; refDir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y; refDir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z; Ray refRay = new Ray(state.getPoint(), refDir); // compute Fresnel term cos = 1 - cos; float cos2 = cos * cos; float cos5 = cos2 * cos2 * cos; Color spec = getSpecular(state); Color ret = Color.white(); ret.sub(spec); ret.mul(cos5); ret.add(spec); return(lr.add(ret.mul(state.traceReflection(refRay, 0)))); } else { return(lr.add(state.specularPhong(getSpecular(state), 2 / glossyness, numSamples))); } }
public Color getRadiance(ShadingState state) { // make sure we are on the right side of the material state.faceforward(); OrthoNormalBasis onb = state.getBasis(); // direct lighting and caustics state.initLightSamples(); state.initCausticSamples(); Color lr = Color.black(); // compute specular contribution if (state.includeSpecular) { Vector3 inv = state.getRay().getDirection().negate(new Vector3()); foreach (LightSample sample in state) { float cosNL = sample.dot(state.getNormal()); float fr = brdf(inv, sample.getShadowRay().getDirection(), onb); lr.madd(cosNL * fr, sample.getSpecularRadiance()); } // indirect lighting - specular if (numRays > 0) { int n = state.getDepth() == 0 ? numRays : 1; for (int i = 0; i < n; i++) { // specular indirect lighting double r1 = state.getRandom(i, 0, n); double r2 = state.getRandom(i, 1, n); float alphaRatio = alphaY / alphaX; float phi = 0; if (r1 < 0.25) { double val = 4 * r1; phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val)); } else if (r1 < 0.5) { double val = 1 - 4 * (0.5 - r1); phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val)); phi = (float)Math.PI - phi; } else if (r1 < 0.75) { double val = 4 * (r1 - 0.5); phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val)); phi += (float)Math.PI; } else { double val = 1 - 4 * (1 - r1); phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val)); phi = 2 * (float)Math.PI - phi; } float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float denom = (cosPhi * cosPhi) / (alphaX * alphaX) + (sinPhi * sinPhi) / (alphaY * alphaY); float theta = (float)Math.Atan(Math.Sqrt(-Math.Log(1 - r2) / denom)); float sinTheta = (float)Math.Sin(theta); float cosTheta = (float)Math.Cos(theta); Vector3 h = new Vector3(); h.x = sinTheta * cosPhi; h.y = sinTheta * sinPhi; h.z = cosTheta; onb.transform(h); Vector3 o = new Vector3(); float ih = Vector3.dot(h, inv); o.x = 2 * ih * h.x - inv.x; o.y = 2 * ih * h.y - inv.y; o.z = 2 * ih * h.z - inv.z; float no = onb.untransformZ(o); float ni = onb.untransformZ(inv); float w = ih * cosTheta * cosTheta * cosTheta * (float)Math.Sqrt(Math.Abs(no / ni)); Ray r = new Ray(state.getPoint(), o); lr.madd(w / n, state.traceGlossy(r, i)); } } lr.mul(rhoS); } // add diffuse contribution lr.add(state.diffuse(getDiffuse(state))); return lr; }
public Color GetRadiance(ShadingState state) { int side = state.getPrimitiveID(); Color kd = null; switch (side) { case 0: kd = left; break; case 1: kd = right; break; case 3: kd = back; break; case 4: kd = bottom; break; case 5: float lx = state.getPoint().x; float ly = state.getPoint().y; if (lx >= lxmin && lx < lxmax && ly >= lymin && ly < lymax && state.getRay().dz > 0) return state.includeLights ? radiance : Color.BLACK; kd = top; break; default: Debug.Assert(false); break; } // make sure we are on the right side of the material state.faceforward(); // setup lighting state.initLightSamples(); state.initCausticSamples(); return state.diffuse(kd); }
public Color GetRadiance(ShadingState state) { // make sure we are on the right side of the material state.faceforward(); OrthoNormalBasis onb = state.getBasis(); // direct lighting and caustics state.initLightSamples(); state.initCausticSamples(); Color lr = Color.black(); // compute specular contribution if (state.includeSpecular) { Vector3 inv = state.getRay().getDirection().negate(new Vector3()); foreach (LightSample sample in state) { float cosNL = sample.dot(state.getNormal()); float fr = brdf(inv, sample.getShadowRay().getDirection(), onb); lr.madd(cosNL * fr, sample.getSpecularRadiance()); } // indirect lighting - specular if (numRays > 0) { int n = state.getDepth() == 0 ? numRays : 1; for (int i = 0; i < n; i++) { // specular indirect lighting double r1 = state.getRandom(i, 0, n); double r2 = state.getRandom(i, 1, n); float alphaRatio = alphaY / alphaX; float phi = 0; if (r1 < 0.25) { double val = 4 * r1; phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val)); } else if (r1 < 0.5) { double val = 1 - 4 * (0.5 - r1); phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val)); phi = (float)Math.PI - phi; } else if (r1 < 0.75) { double val = 4 * (r1 - 0.5); phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val)); phi += (float)Math.PI; } else { double val = 1 - 4 * (1 - r1); phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val)); phi = 2 * (float)Math.PI - phi; } float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float denom = (cosPhi * cosPhi) / (alphaX * alphaX) + (sinPhi * sinPhi) / (alphaY * alphaY); float theta = (float)Math.Atan(Math.Sqrt(-Math.Log(1 - r2) / denom)); float sinTheta = (float)Math.Sin(theta); float cosTheta = (float)Math.Cos(theta); Vector3 h = new Vector3(); h.x = sinTheta * cosPhi; h.y = sinTheta * sinPhi; h.z = cosTheta; onb.transform(h); Vector3 o = new Vector3(); float ih = Vector3.dot(h, inv); o.x = 2 * ih * h.x - inv.x; o.y = 2 * ih * h.y - inv.y; o.z = 2 * ih * h.z - inv.z; float no = onb.untransformZ(o); float ni = onb.untransformZ(inv); float w = ih * cosTheta * cosTheta * cosTheta * (float)Math.Sqrt(Math.Abs(no / ni)); Ray r = new Ray(state.getPoint(), o); lr.madd(w / n, state.traceGlossy(r, i)); } } lr.mul(rhoS); } // add diffuse contribution lr.add(state.diffuse(getDiffuse(state))); return(lr); }