sRGB Texture Workflow
What is sRGB Texture Workflow
The sRGB texture workflow is a key part of color management in real-time rendering. It involves correctly handling color space in the graphics pipeline to ensure accurate final displayed colors. The core principle is: color textures (such as albedo, diffuse) are typically stored in sRGB color space because human perception of brightness is nonlinear, and sRGB encoding utilizes limited bit depth more effectively. However, lighting calculations must be performed in linear space; otherwise results are incorrect. Therefore, after sampling a texture, colors need to be converted from sRGB to linear space, and after rendering, the output is converted back to sRGB for display.
Why sRGB Workflow is Needed
- **Physical correctness**: Lighting equations hold only in linear space. If computed directly in sRGB space, lighting will be too bright or color shifted.
- **Avoid color distortion**: Incorrect color space handling causes texture colors to deviate from design, especially in shadows and highlights.
- **Consistency**: Ensures colors appear consistent across platforms and displays.
Difference between sRGB and Linear Space
- **sRGB**: A nonlinear color space that encodes gamma correction (about 2.2) for storage and display, matching human perception.
- **Linear space**: Lighting calculations and physical simulations should occur in this space; pixel values are proportional to light intensity.
Implementing sRGB Workflow
In graphics APIs and engines, this is typically achieved by:
- **Texture import settings**: Mark color textures as sRGB so the GPU automatically converts them to linear space upon sampling. For example, in Unity, color textures default to "sRGB (Color Texture)" checked, while data textures like normal maps, roughness, etc., use linear.
- **Render target format**: Use framebuffer formats that support sRGB (e.g., sRGB8_ALPHA8); the GPU automatically performs linear-to-sRGB conversion on write.
- **In shaders**: If handled manually, perform `pow(color, 2.2)` after sampling color textures, or use hardware sRGB texture sampling.
- **Final output**: If rendering to a non-sRGB target, manual gamma correction is needed.
- **Do not use sRGB for non-color data**: Normal maps, roughness, metallic, AO, etc., should use linear space; otherwise values are decoded incorrectly.
- **Blending order**: Transparent blending should occur in linear space, then converted to sRGB for output.
- **Mipmap generation**: Mipmaps for sRGB textures should be generated in sRGB space; otherwise average colors appear too dark.
- **UI elements**: UI is usually designed in sRGB space and should avoid being linearized.
- Setting color textures as linear by mistake, causing images to appear darker.
- Setting data textures as sRGB, causing incorrect values.
- Forgetting to convert back to sRGB at final output, causing overbright images.
Considerations
Common Mistakes
Summary
The sRGB texture workflow is fundamental to ensuring rendering quality. Correctly configuring texture and render target color spaces can avoid many visual issues.
FAQ
Why should color textures be marked as sRGB?
Because color textures are stored in sRGB space. Marking them as sRGB allows the GPU to automatically convert them to linear space upon sampling, ensuring correct lighting calculations. If not checked, colors will appear darker.
Do normal maps need to be marked as sRGB?
No. Normal maps store directional data, not colors, and should use linear space. If marked as sRGB, normal directions will be misinterpreted, causing lighting anomalies.
How to set up sRGB texture workflow in Unity?
In Player Settings, set Color Space to Linear. Then in texture import settings, color textures should have sRGB checked by default, while data textures should have it unchecked.
Is linear space rendering better than gamma space?
Yes, linear space rendering provides physically correct lighting, more realistic colors, and avoids overexposure or distortion. Modern engines and mobile devices recommend using linear space.
What is the relationship between sRGB and gamma correction?
sRGB encoding includes gamma correction (about 2.2) to compensate for display nonlinearity. Gamma correction is the process of converting linear values to sRGB values; inverse gamma correction converts them back to linear.