A texture map indicating hidden areas based on visibility distances. Very vaguely inspired by https://houdinigubbins.wordpress.com/2022/09/22/vis/
Rays are casted in all directions with sample_circle_uniform
and the intersect
-function. If a wall curve has been hit then its tangent is checked against the ray direction normalize(cross(dir, -t))
. Whenever the cross products Y component is positive if(m.y > 0.0)
the ray is inside the curve, so we can add its distance to the sum
which gets divided by the number of samples.
int samples = chi('samples');
float range = chf('range');
float sum = 0.0;
for(int i = 0; i < samples; i++){
float u = rand(i, i@ix * i@iz);
vector2 c = sample_circle_edge_uniform(u);
vector dir = set(c.x, 0.0, c.y);
vector pos;
vector uvw;
int prim = intersect(1, v@P, dir * 10.0, pos, uvw);
if(prim < 0) continue;
vector t = primuv(1, 'tangentu', prim, uvw);
vector m = normalize(cross(dir, -t));
if(m.y > 0.0){
float d = distance(pos, v@P);
sum += d;
}
}
f@d = sum / float(samples) / range;