generated from nathanfranke/gdextension
-
-
Notifications
You must be signed in to change notification settings - Fork 233
Open
Labels
Milestone
Description
Performance
- 1. Precalculate this in C++ whenever terrain_size is changed and pass in the uniform:
terrain_size_invrather than in the shader. WIll save millions of divides per second.
Terrain3D/src/terrain_material.cpp
Line 98 in 0bb046e
code += " vec2 ps = vec2(1.0) / terrain_size;\n"; // TODO can be precalculated
- 2. Replace a*b+c with fma(a,b,c), which is allegedly 10% faster. Not supported by webgl (but neither are texture arrays)
https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/shading_language.html
e.g.
-
Maybe also make an FMA macro that uses fma or
*+depending on compatibility or not
- 3.
Lookup region only once per vertex. Move into vertex() and save as a varrying for the colormap in fragment.- Looks bad on lower LODs when using this to calculate pixel data as the vertices are far apart.
- 4. Consider replacing
texturegradwithtexture, if we don't need it for 3D Projection. See Fragment & Texture Normals are wrong #169 update 2 and Fragment & Texture Normals are wrong #169 (comment)
- 5. As above remove all derivative functions and at least get them out of branches. Test optimizing branches
https://community.khronos.org/t/if-statements-in-shaders-confused-by-results/73518/15
- 6. Replace 16x16 Region map with an array. No need for a texture lookup
- 7. Replace 512x512 region blend map w/ a zoomed UV lookup of the region map, or a mathematical version from an array.
- 8.
Since we're blending 4 adjacent vertices, move lookups to vertex() and weight in fragment.- Doesn't look good on lower LODs as the vertices are farther apart, but see redesign below.
- 10. Instead of sampling base/overlay texture lookups for each vertex, bilinear interpolate the UV for the texture lookup and sample albedo/normal once.
- 11. light() is wasteful for mobile according to lfxu. Rewrite it to do only what is needed.
Functional
- 1. May need to do separate transforms in vertex
Firefly artifacts along seams between perfectly aligned meshes godotengine/godot#35067 (comment) - 2. Rotating normal maps properly https://www.youtube.com/watch?v=iXqCszt3LbE
- 3. Single sample triplanar https://www.youtube.com/watch?v=dFApswlwsRc
- 4. Move uv scale to C++
- 5. Add vertex discard shader snippet to material options
- 6. Use antialiasing instead of distance fade
Sometimes I've had the need for antialiasing and have typically faded out (vertex grid, macrovariation) instead of aliasing. Perhaps anti-aliasing is better.
https://stackoverflow.com/questions/20204561/advanced-moir%C3%A9-a-pattern-reduction-in-hlsl-glsl-procedural-textures-shader-a
https://www.yaldex.com/open-gl/ch17lev1sec4.html#ch17fig04
- Triplanar mapping alternative methods.
https://bgolus.medium.com/normal-mapping-for-a-triplanar-shader-10bf39dca05a
Redesign
- Consider looking up height, region, control, color all in vertex. Then with a large mesh, interpolate all in fragment. No lods, or very distant. No fragment lookups. Reducing memory usage (and query) is best optimization.
- Use triangle strips instead of triangles. And render terrain vertices without meshes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Projects
Status
1.x