- Home /
When do shaders compute?
Evening people,
I have a shader, which is applied to many spheres in the scene. Could be 10, could be 100. The shader (not written by me) seems to have a LOT of calculations than a standard shader. Obviously, I want the (android) app to be performant. What I would like to know is if shaders do their calculations when their objects are inside the frustum of a camera or they do them even outside. I would like to determine if bringing close the far clip plane will easily solve my issue or I should implement a logic of each object having a large collider that will activate its object only if camera/player is sort of close.
Thanks in advance!
Answer by Hellium · Nov 16, 2017 at 07:26 PM
Shaders are small scripts that contain the mathematical calculations and algorithms for calculating the colour of each pixel rendered, based on the lighting input and the Material configuration.
They "run" only when your camera(s) need to render it. AFAIK, Unity handles frustum culling, so if your object is outside the frustum, the shader for this object won't be called.
However, your object may be "rendered" even if your camera does not see it. Take the simple example where your object is behind a big wall. If you did not setup occlusion culling, your obejct will be rendered (thus, the shader will be called) followed by the big wall.