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

NME: fix wrong perturbed normals when using pre-existing tangents #13186

Merged
merged 4 commits into from
Oct 31, 2022
Merged

NME: fix wrong perturbed normals when using pre-existing tangents #13186

merged 4 commits into from
Oct 31, 2022

Conversation

Popov72
Copy link
Contributor

@Popov72 Popov72 commented Oct 28, 2022

Fix #13182

Note that regarding tangents in the bump context we don't take into account the w component of the vector.

In the regular bump code, we use this component as a factor to negate the bitangent (the w component is normally either 1 or -1):

From bumpVertex.fx:

#if defined(BUMP) || defined(PARALLAX) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC)
	#if defined(TANGENT) && defined(NORMAL)
		vec3 tbnNormal = normalize(normalUpdated);
		vec3 tbnTangent = normalize(tangentUpdated.xyz);
		vec3 tbnBitangent = cross(tbnNormal, tbnTangent) * tangentUpdated.w;
		vTBN = mat3(finalWorld) * mat3(tbnTangent, tbnBitangent, tbnNormal);
	#endif
#endif

We don't do it in the NME: should we? If yes, we need to discuss it, I don't see a way to do it without a breaking change...

@azure-pipelines
Copy link

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@Popov72 Popov72 added bug nme Node Material Editor labels Oct 28, 2022
@azure-pipelines
Copy link

@sebavan
Copy link
Member

sebavan commented Oct 30, 2022

Should this not also apply to anisotropy and clear coat block ???

@sebavan
Copy link
Member

sebavan commented Oct 31, 2022

Cool thanks a lot, I am not sure to understand the impact of the breaking change you are mentioning ?

Isnt it more like a bug fix as the materials won t be broken, just lit properly ?

@Popov72
Copy link
Contributor Author

Popov72 commented Oct 31, 2022

It's not a bug fix if tangent.w=+1 for all vertices, so for a number of people what we currently do is ok: I don't know if tangent.w=-1 is used a lot or not in models...

The breaking change I'm speaking about is in the implementation on our side: the existing node materials using perturbed normals + pre-existing tangents would break if we implement the change. The users will have to fix their node materials to account for the change. At least it's what I think would happen but I didn't think about it too thoroughly, so maybe we should discuss about that issue.

In any case, I think it's a different issue and we can merge this PR if it is ok.

@sebavan
Copy link
Member

sebavan commented Oct 31, 2022

Makes sense !!! Let s chat on wednesday

@sebavan sebavan enabled auto-merge October 31, 2022 21:53
@sebavan sebavan merged commit 5de3604 into BabylonJS:master Oct 31, 2022
RaananW pushed a commit that referenced this pull request Dec 9, 2022
NME: fix wrong perturbed normals when using pre-existing tangents
Former-commit-id: 6237dadc8ddb225b63ebfcd16805af2c79b2ef40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug nme Node Material Editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NME: wrong perturbed normal when using pre-existing tangents
2 participants