Skip to content
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

Shader optimizations #26

Open
9 of 19 tasks
TokisanGames opened this issue Jan 28, 2023 · 0 comments
Open
9 of 19 tasks

Shader optimizations #26

TokisanGames opened this issue Jan 28, 2023 · 0 comments
Labels
enhancement New feature or request low priority Low Priority
Milestone

Comments

@TokisanGames
Copy link
Owner

TokisanGames commented Jan 28, 2023

Performance

  • 1. Precalculate this in C++ whenever terrain_size is changed and pass in the uniform: terrain_size_inv rather than in the shader. WIll save millions of divides per second.
    code += " vec2 ps = vec2(1.0) / terrain_size;\n"; // TODO can be precalculated

e.g.


  • 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.


  • 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

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

Redesign

@TokisanGames TokisanGames added enhancement New feature or request good first issue Good for newcomers labels Jan 28, 2023
@TokisanGames TokisanGames added this to the Polished Version milestone Jan 28, 2023
@TokisanGames TokisanGames added the low priority Low Priority label Feb 3, 2023
@TokisanGames TokisanGames modified the milestones: Polished Version, Stable Jul 19, 2023
@TokisanGames TokisanGames changed the title Minor shader optimizations Shader optimizations Jul 31, 2023
@TokisanGames TokisanGames removed the good first issue Good for newcomers label Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low priority Low Priority
Projects
Development

No branches or pull requests

1 participant