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(); // 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) { // 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))); } }