Skip to content

Fixed wrapping issue when Outline is at screen boundary#41

Open
snajder-r wants to merge 1 commit intoRobinseibold:mainfrom
snajder-r:PR_FixTextureWrap
Open

Fixed wrapping issue when Outline is at screen boundary#41
snajder-r wants to merge 1 commit intoRobinseibold:mainfrom
snajder-r:PR_FixTextureWrap

Conversation

@snajder-r
Copy link
Copy Markdown

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

  • Unity 2023.2.191
  • DX11
  • Universal Render Pipeline

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:

Setting wrapMode: TextureWrapMode.Clamp when allocating Normals texture.

After this PR:

After setting the clamping mode for the normals texture (clamping the UVs) 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
Copy link
Copy Markdown
Author

Just noticed that this fixes issue #32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant