I’ve a shader that pulls 2D quads from a texture atlas utilizing instancing. I would like so as to add a characteristic that permits me to map every of the RGBA channels within the texture utilizing a 5×5 matrix. For instance, the next would swap the crimson and inexperienced channels:
Zero 1 Zero Zero 0 1 Zero Zero Zero 0 Zero Zero 1 Zero 0 Zero Zero Zero 1 0 Zero Zero Zero Zero 1
I solely want just a few of those transformations, so my plan is to offer them to the GPU as uniform after which index into this by passing an attribute to my shader for every quad. I believe there are two approaches I may take:
1) Lookup the 5×5 matrix as soon as within the vertex shader and go it to the fragment shader as a various
2) Go the index to the fragment shader as a various and lookup the matrix within the fragment shader
I am unsure which of those approaches could be extra performant. My inclination is 1), as a result of then the lookup solely has to occur as soon as per occasion, however does that imply there’s extra overhead in passing 25 floating level numbers by way of the various?
I may try to benchmark this, however typically, have you learnt of article that compares these alternate options in additional element? By the best way, my graphics pipeline is WebGL if that makes a distinction.