-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
MeshSurfaceSampler: interpolate normals #26219
Conversation
(I see that PR fails teh screenshot for webgl_instancing_scatter - it still works but now looks kind of different, I guess) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @makc! I think this is a strict improvement on the current behavior. Even if we added sampleBarycentric
, it still makes sense for the sample
method to handle position and normal vectors.
EDIT: We'll want to regenerate the screenshot too.
also it just came to me, but do we need to normalize() targetNormal 🤔 it will most likely be normalized in whatever fragment shader is using it, but in javascript land people might count on unit length. |
Geometric normals and interpolated surface normals can serve different use cases so I'm not sure if I see this as an improvement in some cases because it blocks the ability to reliably retrieve the geometric normals which I've used in the past. I'm fine with this change but please add the ability to sample the face, barycoord, and index so advanced use cases that require more control and granularity can still function. Something like the following, though I'm flexible on API. This is the data I think should be returned: sampleBarycoord( targetBarycoord, targetTriangle ) : faceIndex |
@gkjohnson what do you mean by "targetTriangle" above? Face index + barycentric coordinates are unambiguous without further information, correct?
|
You're right - this was more for convenience but I was thinking a Triangle instance with the vertices filled in. Barycoord and face index should be enough, though.
Yes this is something the user has to be aware of. This is a bit of a separate topic but it should be possible to implement this without deindexing the geometry, right? |
Yes, I think that could be fixed. 👍 |
@gkjohnson you could have what you want with only a minor change, that is by making sampleFace() return "u" and "v" instead of "this" - then you could inline sample() in your app code to gain access to face index value and, together with barycentric coords it returns, work the magic on any other attributes beyond position-normal-color-uv |
Face index is also needed. And I think a barycoord is also a more common and understandable way of reporting a point on a triangles surface. It's not necessarily obvious how u and v are applied. |
that's what I am saying, you could have face index today if instead of
you write
if you think u and v are not enough you could return Vector3 with u, v and 1 - u - v, too. |
I think that's what is meant by |
not quite sure if this conversation is off-topic, or is this something you want me to add to this PR 🤔 I mean, if @gkjohnson has some better implementation in mind but not the time to make his own PR - just paste it here and I will commit it. |
Could you update the screenshot?
I think this could be merged after that is fixed. |
ok done that. btw @gkjohnson I think after this PR you could do |
@makc thanks! |
This is 2nd change I mentioned in #26207 - it is going to sound silly after @gkjohnson said
and yet this is exactly what I am proposing here 😅
The thing is, for the grass you need both the texture and the normal of the terrain to match the color at the base of the blade - then it can seamlessly blend in. Meanwhile MeshSurfaceSampler ignores normal attribute and just calculates flat normal from vertex positions, which causes very visible difference and the blending does not work. I agree with @donmccurdy when he says
but so far as the method is not there, this PR reflects what I had to do in order to make it work (I did not bother to keep _face.getNormal call in case there is no normal attribute originally since there is hardly ever such a case, but I left it in this PR in case you will have any backward compatibility concerns).