-
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
Attenuation thickness not applied correctly? #10151
Comments
@emackey thanks for raising this. It's nice to have a point of comparison. @Popov72 It's not related to the current PR.
I'll open a PR for the first two. For the node scale, maybe the Babylon team could come up with a way to set this dynamically so that the shader can scale the attenuation distance based on the node's world scale? I'm pretty swamped with other work at the moment. |
Babylon PR for the first two issues is here: The dragon is scaled to 0.24 so, in Babylon Sandbox, if you scale up the attenuation colour by 4, you get this: |
@MiiBond Awesome, thanks for taking a look at this! Point of clarification on scaling:
|
Just double-checking my math here, since this a new test model.
So the thickest part of the dragon's body is 3.66 times the attenuation distance, making it dark orange. Thinner parts, such as the claws, are closer to 1x the attenuation distance, making them faint yellow. If the node scaling were not accounted for here, yes, the dragon would be considered 4 times thicker and darker than it is. The claws would be orange and the body would be a very deep dark color. So it seems like I could tweak the model to lower both the |
@emackey yes, I wasn't being careful when I wrote that message. Yes, you're correct. The thickness scale is what needs to be set dynamically so that the attenuation can be applied. Right now, the shader assumes that the thickness is already in world units. |
I wonder if this is something that can be adapted at the app level, instead of the shader. One could premultiply the thicknessFactor with the scaling. I haven't yet looked at the sample viewer implementation to see if that's what they're doing. |
That's exactly what I'm doing in Adobe Dimension. |
There are 3 scaling values, one for each x/y/z axis: is glTF specifying how to derive the final scale value to use in the |
We don't yet specify this. In Adobe Dimension, I chose to take the average so as to try to better handle non-uniform scaling but I think taking the maximum is maybe the better choice. I may end up switching Dimension's logic to do that as well. |
glTF does not dictate a specific formula there, as "thickness" is merely an approximation for something that a path tracer would be able to calculate true values for. I could imagine using the max of x, y, z, or using an average. But ultimately, non-uniform scales will never apply correctly to a mesh with a baked thickness map. A strongly nonuniform scale would cause the values of a thickness map to change substantially, if it were to be re-baked at that scale. There's no fixing that with a multiplier. Perhaps we should add a note to the spec that says you shouldn't nonuniformly scale a node with a thickness map. |
There's nothing really stopping an implementation from handling non-uniform scaling correctly based on view direction. So, specifying that the thicknessScale in glTF applies to the max dimension of the un-scaled mesh seems reasonable. It's up to an implementation if they go to the trouble of supporting non-uniform scaling in their rendering. |
On our side, we have merged the PR from @MiiBond + we pre-multiply the |
@Popov72 Sounds great! |
Thanks @Popov72 !!! |
Although
KHR_materials_volume
is still in draft, I've been testing the implementation provided by @MiiBond in #8684.My latest test model is DragonAttenuation. (Sample PR opened as KhronosGroup/glTF-Sample-Models#306).
In the Khronos Sample Viewer, the model looks like this:
But, in Babylon Sandbox, I'm seeing this:
It's hard to see in the screenshot, but the deep orange color is somewhat visible in the thicker parts of the dragon. The thin parts are opaque white/gray, possibly the color of the thickness map itself.
Maybe there's a bug where the thickness map colors are leaking into BaseColor somehow?
This model also features a material variant, with a variant called "Surface Color" where the yellow itself comes from the baseColor and there is no attenuation. This variant appears to work correctly in the sandbox.
The text was updated successfully, but these errors were encountered: