Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect tangets result in inverted normals on 3 out of 6 sides. #1

Open
khalv opened this issue Jun 2, 2018 · 3 comments
Open

Incorrect tangets result in inverted normals on 3 out of 6 sides. #1

khalv opened this issue Jun 2, 2018 · 3 comments
Assignees
Labels

Comments

@khalv
Copy link

khalv commented Jun 2, 2018

So, this is a really lightweight and cool Triplanar solution, but unfortunately, since the o.Normal output is in tangent space, it still relies on tangents and bitangents being generated by Unity and will produce incorrect normals for every face whose normal isn't parallel to the projection plane. Unfortunately, i don't think there is any way of providing custom tangents and bitangents with surface shaders.

@keijiro keijiro self-assigned this Jun 3, 2018
@EricBatlle
Copy link

EricBatlle commented Jan 2, 2019

I don't really get your problem, but it seems like you need to get the coordinates on paralel, not perpendicular, try to change:

            // Triplanar mapping
            float2 tx = IN.localCoord.yz * _MapScale;
            float2 ty = IN.localCoord.zx * _MapScale;
            float2 tz = IN.localCoord.xy * _MapScale;

to

            // Triplanar mapping
            float2 tx = IN.localCoord.zy* _MapScale;
            float2 ty = IN.localCoord.xz* _MapScale;
            float2 tz = IN.localCoord.xy * _MapScale;

@khalv
Copy link
Author

khalv commented Jan 2, 2019

@ls29322 Here is the problem: Surface shaders are designed so that a tangent space normal map is assigned inside the surface function, and transformed into world space using the TBN matrix. The TBN matrix uses the tangents and bitangents generated for a UV map, which don't match our projection. We want the tangents and bitangents to also be triplanar projected, otherwise we get wrong normals. You can see an example of what i mean here:

Image

Swizzling the projection axis the way you're suggesting doesn't solve the problem, you just get bad normals for the other 3 sides instead. The way the problem looks is that "outwards" pointing features become "inwards" pointing on the opposite sides of the projection axes. There are also some other subtle errors.

@joshcamas
Copy link

Yeah, I'm definitely getting an issue that looks like this.

It's noticeable when you use transparent textures:
Screenshot_191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants