public static OrthoNormalBasis makeFromWV(Vector3D w, Vector3D v) { OrthoNormalBasis onb = new OrthoNormalBasis(); onb.w.set(w); onb.w.normalize(); //w.normalize(onb.w); onb.u = v.cross(onb.w); onb.u.normalize(); //Vector3.cross(v, onb.w, onb.u).normalize(); onb.v = onb.w.cross(onb.v); //Vector3.cross(onb.w, onb.u, onb.v); return(onb); }
internal RGBColor getIrradiance(Sample x) { RGBColor temp = new RGBColor(irr); temp.addLerp((float)(x.pi.x() - pi.x()), transGradient[0]); temp.addLerp((float)(x.pi.y() - pi.y()), transGradient[1]); temp.addLerp((float)(x.pi.z() - pi.z()), transGradient[2]); Vector3D cross = ni.cross(x.ni); temp.addLerp((float)cross.x(), rotGradient[0]); temp.addLerp((float)cross.y(), rotGradient[1]); temp.addLerp((float)cross.z(), rotGradient[2]); return(temp); }
public virtual Vector3D perturbNormal(Vector3D normal, Vector3D localPoint, Primitive primitive) { RGBColor color; Vector3D newNormal; Vector3D gradientU; Vector3D gradientV; Vector3D r, s, t; Vector3D temp; double height, heightDiff; double dx, dy; double x, y; double rDamping, tDamping; double rDampingAbs, tDampingAbs; double rDampingTotal, tDampingTotal; double rTotal, tTotal; s = normal; r = s.cross(new Vector3D(0, 1, 0)); if (r.norm() < RaytracerPhotonmapping.SceneConstants.EPSILON) { r = new Vector3D(0, 1, 0); if (System.Math.Abs(s.y() - 1) < RaytracerPhotonmapping.SceneConstants.EPSILON) { s = new Vector3D(0, 1, 0); } else { s = new Vector3D(0, -1, 0); } } r.normalize(); t = r.cross(s); t.normalize(); gradientU = r.scaleNew(gradDisp().x()); gradientV = t.scaleNew(gradDisp().y()); color = source().diffuseColor(primitive.mapTextureCoordinate(localPoint)); height = color.average(); dx = (samples().x() > 1.0)?(2.0 / (samples().x() - 1.0)):0; dy = (samples().y() > 1.0)?(2.0 / (samples().y() - 1.0)):0; rTotal = 0; tTotal = 0; rDampingTotal = 0; tDampingTotal = 0; y = -1.0; for (int iy = 0; iy < (int)samples().y(); iy++) { tDampingAbs = (1.0 - (y * y) * 0.8); if (tDampingAbs > (1.0 - RaytracerPhotonmapping.SceneConstants.EPSILON)) { tDampingAbs = 0; } tDamping = (y > 0)?tDampingAbs:-tDampingAbs; x = -1.0; for (int ix = 0; ix < (int)samples().x(); ix++) { temp = gradientU.scaleNew(x); temp.add(gradientV.scaleNew(y)); temp.add(localPoint); color = source().diffuseColor(primitive.mapTextureCoordinate(temp)); heightDiff = height - color.average(); rDampingAbs = (1.0 - (x * x) * 0.8); if (rDampingAbs > (1.0 - RaytracerPhotonmapping.SceneConstants.EPSILON)) { rDampingAbs = 0; } rDamping = (x > 0)?rDampingAbs:-rDampingAbs; rDampingTotal += rDampingAbs; tDampingTotal += tDampingAbs; rTotal += heightDiff * rDamping; tTotal += heightDiff * tDamping; x += dx; } y += dy; } r.scale(rTotal / rDampingTotal); t.scale(tTotal / tDampingTotal); newNormal = r.addNew(t); newNormal.scale(bumpFactor()); newNormal.add(s); newNormal.normalize(); return(newNormal); }