-
-
Notifications
You must be signed in to change notification settings - Fork 21.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
Improve performance of shader lighting code in Forward renderers. #99136
Improve performance of shader lighting code in Forward renderers. #99136
Conversation
e480716
to
831f763
Compare
- Skip sampling shadows if attenuation is very small. - Skip computing diffuse and specular light if attenuation and shadow are very small.
831f763
to
0ce4c6d
Compare
Marking as ready for review, benchmarking and testing for regressions is welcome. Differences in projects with only directional lights are unlikely to show any difference whatsoever. |
Finally tested on an older device (Pixel 4 Adreno 640). This PR roughly reduces the frame time from 285 ms to about 260 ms which lines up with the other mobile devices you tested on. |
Thanks! |
#endif | ||
float Dr = D_GGX(ccNdotH, mix(0.001, 0.1, clearcoat_roughness)); | ||
float Gr = 0.25 / (cLdotH * cLdotH); | ||
float Fr = mix(.04, 1.0, cLdotH5); |
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.
Pretty sure this is the source of the errors I'm getting on a fresh compile. Opening certain scenes straight up crashes the editor.
servers\rendering\renderer_rd\shader_rd.cpp:336 - Error compiling Fragment shader, variant #16 ().
servers\rendering\renderer_rd\shader_rd.cpp:337 - Failed parse:
WARNING: 0:60: '' : all default precisions are highp; use precision statements to quiet warning, e.g.:
"precision mediump int; precision highp float;"
ERROR: 0:1086: 'cLdotH5' : undeclared identifier
ERROR: 0:1086: '' : missing #endif
ERROR: 0:1086: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
cLdotH5
is only defined when !defined(SPECULAR_SCHLICK_GGX)
is true
. Should this section be moved into the same conditional block, or should cLdotH5
be defined outside of it?
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.
We should remove the !defined(SPECULAR_SCHLICK_GGX)
check in the clearcoat section. and then in the specular GGX section add a !defined(LIGHT_CLEARCOAT_USED)
and only define cLdotH5
when clearcoat hasn't already defined it
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.
Fixed in #100081
Using the TPS demo from this PR with the Mobile renderer.
Approximate GPU times.
Ryzen 7950 Integrated Graphics
master
: ~32.5 mslight-compute-attenuation-skip
: ~27.0 msMali G-78 (Samsung S21)
master
: ~27.4 mslight-compute-attenuation-skip
: ~24.6 msMali G-715 (Google Pixel 8)
master
: ~19.4 mslight-compute-attenuation-skip
: ~17.3 msBehavior should be identical in theory although verification is welcome. Performance improvements are also expected in Forward+ but will be less significant as there's light clustering involved.
Opening as draft for now as I intend to do more research into improving some of the other features by reorganizing the code further.
Contributed by W4 Games. 🍀