Height Field Visibility

calendar_today

22.07.2024

label

Environment

mouse

Houdini 20.5

Description

A custom height field mask showing the eye-level visibility of each voxel. Most visible parts from any location on the terrain are highlighted red, rather hidden areas are marked blue.

1 Code

// PARAMETERS
float lift = chf('lift');
float shorten = chf('shorten');

// SAMPLE POSITIONS
vector pos[] = detail(1, 'pos', 0);

// RAY ORIGINS
vector orig = v@P;
orig.y += f@height;
orig = minpos(1, orig);
orig.y += lift;

// RAYTRACING
int missed = 0;
foreach(vector p; pos){
    vector dir = p - v@P;
    float dist = length(dir);
    dir = normalize(dir) * max(dist - shorten, 0.0);
    int pr = intersect(1, orig, dir, set(0), set(0));
    missed += pr < 0;
}

// OUTPUT
f@mask = missed / float(len(pos));

/*
GRID POINTS FOR DEBUGGING
int pt = addpoint(0, orig);
setpointattrib(0, 'hits', pt, missed, 'set');
*/
download

Downloads