Wireframe shader in Mantra

calendar_today

29.03.2022

label

Shading, Video

mouse

Houdini 17.0

1 Introduction

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 a the shader snippets iterates over the array, measuring the closest distance from the surface position towards the closest line between a pair of point positions.

2 Gather point positions

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

// 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);
}

3 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.

// 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

Houdini Tutorial - Wireframe Shader

comments

comments

Leave a comment

Available formatting commands

Use Markdown commands or their HTML equivalents to add simple formatting to your comment:

Text markup
*italic*, **bold**, ~~strikethrough~~, `code` and <mark>marked text</mark>.
Lists
- Unordered item 1
- Unordered list item 2
1. Ordered list item 1
2. Ordered list item 2
Quotations
> Quoted text
Code blocks
```
// A simple code block
```
```php
// Some PHP code
phpinfo();
```
Links
[Link text](https://example.com)
Full URLs are automatically converted into links.