Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 522fd08

Browse files
author
Kevin Gu
committed
fix linear color space
1 parent 5b95fa2 commit 522fd08

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Runtime/Resources/shaders/UIWidgets_canvas.cginc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ struct v2f {
3030
float2 fpos : TEXCOORD1;
3131
};
3232

33+
inline half3 gamma_to_linear_space(half3 sRGB) {
34+
return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h);
35+
}
36+
37+
inline half4 adjust_color(half4 color) {
38+
#ifdef UNITY_COLORSPACE_GAMMA
39+
return color;
40+
#else
41+
color.rgb = gamma_to_linear_space(color.rgb);
42+
return color;
43+
#endif
44+
}
3345

3446
half shader_gradient_layout(half2 pos) {
3547
half4 p4 = half4(pos, 0.0, 1.0);
@@ -50,9 +62,9 @@ half shader_gradient_layout(half2 pos) {
5062
half4 shader_gradient_colorize(half pt) {
5163
if (_tileMode == 0) { // clamp
5264
if (pt <= 0.0) {
53-
return _leftColor;
65+
return adjust_color(_leftColor);
5466
} else if (pt >= 1.0) {
55-
return _rightColor;
67+
return adjust_color(_rightColor);
5668
}
5769

5870
half2 coord = half2(pt, 0.5);
@@ -107,7 +119,7 @@ half4 shader_color (v2f i) {
107119
half4 c;
108120

109121
#if defined(UIWIDGETS_COLOR)
110-
c = _color;
122+
c = adjust_color(_color);
111123
#elif defined(UIWIDGETS_IMAGE)
112124
half2 pt = shader_image_layout(i.fpos);
113125
c = shader_image_colorize(pt);

0 commit comments

Comments
 (0)