2
votes

I have a shader code for 3 channels. Basically there I use

texture(inputTexture0, vUV).rgb

I will do some adds and element wise multiplication, such as:

vec3 + vec3

dot(vec3, vec3)

If I don't want to reprogram the shader code for 1 channel, I want to know theoretically how much processing time is wasted, compared to a shader code specially for 1 channel?

1
I don´t know about the "adds and element wise multiplication", but I do know that texture().r and texture().rgb would have exactly the same cost.Dan
And for 3 channels, the output is color = vec4(); I don't need to revise it either right? The shader compiler will automatically output 1 channeluser1914692

1 Answers

2
votes

This is highly hardware dependent. Traditionally, many GPUs would always operate on vectors, even if just a scalar operation (i.e. one component) was needed. It's still possible that clever compiler optimizations could pack several scalar operations into one vector operation. But fundamentally, on this type of architecture, using only one component will not reduce the number of operations.

Partly based on GPUs being used for much more than traditional graphics (compute), architectures that can handle scalar operations more efficiently are becoming increasingly common.

So using operations on vec3 values if you in fact need only one component could be anywhere between the same processing time and 3 times the processing time. Chances are that if you measure on a wide variety of GPUs, you could find results close to both of these extremes.