I was thinking of writing curvature shader. The idea is to check normal direction in nearby points of the intersectiong and comparing them. Here is the code:
float backstep = 0.001f;
float delta = 0.001f;
VR::Vector normal = rc.rayresult.normal;
normal.makeNormalized();
VR::GenericPrimitive *prim = rc.rayresult.primitive;
// These form the surface plane
VR::Vector surfX;
VR::Vector surfY;
//surfX = VR::Vector(-normal.z / normal.x, 0.f, 1.f);
//surfY = (normal ^ surfY);
if (normal.x == 0 && normal.y == 0) {
surfX = VR::Vector(1,0,0);
surfY = VR::Vector(0,1,0);
} else {
surfX = normal ^ VR::Vector(0,0,1);
surfY = normal ^ surfX;
}
surfX.makeNormalized();
surfY.makeNormalized();
VR::Vector pos = rc.rayresult.origPoint + normal * backstep;
VR::RSRay xRay = VR::RSRay(VR::Ray(pos + surfX * delta, -normal));
VR::RSRay yRay = VR::RSRay(VR::Ray(pos + surfY * delta, -normal));
xRay.clearIntersection();
yRay.clearIntersection();
if (!prim->intersect(xRay))
return AColor(1,0,0,1);
VR::Vector xNormal = prim->getNormal(xRay);
if (!prim->intersect(yRay))
return AColor(0,1,0,1);
VR::Vector yNormal = prim->getNormal(yRay);
Unfortunately it never finds any intersections (just returns red color from the first if clause).
So what am I doing wrong here? Intersecting the whole scene would probably be inneficient since I just want to measure the curvature (difference in normals around the intersection point) of the single object.
- Jerry