opengl - Will the fragment shader automatically clamp the color value to its range? -
opengl - Will the fragment shader automatically clamp the color value to its range? -
will fragment shader automatically clamp color value range?
do need explicitly clam value int shader code? if not, , shader automatically clampping, mean save processing time?
yes, clamped automatically if color buffer in normalized fixed-point format. copied opengl 3.3 spec:
color values written fragment shader may floating-point, signed integer, or unsigned integer. if color buffer has signed or unsigned normalized fixed-point format, color values assumed floating-point , converted fixed-point described in equations 2.6 or 2.4, respectively; otherwise no type conversion applied.
the referenced section "conversion floating-point normalized fixed-point" says (emphasis added):
the conversion floating-point value f corresponding unsigned normalized fixed-point value c defined first clamping f range [0, 1], ...
explicitly clamping in fragment shader waste of operations if frame buffer format of normalized fixed-point type (like typical gl_rgba8
). clamping operations in shader cheap, unnecessary.
the situation different if utilize floating point color buffers. implied spec quote above, no clamping applied in case. expected, because 1 main motivation using floating point color buffers have extended range of values. floating point color buffers created rendering fbo attachment type of gl_rgba16f
, gl_rgba32f
, or similar.
opengl fragment-shader
Comments
Post a Comment