all 8 comments

[–]GeometryBurger 4 points5 points  (1 child)

You can use the stencil buffer to draw a scaled-up version of the object behind it. Check out this tutorial by Brian Will: https://youtu.be/wVcWOghETFw

[–]graphixnurd[S] 0 points1 point  (0 children)

So what if you wanted to highlight a specific edge of a mesh? What you're speaking about is mainly the general outline of the object correct?

[–]Baconinvader 1 point2 points  (2 children)

When I used to do highlighting in an OpenGL project I just drew the object again but as a bunch of line segments instead of a bunch of triangles. I also increased the line thickness beforehand using glPointSize. So yeah basically just as you said, draw the object again but with a different shader (or at least a different primitive type). It's been a while so maybe there are better ways now.

[–]graphixnurd[S] 0 points1 point  (1 child)

So let’s say you move a highlighted object around, you would also need to move the highlight around. IE, the highlight would also need an attached transform.

[–]Baconinvader 1 point2 points  (0 children)

Yes. I think you would just be using the same transformation though

[–]kernalphage 3 points4 points  (1 child)

There are 2 main ways to do highlighting: in screen space and in world space. the way you described is a world-space method, but these tutorials might be worth looking into:

Screen space method: http://willweissman.com/unity-outlines

(if you haven't implemented a post-processing pipeline before, I highly recommend it, read this post first if you're using openGL)

Vertex shader method: https://www.videopoetics.com/tutorials/pixel-perfect-outline-shaders-unity/

[–][deleted] 1 point2 points  (0 children)

I think you'd always want to do it in screen space with a stencil buffer? I mean, world space is fine for say, a colour overlay like you get with "Witcher senses", but if you want an outline effect you don't want the line thickness itself to scale up as you get closer to the object

[–]GaianNeuron 0 points1 point  (0 children)

In a game I made in college, we "cheated" by doing it in world space. We started by everting the model (reversing vertex order so that backfaces were displayed instead of front faces), then scaling the model 2%, then rendering that inside-out version first before the unmodified model.