summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred
diff options
context:
space:
mode:
authorGraham Linden <graham@lindenlab.com>2013-07-25 09:36:13 -0700
committerGraham Linden <graham@lindenlab.com>2013-07-25 09:36:13 -0700
commitf357269c38a8627aeb67c82c5ee34b49336e0d8b (patch)
tree1bc688e9548a02799d5c90817193f1a851c74edc /indra/newview/app_settings/shaders/class1/deferred
parent24cef8d36b13c02ec06c58cc66d9bce040891069 (diff)
NORSPEC-325 WIP restore gamma (uncorrected) attenuation and unify sRGB conversion in one place
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/alphaF.glsl38
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl6
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl28
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/materialF.glsl45
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl23
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl14
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl38
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl23
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/srgb.glsl49
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl21
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/waterF.glsl21
12 files changed, 86 insertions, 222 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
index e3be7a52ec..075699c591 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
@@ -93,10 +93,13 @@ uniform vec3 light_direction[8];
uniform vec3 light_attenuation[8];
uniform vec3 light_diffuse[8];
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cl);
+
vec3 calcDirectionalLight(vec3 n, vec3 l)
{
float a = max(dot(n,l),0.0);
- //a = pow(a, 1.0/1.3);
+ a = pow(a, 1.0/1.3);
return vec3(a,a,a);
}
@@ -392,37 +395,6 @@ vec3 fullbrightScaleSoftClip(vec3 light)
return light;
}
-vec3 srgb_to_linear(vec3 cs)
-{
-
-/* { cs / 12.92, cs <= 0.04045
- cl = {
- { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
-
- vec3 low_range = cs / vec3(12.92);
-
- if (((cs.r + cs.g + cs.b) / 3) <= 0.04045)
- return low_range;
-
- return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- cl = clamp(cl, vec3(0), vec3(1));
-
- if ((cl.r+cl.g+cl.b) < 0.0031308)
- return 12.92 * cl;
-
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
-
-
void main()
{
vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
@@ -533,7 +505,7 @@ void main()
color.rgb *= ambient;
- color.rgb += atmosAffectDirectionalLight(final_da);
+ color.rgb += atmosAffectDirectionalLight(pow(final_da, 1.0/1.3));
color.rgb *= gamma_diff.rgb;
color.rgb = mix(atmosLighting(color.rgb), fullbrightAtmosTransport(color.rgb), diff.a);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl
index 6fe34b887a..adc361d7a2 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl
@@ -39,15 +39,15 @@ vec2 encode_normal(vec3 n)
return n.xy / f + 0.5;
}
+
void main()
{
- vec4 diff = diffuseLookup(vary_texcoord0.xy);
- vec3 col = vertex_color.rgb * diff.rgb;
+ vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb;
vec3 spec;
spec.rgb = vec3(vertex_color.a);
- frag_data[0] = vec4(col, 0);
+ frag_data[0] = vec4(col, 0.0);
frag_data[1] = vec4(spec, vertex_color.a); // spec
vec3 nvn = normalize(vary_normal);
frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
index da4ebfea58..00548ea826 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
@@ -39,6 +39,9 @@ VARYING vec3 vary_position;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cl);
+
vec3 fullbrightAtmosTransportDeferred(vec3 light)
{
return light;
@@ -100,31 +103,6 @@ vec4 applyWaterFogDeferred(vec3 pos, vec4 color)
}
#endif
-vec3 srgb_to_linear(vec3 cs)
-{
-
-/* { cs / 12.92, cs <= 0.04045
- cl = {
- { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
-
- return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- cl = clamp(cl, vec3(0), vec3(1));
-
- if ((cl.r+cl.g+cl.b) < 0.0031308)
- return 12.92 * cl;
-
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
-
void main()
{
#if HAS_DIFFUSE_LOOKUP
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index b8c5360486..d3bd55da7a 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -30,37 +30,6 @@
uniform float emissive_brightness;
-
-vec3 srgb_to_linear(vec3 cs)
-{
-
-/* { cs / 12.92, cs <= 0.04045
- cl = {
- { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
-
- vec3 low_range = cs / vec3(12.92);
-
- if (((cs.r + cs.g + cs.b) / 3) <= 0.04045)
- return low_range;
-
- return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- cl = clamp(cl, vec3(0), vec3(1));
-
- if ((cl.r+cl.g+cl.b) < 0.0031308)
- return 12.92 * cl;
-
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
-
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
#ifdef DEFINE_GL_FRAGCOLOR
@@ -145,6 +114,9 @@ uniform vec3 light_direction[8];
uniform vec3 light_attenuation[8];
uniform vec3 light_diffuse[8];
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cl);
+
#ifdef WATER_FOG
uniform vec4 waterPlane;
uniform vec4 waterFogColor;
@@ -558,7 +530,7 @@ void main()
dot(norm.xyz,vary_mat1),
dot(norm.xyz,vary_mat2));
#else
- vec4 norm = vec4(0,1,0,1.0);
+ vec4 norm = vec4(0,0,0,1.0);
vec3 tnorm = vary_normal;
#endif
@@ -682,7 +654,7 @@ void main()
col.rgb *= ambient;
- col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); //pow(final_da, 1.0/1.3));
+ col.rgb = col.rgb + atmosAffectDirectionalLight(pow(final_da, 1.0/1.3));
col.rgb *= gamma_diff.rgb;
float glare = 0.0;
@@ -705,7 +677,7 @@ void main()
col += spec_contrib;
}
- col = mix(col.rgb, diffcol.rgb, diffuse.a);
+ col = mix(col.rgb, gamma_diff.rgb, diffuse.a);
if (envIntensity > 0.0)
{
@@ -724,11 +696,11 @@ void main()
}
col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a);
- col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
+ col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
//convert to linear space before adding local lights
col = srgb_to_linear(col);
-
+
vec3 npos = normalize(-pos.xyz);
#define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare);
@@ -747,6 +719,7 @@ void main()
//convert to gamma space for display on screen
col.rgb = linear_to_srgb(col.rgb);
+
#ifdef WATER_FOG
vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al));
col.rgb = temp.rgb;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl
index 3b6724479c..0b62c4ec09 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl
@@ -84,25 +84,8 @@ vec3 decode_normal (vec2 enc)
return n;
}
-vec3 srgb_to_linear(vec3 cs)
-{
-
-/* { cs / 12.92, cs <= 0.04045
- cl = {
- { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
-
- return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cl);
vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
{
@@ -198,7 +181,7 @@ void main()
proj_tc.xyz /= proj_tc.w;
- float fa = falloff;
+ float fa = falloff+1.0;
float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
index 4ca0c35d91..106d48bd71 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
@@ -115,7 +115,7 @@ void main()
float noise = texture2D(noiseMap, frag.xy/128.0).b;
vec3 col = texture2DRect(diffuseRect, frag.xy).rgb;
- float fa = falloff;
+ float fa = falloff+1.0;
float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
index 01f9d99682..89530f4082 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
@@ -38,19 +38,7 @@ VARYING vec2 vary_fragcoord;
uniform float display_gamma;
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- cl = clamp(cl, vec3(0), vec3(1));
-
- if ((cl.r+cl.g+cl.b) < 0.0031308)
- return 12.92 * cl;
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
+vec3 linear_to_srgb(vec3 cl);
void main()
{
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
index 045b449bbf..39d613e02b 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
@@ -78,37 +78,8 @@ vec3 vary_AtmosAttenuation;
uniform mat4 inv_proj;
uniform vec2 screen_res;
-
-vec3 srgb_to_linear(vec3 cs)
-{
-
-/* { cs / 12.92, cs <= 0.04045
- cl = {
- { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
-
- vec3 low_range = cs / vec3(12.92);
-
- if (((cs.r + cs.g + cs.b) / 3) <= 0.04045)
- return low_range;
-
- return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- cl = clamp(cl, vec3(0), vec3(1));
-
- if ((cl.r+cl.g+cl.b) < 0.0031308)
- return 12.92 * cl;
-
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
-
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cl);
vec3 decode_normal (vec2 enc)
{
@@ -143,7 +114,6 @@ vec3 getPositionEye()
{
return vary_PositionEye;
}
-
vec3 getSunlitColor()
{
return vary_SunlitColor;
@@ -388,7 +358,7 @@ void main()
norm.xyz = decode_normal(norm.xy); // unpack norm
float da = max(dot(norm.xyz, sun_dir.xyz), 0.0);
- //da = pow(da, 1.0/1.3);
+ da = pow(da, 1.0/1.3);
vec4 diffuse = texture2DRect(diffuseRect, tc);
@@ -408,7 +378,9 @@ void main()
ambient = (1.0-ambient);
col.rgb *= ambient;
+
col += atmosAffectDirectionalLight(max(min(da, 1.0), 0.0));
+
col *= diffuse.rgb;
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl
index 53732e961c..251abfd119 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl
@@ -82,25 +82,8 @@ vec3 decode_normal (vec2 enc)
return n;
}
-vec3 srgb_to_linear(vec3 cs)
-{
-
-/* { cs / 12.92, cs <= 0.04045
- cl = {
- { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
-
- return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cl);
vec4 correctWithGamma(vec4 col)
{
@@ -201,7 +184,7 @@ void main()
proj_tc.xyz /= proj_tc.w;
- float fa = falloff;
+ float fa = falloff+1.0;
float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0);
dist_atten *= dist_atten;
dist_atten *= 2.0;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl
new file mode 100644
index 0000000000..177f6c25f8
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl
@@ -0,0 +1,49 @@
+/**
+ * @file srgb.glsl
+ *
+ * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+vec3 srgb_to_linear(vec3 cs)
+{
+
+/* { cs / 12.92, cs <= 0.04045
+ cl = {
+ { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
+
+ vec3 low_range = cs / vec3(12.92);
+ vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
+ return mix(high_range, low_range, lessThanEqual(cs,vec3(0.04045)));
+}
+
+vec3 linear_to_srgb(vec3 cl)
+{
+ /* { 0.0, 0 <= cl
+ { 12.92 * c, 0 < cl < 0.0031308
+ cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
+ { 1.0, cl >= 1*/
+
+ cl = clamp(cl, vec3(0), vec3(1));
+ vec3 low_range = cl * 12.92;
+ vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055;
+ return mix(high_range, low_range, lessThan(cl,vec3(0.0031308)));
+}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl
index 938947bbce..858c3a1fe9 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl
@@ -56,25 +56,8 @@ VARYING vec4 refCoord;
VARYING vec4 littleWave;
VARYING vec4 view;
-vec3 srgb_to_linear(vec3 cs)
-{
-
-/* { cs / 12.92, cs <= 0.04045
- cl = {
- { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
-
- return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cl);
vec2 encode_normal(vec3 n)
{
diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
index 34189deaad..5538c41d1c 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
@@ -67,25 +67,8 @@ VARYING vec4 littleWave;
VARYING vec4 view;
VARYING vec4 vary_position;
-vec3 srgb_to_linear(vec3 cs)
-{
-
-/* { cs / 12.92, cs <= 0.04045
- cl = {
- { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/
-
- return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- /*{ 0.0, 0 <= cl
- { 12.92 * c, 0 < cl < 0.0031308
- cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1
- { 1.0, cl >= 1*/
-
- return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
-}
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cl);
vec2 encode_normal(vec3 n)
{