Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do some calculations in GLSL that only happens once per frame?

I would like to precalculate some values to be used each time the fragment shader is called. How/where do I do that? I am using a full screen quad, four vertices.

like image 502
OMH Avatar asked Dec 01 '25 07:12

OMH


1 Answers

Some profiling might be required to see if you will really benefit from precalculating these values instead of doing the calculations in the fragment shader (usually it's a win, but sometimes not).

If you will benefit from this, values calculated once per frame can be passed in as uniforms. You can also calculate these in the vertex shader and pass them along as varyings (which won't really vary), due to the small number of vertices you're talking about here.

like image 179
Brad Larson Avatar answered Dec 03 '25 21:12

Brad Larson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!