Real-time object outline in the viewport

   3059   8   1
User Avatar
Member
74 posts
Joined: Jan. 2015
Offline
Many architectural-type videos show the objects with an outline, sort of like a cartoon shader. I'd like to see this outline in real-time, in the viewport. When I select an object, Houdini gives the object a highlight-type, colored outline in the viewport. So it seems like the mechanism for real-time outline already exists. Is this mechanism available to users? Can I have this outlined look on demand, assigned to chosen objects, in the viewport? If not, is this object "highlighting" in the viewport customizable via some config files?
Edited by element33 - Aug. 24, 2022 21:12:12
User Avatar
Member
4528 posts
Joined: Feb. 2012
Offline
Hi,

Do you mean this sort of outline?



If so, you can convert your geo to polylines using Convert Line SOP and then compute vectors for raycasting onto original geometry:

string cam = chs("cam");

vector p = toNDC(cam, @P);
p.z = -1;
p = fromNDC ( cam, p );

v@outlineNormal = -normalize ( @P - p );

v@pworld = @P;
@P = p;

Then delete points based on occlusion from the camera:

vector n = v@outlineNormal;

vector phit = 0;
vector uvhit = 0;
vector p = v@pworld + v@N * 0.001;
int pr = intersect ( 1, p, n, phit, uvhit );

int result = pr != -1;
pr = intersect ( 1, p, -v@outlineNormal, phit, uvhit );
result |= pr != -1;
    
if ( result )
    removepoint ( 0, @ptnum );
        
@P = v@pworld;

I use Boolean Union to get rid of intersecting bits inside the geometry.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
74 posts
Joined: Jan. 2015
Offline
animatrix_
Do you mean this sort of outline?
Thanks. Your post doesn't really show a clear image of an object outline, so it's hard to tell I implemented your code, but so far, all lines are removed i.e. seems like "result" is true for all lines. I'm investigating why. To verify: the result of the first chunk of vex should be a tiny, flat version of the geometry, right in front of the camera, with v@outlineNormals pointing into the camera, away from the actual object? Seems like you're intersection-test both v@outlineNormals and their inversions.

BTW, it would be nice if Houdini had this as a display option, without the need for extra code, seems like many 3D apps now have this.
Edited by element33 - Aug. 25, 2022 09:54:25
User Avatar
Member
4528 posts
Joined: Feb. 2012
Offline
element33
To verify: the result of the first chunk of vex should be a tiny, flat version of the geometry, right in front of the camera, with v@outlineNormals pointing into the camera, away from the actual object? Seems like you're intersection-test both v@outlineNormals and their inversions.

BTW, it would be nice if Houdini had this as a display option, without the need for extra code, seems like many 3D apps now have this.

Yes, but make sure to set the camera path also, otherwise it won't work. In my case I test both directions because I want to keep only the silhouette of the geometry as viewed from the camera.

If you want to keep the front facing outlines, you can remove this line:
result |= pr != -1;

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
74 posts
Joined: Jan. 2015
Offline
Thanks. The issue wasn't the camera path but the lack of normals (I'm importing an .obj). I got something now. The outline is sensitive to the v@N multiplier (0.001 in your case) and the resample dist (as the resample is done on the tiny pancake near camera). I can't do a proper Boolean cleanup, my model is too dense, Houdini locks up. I'll try a workaround. In the case of the triangular building, I don't think I should see the outlines behind it ("through it")?
Edited by element33 - Aug. 25, 2022 10:36:31

Attachments:
outline.png (18.6 KB)

User Avatar
Member
4528 posts
Joined: Feb. 2012
Offline
element33
Thanks. The issue wasn't the camera path but the lack of normals (I'm importing an .obj). I got something now. The outline is sensitive to the v@N multiplier (0.001 in your case) and the resample dist (as the resample is done on the tiny pancake near camera). I can't do a proper Boolean cleanup, my model is too dense, Houdini locks up. I'll try a workaround. In the case of the triangular building, I don't think I should see the outlines behind it ("through it")?

Yes this method is sensitive as you noticed. If you want to completely clean out the backfacing outlines, you can increase the raycast distance:

int pr = intersect ( 1, p, n*1000, phit, uvhit );
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
74 posts
Joined: Jan. 2015
Offline
Thanks, it worked. Interestingly, if I also multiply the inverted outlineNormal, I get the outline of the whole object.
Edited by element33 - Aug. 25, 2022 11:53:29

Attachments:
outline2.png (23.5 KB)

User Avatar
Member
4528 posts
Joined: Feb. 2012
Offline
element33
Thanks, it worked. Interestingly, if I also multiply the inverted outlineNormal, I get the outline of the whole object.

Yes that's the effect I wanted personally so that's why I am raycasting both directions. But you can choose either depending on your needs.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
1745 posts
Joined: May 2006
Offline
Also labs extract silhouette in contour mode:

Attachments:
labs_extract_sihlouette.PNG (47.1 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
  • Quick Links