Robinseibold / Unity-URP-Outlines

A custom renderer feature for screen space outlines
MIT License
590 stars 51 forks source link

Clamping UVs in order to mitigate wraparound effect #40

Closed snajder-r closed 3 months ago

snajder-r commented 3 months ago

Clamping UVs in order to mitigate wraparound effect, where Outlines at the top of the screen also show up at the bottom and vice versa as well as for left and right.

Tested in

Before this PR:

The outline (white in my example) around the cube touches the screen on the right and left side. Because the UVs have the outline width added and subtracted, some UVs will have negative values in the bottom and left, and some will have values above 1 at the top and right. This results in a wraparound when sampling the Normal Texture, and in the end results in Outlines showing up at the opposing screen border:

Before this commit, the Normal sampled for +1/+1 UVs looked like this. Note the blue line at the top right. image

And the Outline like this:

image

Changes in this PR:

The following nodes have been added to the Outlines Shadergraph:

image

After this PR:

After clamping the UVs to [OutlineScale, 1-OutlineScale] this wraparound is fixed. Normals:

image

And the Outline after the patch:

image

Unintentional side-effect:

The Outline is no longer drawn along the screen border. Note the bottom-right corner on the before and after images. But I personally think that's better anyways.

snajder-r commented 3 months ago

Closing it, as I found a better solution. PR #41 replaces this PR.