-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PBR renderer: improved handling of sRGB textures
Also added option to convert shader output to sRGB color space
- Loading branch information
1 parent
caaad88
commit 8e70179
Showing
9 changed files
with
214 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef _SRGB_UTILITIES_FXH_ | ||
#define _SRGB_UTILITIES_FXH_ | ||
|
||
float3 SRGBToLinear(float3 sRGB) | ||
{ | ||
float3 bLess = step(float3(0.04045, 0.04045, 0.04045), sRGB); | ||
return lerp(sRGB / 12.92, | ||
pow(saturate((sRGB + float3(0.055, 0.055, 0.055)) / 1.055), float3(2.4, 2.4, 2.4)), | ||
bLess); | ||
} | ||
|
||
float4 SRGBAToLinear(float4 sRGBA) | ||
{ | ||
return float4(SRGBToLinear(sRGBA.rgb), sRGBA.a); | ||
} | ||
|
||
float3 FastSRGBToLinear(float3 sRGB) | ||
{ | ||
return pow(sRGB, float3(2.2, 2.2, 2.2)); | ||
} | ||
|
||
float4 FastSRGBAToLinear(float4 sRGBA) | ||
{ | ||
return float4(FastSRGBToLinear(sRGBA.rgb), sRGBA.a); | ||
} | ||
|
||
float3 LinearToSRGB(float3 RGB) | ||
{ | ||
float3 bGreater = step(float3(0.0031308, 0.0031308, 0.0031308), RGB); | ||
return lerp(RGB * 12.92, | ||
(pow(RGB, float3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) * 1.055) - float3(0.055, 0.055, 0.055), | ||
bGreater); | ||
} | ||
|
||
float4 LinearToSRGBA(float4 RGBA) | ||
{ | ||
return float4(LinearToSRGB(RGBA.rgb), RGBA.a); | ||
} | ||
|
||
float3 FastLinearToSRGB(float3 RGB) | ||
{ | ||
return pow(RGB, float3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2)); | ||
} | ||
|
||
float4 FastLinearToSRGBA(float4 RGBA) | ||
{ | ||
return float4(FastLinearToSRGB(RGBA.rgb), RGBA.a); | ||
} | ||
|
||
#endif // _SRGB_UTILITIES_FXH_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.