Is it possible to tell Panda3D to pass a texture to the shader using a signed texture type (i.e. specifically the GL 3.x “SNORM” types such as RGBA8_SNORM)?
For context, I’m implementing blended normal maps in my own shader and it seems really silly/wasteful to have to do “(normal * 2) - 1” multiple times for each pixel instead of just telling the hardware/driver to interpret the passed data as signed values to begin with…
You can use a texture format like Texture.F_rgba16 and set the component type to T_float. With that way you can have signed and unsigned floats.
I’m not sure how you would write to them tho, since PNMImage does not support negative values.
However, your operation * 2 - 1 does cost really nothing, GPUs have special units called Fused Multiply Add,
so the operation a * b + c is only one cycle. Compared to your texel lookup, thats probably a few hundred times faster.
If you are using glsl 4.0 +, you can even tell the gpu to explicitly use those units, for example:
vec3 normal = fma(sampled_normal, vec3(2), vec3(-1));
TLDRL; *2 -1 is almost free, and you are probably overoptimizing.