Rework BaseMaterial3D deep parallax implementation and add new features#97646
Rework BaseMaterial3D deep parallax implementation and add new features#97646Calinou wants to merge 2 commits into
Conversation
a768137 to
1f6e871
Compare
|
I've pushed an update that makes use of @tetrapod00's suggested fix for Compatibility. However, it causes a shader compilation error: For some reason, preprocessor macros don't work in the shader generated in BaseMaterial3D, even though it doesn't use |
|
MacOS x86_64 (Forward+), looks like its not working: Used build from: Calinou@1f6e871 Same shader compile error from above. |
This is expected for now until we fix BaseMaterial3D to allow using shader preprocessor within its generated code. This should be done in a separate PR. |
Is there an older hash I could build without the shader compilation issue? |
No, but you can remove the uses of the shader preprocessor within the PR's changes if you only intend to use Forward+/Mobile in your project. |
|
I'm sure Trim Edges and Write Depth will meet the needs of many people who desired displacement mapping. I will note that I believe the addition of these features makes godotengine/godot-proposals#2455 even more relevant now. |
It doesn't work well with repeating textures unfortunately, since UV will go outside the |
|
Where uvs go outside the range I have discovered a cutting method described by Steve Steeting (Sinbad of Ogre3D) https://github.com/sinbad/FbxUdimUnpack?tab=readme-ov-file#fbx-udim-unpacker |
|
I noticed that when "Deep Parallax" is enabled both "Flip Tangent" and "Flip Binormal" don't appear to have an effect. Is that intended? |
Not by MSAA, because the edges are created by a shader and not by geometry. However, all other antialiasing methods that are based on post-processing (TAA, FXAA, FSR2, SSAA, SMAA) will work. |
1f6e871 to
56e61ac
Compare
|
Rebased and tested again on Linux + GeForce RTX 5090 (NVIDIA 580.119.02), I get a driver crash when enabling Deep Parallax on a material. |
The deep parallax effect now features built-in interpolation to make low layer counts look better. It also integrates Z correction for a more convincing depth effect at oblique angles. The new features are disabled by default, but allow for greater realism at a performance cost. Each of them can be enabled separately: - Correct Shadow Receive: This allows the material to receive shadows (and even cast self-shadows) according to the deep parallax effect. Self-shadowing is powered by the existing shadow map system, so it works best with sharp shadows such as the ones cast by OmniLight3D and SpotLight3D, especially when placed at grazing angles. This only has a small performance cost, but it can cause self-shadowing artifacts if lights have a shadow bias that's too low or if the material has a heightmap scale that's too high. Enabling Write Depth at the same time can alleviate those self-shadowing artifacts, with the associated performance cost of that feature. - Write Depth: This allows the material to correctly interact with other materials in the scene, regardless of whether the other materials have deep parallax enabled. This has a significant performance cost. - Trim Edges: This allows the material to have its silhouette affected by the deep parallax effect. This works best with certain UV layouts, but it can have artifacts if the UV layout has visible seams. This has a moderate performance cost. Co-authored-by: sphynx-owner <61445300+sphynx-owner@users.noreply.github.com>
88836bd to
9616117
Compare
|
Enabling Deep Parallax with heightmap crashes for me. |












The deep parallax effect now features built-in interpolation to make low layer counts look better. It also integrates Z correction for a more convincing depth effect at oblique angles.
The new features are disabled by default, but allow for greater realism at a performance cost. Each of them can be enabled separately:
Correct Shadow Receive: This allows the material to receive shadows (and even cast self-shadows) according to the deep parallax effect. Self-shadowing is powered by the existing shadow map system, so it works best with sharp shadows such as the ones cast by OmniLight3D and SpotLight3D, especially when placed at grazing angles. This only has a small performance cost, but it can cause self-shadowing artifacts if lights have a shadow bias that's too low or if the material has a heightmap scale that's too high. Enabling Write Depth at the same time can alleviate those self-shadowing artifacts, with the associated performance cost of that feature.
Write Depth: This allows the material to correctly interact with other materials in the scene, regardless of whether the other materials have deep parallax enabled. This has a significant performance cost.
Trim Edges: This allows the material to have its silhouette affected by the deep parallax effect. This works best with certain UV layouts, but it can have artifacts if the UV layout has visible seams. This has a moderate performance cost.
Thanks to @sphynx-owner who made the initial implementation and Tentabrobpy from the Godot VFX Discord for further assistance 🙂
Testing project: https://github.com/Calinou/godot-parallax-test-4.0
Preview
parallax_1.mp4
parallax_2.mp4
Comparison with default settings
8/32 layers (default quality)
64/64 layers (maximum quality)
Visual impact of each feature being toggled
Benchmark
PC specifications
Measured using the test scene shown in the Before/After comparison before. Materials cover most (but not all) of the view. Using a 3840×2160 viewport.
TODO
discardwithinif (false). Since Write Depth does not actually require usingdiscard, doing so would probably improve performance a bit. For reference, the Mobile rendering method (which lacks a depth prepass) works fine without thisdiscardstatement (although removing it reintroduces the occasional self-shadowing artifacts that occur when Correct Shadow Receive is enabled).Footnotes
Correct Shadow Receive ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8
Write Depth ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8
Trim Edges ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8