Wireframe shader in Mantra

calendar_today

29.03.2022

label

Rendering

mouse

Houdini 17.0

Description

This custom wireframe shader consists of two parts: A primitive wrangle in SOPs and a VEX snippet inside a Mantra shader. The wrangle creates an array of all point coordinates of each primitive and the shader snippet iterates over the array, measuring the closest distance from the surface position towards the closest line between a pair of point positions.

1 Gather point positions

For a wireframe shader with consistent line widths, first create a primitive attribute that contains all point positions on each primitive.

C
        // primitive attribute with point positions
int pts_prim[] = primpoints(0, @primnum);

v[]@pos = {};
foreach(int pt; pts_prim){
    vector p = point(0, 'P', pt);
    append(@pos, p);
}
    

2 Distance to line

Then inside a shader choose point pairs for ptlined() to determine the shortest distance to your shading position to check against a custom wire width.

C
        // shader snippet feeding point positions into ptlined()
// determining shortest distance to check against wire width.
int num = len(pos);

float dist = 1e6;
for(int i = 0; i < num; i++){
    vector pos_0 = pos[i];
    vector pos_1 = pos[(i + 1) % num];
    float dist_curr = ptlined(pos_0, pos_1, P);
    if(dist_curr < dist){
        dist = dist_curr;
    }
}

stroke = dist <= stroke;
    
download

Downloads

smart_display

Videos

Wireframe Shader – Houdini Tutorial

link

Related articles

favorite

202

label

Rendering

Low poly helicopter on a CRT screen

favorite

242

label

Rendering

One-parameter shader

favorite

249

label

Rendering

Raymarching Meshes

favorite

300

label

Rendering

Render Cartoon Outlines in SOPs

favorite

299

label

Rendering

UV coordinates and displacements in Mantra

favorite

287

label

RenderingEnvironment

Artistic viewport landscape