Terrain shader: Fix incorrect tangent normals sampled using seamless UV method#66
Closed
wheatleymf wants to merge 2 commits intoFacepunch:masterfrom
Closed
Terrain shader: Fix incorrect tangent normals sampled using seamless UV method#66wheatleymf wants to merge 2 commits intoFacepunch:masterfrom
wheatleymf wants to merge 2 commits intoFacepunch:masterfrom
Conversation
Contributor
|
sexy hunk |
Contributor
|
Could update your branch, please 🙏 |
Terrain_SampleSeamlessUV now additionally returns a 2x2 rotation matrix which can be used to transform vectors and other data if necessary. This also adds a function overload `Terrain_SampleSeamlessUV( float2 uv )` for cases when you don't need a rotation matrix. This will avoid breaking any shaders that rely on old implementation of this function
Previous implementation of seamless UV was sampling tangent normal map 'as is', without transforming vectors to be inline with the UV rotation angle - which resulted into NdotL shading errors. This is now corrected and tangent vector accounts for UV rotation.
Contributor
Author
Should be done now |
Contributor
|
This PR has been merged upstream. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Currently, terrain shader samples tangent normal maps using seamless UVs 'as is', which means that normals are not transformed to be inline with the new UV rotation angle. This results in some issues with NdotL shading. Here's a comparison between current, and corrected normals:
Fix
The solution for this is to multiply tangent normal with 2x2 rotation matrix that we can access from
Terrain_SampleSeamless2Din TerrainCommon.hlsl. This is probably very stupid, but I had to add an outputout float2x2 uvAngleso I can access this matrix from other shaders:To avoid breaking any shaders that rely on a previous implementation of this function, I've added an overload that has an old set of arguments:
In
terrain.shader, inside theTerrain_Splat4function, tangent normal is transformed like this:I am not entirely sure if that's a correct way to approach this, and I absolutely don't know if it was a good idea to change seamless UV function like I did, so please let me know if my solution is stupid.