-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
WIP cull mode specialization #3734
Conversation
ebbb63a
to
05e5ae3
Compare
Fixed a stray unrelated modification |
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.
Looks good, only uncertain about the bit mask for the specialization flag.
Okay, I've at least documented all the known concerns in the PR body. |
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.
As mentioned, it's basically good. Just cleaning up a few rough edges. :)
Co-authored-by: Robert Swain <robert.swain@gmail.com>
Co-authored-by: Robert Swain <robert.swain@gmail.com>
Co-authored-by: Robert Swain <robert.swain@gmail.com>
Co-authored-by: Robert Swain <robert.swain@gmail.com>
Hmm. It looks like setting
Flips how? Horizontally? Vertically? I don't know what is intended so that probably needs to be improved. :) But anyway, what the code seems to do is swap the vertex positions horizontally, so the bottom-left and bottom-right get swapped, and the top-left and top-right get swapped. However, the indices remain the same. This results in the winding order being reversed. So flipping is not even just making the texture coordinates flip, it is practically rotating the quad 180 degrees about its y-axis. Did you mean the bottom quad is with the same base colour, double-sided set to true, and flip set to true on the quad? As for what the pbr.wgsl shader is doing for double-sided: if ((material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u) {
if (!in.is_front) {
N = -N;
#ifdef VERTEX_TANGENTS
#ifdef STANDARDMATERIAL_NORMAL_MAP
T = -T;
B = -B;
#endif
#endif
}
} So if the material indicates that the mesh is double-sided, with your PR back-face culling is disabled (and front-face culling for that matter) and the winding is used to identify in the fragment shader whether the fragment is for the front or back face of the triangle. Our winding convention is counter-clockwise, due to using a right-handed projection I believe, though I may be wrong. So when you set flip: true on the quad, and it practically reverses the winding of the triangle, it results in the fragments looking at the back face of the triangle. That the means All of that said, I see that the shading is different. The question is why. :) |
Ohhh, but even if the winding is changed, the normal isn't changed. So the normal points in the wrong direction. I think it looks like the intention is that flip: true should only flip the UVs horizontally, not also flip the vertex positions horizontally. I tried to look back through the git history and this flip property goes all the way back to June 2020 in a commit by @cart :
Different times. I think the code should not be this: let north_west = vec2(-extent_x, extent_y);
let north_east = vec2(extent_x, extent_y);
let south_west = vec2(-extent_x, -extent_y);
let south_east = vec2(extent_x, -extent_y);
let vertices = if quad.flip {
[
(
[south_east.x, south_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 1.0],
),
(
[north_east.x, north_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 0.0],
),
(
[north_west.x, north_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0],
),
(
[south_west.x, south_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 1.0],
),
]
} else {
[
(
[south_west.x, south_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 1.0],
),
(
[north_west.x, north_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0],
),
(
[north_east.x, north_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 0.0],
),
(
[south_east.x, south_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 1.0],
),
]
}; but should instead be this: let north_west = vec2(-extent_x, extent_y);
let north_east = vec2(extent_x, extent_y);
let south_west = vec2(-extent_x, -extent_y);
let south_east = vec2(extent_x, -extent_y);
let vertices = if quad.flip {
[
(
[south_west.x, south_west.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 1.0],
),
(
[north_west.x, north_west.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 0.0],
),
(
[north_east.x, north_east.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0],
),
(
[south_east.x, south_east.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 1.0],
),
]
} else {
[
(
[south_west.x, south_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 1.0],
),
(
[north_west.x, north_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0],
),
(
[north_east.x, north_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 0.0],
),
(
[south_east.x, south_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 1.0],
),
]
}; That is, quad.flip only flips the UV coordinates in x. As the vertex positions and normals are identical, it doesn't affect the lighting at all. |
Closing in favor of #3982 |
Objective
Fixes #3729
Solution
Add cull mode specialization
Caveats
I never got around to tidying this up, but I'm pushing it here for the sake of potential collaboration.
MeshPipelineKey
for every possible cull mode? Or is on/off enough?fn double_sided
on various material... things. My "generic rust" skills aren't fantastic. Are all these even necessary?Marking as a draft PR for now.