powervr-graphics / Native_SDK

C++ cross-platform 3D graphics SDK. Includes demos & helper code (resource loading etc.) to speed up development of Vulkan, OpenGL ES 2.0 & 3.x applications
https://docs.imgtec.com/sdk-documentation/html/introduction.html
MIT License
702 stars 197 forks source link

Optimising the PostProcessing/FragShader.fsh #63

Closed senthuran-ukr closed 3 years ago

senthuran-ukr commented 3 years ago

I see that in the vulkan postfragment Fragshader, when calculating the oFilter you are doing log2 and exp2 for each fragments/frame. Instead calculate the final exposure value in the CPU and pass it to the push constant(Save GPU cycle). Therefore we only recalculate the "exposure" value when we need to when the user input changes in the application.

OLD VERSION

layout(push_constant) uniform pushConstantsBlock{
    mediump float linearExposure;
    mediump float threshold;
};
......
mediump float exposure = log2(max(linearExposure, 0.0001f));
exposure -= threshold;
exposure = exp2(exposure);
oFilter = luma(exposure * oColor.rgb);;

SIMPLER & OPTIMISED VERSION

layout(push_constant) uniform pushConstantsBlock{
    mediump float exposure;
};
oFilter = luma(exposure * oColor.rgb);;

https://github.com/powervr-graphics/Native_SDK/blob/master/examples/Vulkan/PostProcessing/FragShader.fsh

HOPE IT HELPS. MERRY CHRISTMAS.

lilly-lizard commented 3 years ago

Thanks Senthuran!

This change will be going into the upcoming release.

A tad late, but merry christmas to you too!