Skip to content

Commit a57d82b

Browse files
author
Rye
committed
Eliminate reduntant copies and full screen passes from post process effect chain
1 parent a895f4e commit a57d82b

16 files changed

+539
-475
lines changed

indra/newview/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,7 @@ set(viewer_APPSETTINGS_FILES
16861686
packages-info.txt
16871687
featuretable.txt
16881688
featuretable_mac.txt
1689+
featuretable_linux.txt
16891690
)
16901691

16911692
source_group("App Settings" FILES ${viewer_APPSETTINGS_FILES})

indra/newview/app_settings/settings.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10080,6 +10080,17 @@
1008010080
<key>Value</key>
1008110081
<string>00000000-0000-0000-0000-000000000000</string>
1008210082
</map>
10083+
<key>RenderCAS</key>
10084+
<map>
10085+
<key>Comment</key>
10086+
<string>Use Contrast Adaptive Sharpening post process effect</string>
10087+
<key>Persist</key>
10088+
<integer>0</integer>
10089+
<key>Type</key>
10090+
<string>Boolean</string>
10091+
<key>Value</key>
10092+
<integer>1</integer>
10093+
</map>
1008310094
<key>RenderCASSharpness</key>
1008410095
<map>
1008510096
<key>Comment</key>

indra/newview/app_settings/shaders/class1/deferred/CASF.glsl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ uniform sampler2D diffuseRect;
3838
uniform vec2 out_screen_res;
3939
uniform uvec4 cas_param_0;
4040
uniform uvec4 cas_param_1;
41+
uniform float gamma;
4142

4243
vec3 srgb_to_linear(vec3 cs);
4344
vec3 linear_to_srgb(vec3 cl);
@@ -2545,11 +2546,69 @@ A_STATIC void CasSetup(
25452546
#endif
25462547

25472548
#ifdef A_GPU
2549+
2550+
//=================================
2551+
// borrowed noise from:
2552+
// <https://www.shadertoy.com/view/4dS3Wd>
2553+
// By Morgan McGuire @morgan3d, http://graphicscodex.com
2554+
//
2555+
float hash(float n) { return fract(sin(n) * 1e4); }
2556+
float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); }
2557+
2558+
float noise(float x) {
2559+
float i = floor(x);
2560+
float f = fract(x);
2561+
float u = f * f * (3.0 - 2.0 * f);
2562+
return mix(hash(i), hash(i + 1.0), u);
2563+
}
2564+
2565+
float noise(vec2 x) {
2566+
vec2 i = floor(x);
2567+
vec2 f = fract(x);
2568+
2569+
// Four corners in 2D of a tile
2570+
float a = hash(i);
2571+
float b = hash(i + vec2(1.0, 0.0));
2572+
float c = hash(i + vec2(0.0, 1.0));
2573+
float d = hash(i + vec2(1.0, 1.0));
2574+
2575+
// Simple 2D lerp using smoothstep envelope between the values.
2576+
// return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)),
2577+
// mix(c, d, smoothstep(0.0, 1.0, f.x)),
2578+
// smoothstep(0.0, 1.0, f.y)));
2579+
2580+
// Same code, with the clamps in smoothstep and common subexpressions
2581+
// optimized away.
2582+
vec2 u = f * f * (3.0 - 2.0 * f);
2583+
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
2584+
}
2585+
2586+
//===============================================================
2587+
2588+
vec3 legacyGamma(vec3 color)
2589+
{
2590+
vec3 c = 1. - clamp(color, vec3(0.), vec3(1.));
2591+
c = 1. - pow(c, vec3(gamma)); // s/b inverted already CPU-side
2592+
2593+
return c;
2594+
}
2595+
25482596
void main()
25492597
{
25502598
vec4 diff = vec4(0.f);
25512599
uvec2 point = uvec2(vary_fragcoord * out_screen_res.xy);
25522600
CasFilter(diff.r, diff.g, diff.b, point, cas_param_0, cas_param_1, true);
2601+
diff.rgb = linear_to_srgb(diff.rgb);
2602+
2603+
#ifdef LEGACY_GAMMA
2604+
diff.rgb = legacyGamma(diff.rgb);
2605+
#endif
2606+
2607+
vec2 tc = vary_fragcoord.xy*out_screen_res.xy*4.0;
2608+
vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y);
2609+
vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb));
2610+
diff.rgb += nz*0.003;
2611+
25532612
diff.a = texture(diffuseRect, vary_fragcoord).a;
25542613
frag_color = diff;
25552614
}

indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl

Lines changed: 0 additions & 58 deletions
This file was deleted.

indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,57 +33,10 @@ uniform sampler2D depthMap;
3333
uniform vec2 screen_res;
3434
in vec2 vary_fragcoord;
3535

36-
//=================================
37-
// borrowed noise from:
38-
// <https://www.shadertoy.com/view/4dS3Wd>
39-
// By Morgan McGuire @morgan3d, http://graphicscodex.com
40-
//
41-
float hash(float n) { return fract(sin(n) * 1e4); }
42-
float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); }
43-
44-
float noise(float x) {
45-
float i = floor(x);
46-
float f = fract(x);
47-
float u = f * f * (3.0 - 2.0 * f);
48-
return mix(hash(i), hash(i + 1.0), u);
49-
}
50-
51-
float noise(vec2 x) {
52-
vec2 i = floor(x);
53-
vec2 f = fract(x);
54-
55-
// Four corners in 2D of a tile
56-
float a = hash(i);
57-
float b = hash(i + vec2(1.0, 0.0));
58-
float c = hash(i + vec2(0.0, 1.0));
59-
float d = hash(i + vec2(1.0, 1.0));
60-
61-
// Simple 2D lerp using smoothstep envelope between the values.
62-
// return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)),
63-
// mix(c, d, smoothstep(0.0, 1.0, f.x)),
64-
// smoothstep(0.0, 1.0, f.y)));
65-
66-
// Same code, with the clamps in smoothstep and common subexpressions
67-
// optimized away.
68-
vec2 u = f * f * (3.0 - 2.0 * f);
69-
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
70-
}
71-
72-
//=============================
73-
74-
75-
7636
void main()
7737
{
7838
vec4 diff = texture(diffuseRect, vary_fragcoord.xy);
7939

80-
#ifdef HAS_NOISE
81-
vec2 tc = vary_fragcoord.xy*screen_res*4.0;
82-
vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y);
83-
vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb));
84-
diff.rgb += nz*0.003;
85-
#endif
86-
8740
frag_color = diff;
8841

8942
gl_FragDepth = texture(depthMap, vary_fragcoord.xy).r;

indra/newview/app_settings/shaders/class1/deferred/postDeferredTonemap.glsl

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ out vec4 frag_color;
3030
uniform sampler2D diffuseRect;
3131
uniform sampler2D exposureMap;
3232

33+
uniform float gamma;
3334
uniform vec2 screen_res;
3435
in vec2 vary_fragcoord;
3536

@@ -149,6 +150,42 @@ vec3 toneMap(vec3 color)
149150
return color;
150151
}
151152

153+
//=================================
154+
// borrowed noise from:
155+
// <https://www.shadertoy.com/view/4dS3Wd>
156+
// By Morgan McGuire @morgan3d, http://graphicscodex.com
157+
//
158+
float hash(float n) { return fract(sin(n) * 1e4); }
159+
float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); }
160+
161+
float noise(float x) {
162+
float i = floor(x);
163+
float f = fract(x);
164+
float u = f * f * (3.0 - 2.0 * f);
165+
return mix(hash(i), hash(i + 1.0), u);
166+
}
167+
168+
float noise(vec2 x) {
169+
vec2 i = floor(x);
170+
vec2 f = fract(x);
171+
172+
// Four corners in 2D of a tile
173+
float a = hash(i);
174+
float b = hash(i + vec2(1.0, 0.0));
175+
float c = hash(i + vec2(0.0, 1.0));
176+
float d = hash(i + vec2(1.0, 1.0));
177+
178+
// Simple 2D lerp using smoothstep envelope between the values.
179+
// return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)),
180+
// mix(c, d, smoothstep(0.0, 1.0, f.x)),
181+
// smoothstep(0.0, 1.0, f.y)));
182+
183+
// Same code, with the clamps in smoothstep and common subexpressions
184+
// optimized away.
185+
vec2 u = f * f * (3.0 - 2.0 * f);
186+
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
187+
}
188+
152189
//===============================================================
153190

154191
void debugExposure(inout vec3 color)
@@ -161,16 +198,40 @@ void debugExposure(inout vec3 color)
161198
}
162199
}
163200

201+
vec3 legacyGamma(vec3 color)
202+
{
203+
vec3 c = 1. - clamp(color, vec3(0.), vec3(1.));
204+
c = 1. - pow(c, vec3(gamma)); // s/b inverted already CPU-side
205+
206+
return c;
207+
}
208+
164209
void main()
165210
{
166211
//this is the one of the rare spots where diffuseRect contains linear color values (not sRGB)
167212
vec4 diff = texture(diffuseRect, vary_fragcoord);
168213

214+
#ifdef TONEMAP
169215
#ifndef NO_POST
170216
diff.rgb = toneMap(diff.rgb);
171-
#else
217+
#endif
218+
#ifndef GAMMA_CORRECT
172219
diff.rgb = clamp(diff.rgb, vec3(0.0), vec3(1.0));
173220
#endif
221+
#endif
222+
223+
#ifdef GAMMA_CORRECT
224+
diff.rgb = linear_to_srgb(diff.rgb);
225+
226+
#ifdef LEGACY_GAMMA
227+
diff.rgb = legacyGamma(diff.rgb);
228+
#endif
229+
230+
vec2 tc = vary_fragcoord.xy*screen_res*4.0;
231+
vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y);
232+
vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb));
233+
diff.rgb += nz*0.003;
234+
#endif
174235

175236
//debugExposure(diff.rgb);
176237
frag_color = max(diff, vec4(0));

indra/newview/featuretable.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version 64
1+
version 65
22
// The version number above should be incremented IF AND ONLY IF some
33
// change has been made that is sufficiently important to justify
44
// resetting the graphics preferences of all users to the recommended
@@ -80,6 +80,7 @@ RenderHeroProbeDistance 1 16
8080
RenderHeroProbeUpdateRate 1 6
8181
RenderHeroProbeConservativeUpdateMultiplier 1 16
8282
RenderDownScaleMethod 1 1
83+
RenderCAS 1 1
8384
RenderCASSharpness 1 1
8485
RenderExposure 1 4
8586
RenderTonemapType 1 1
@@ -120,6 +121,7 @@ RenderHeroProbeResolution 1 256
120121
RenderHeroProbeDistance 1 4
121122
RenderHeroProbeUpdateRate 1 6
122123
RenderHeroProbeConservativeUpdateMultiplier 1 16
124+
RenderCAS 1 0
123125
RenderCASSharpness 1 0
124126
RenderExposure 1 1
125127
RenderTonemapType 1 1
@@ -160,6 +162,7 @@ RenderHeroProbeResolution 1 256
160162
RenderHeroProbeDistance 1 6
161163
RenderHeroProbeUpdateRate 1 3
162164
RenderHeroProbeConservativeUpdateMultiplier 1 16
165+
RenderCAS 1 0
163166
RenderCASSharpness 1 0
164167
RenderExposure 1 1
165168
RenderTonemapType 1 1
@@ -200,6 +203,7 @@ RenderHeroProbeResolution 1 512
200203
RenderHeroProbeDistance 1 6
201204
RenderHeroProbeUpdateRate 1 3
202205
RenderHeroProbeConservativeUpdateMultiplier 1 16
206+
RenderCAS 1 0
203207
RenderCASSharpness 1 0
204208
RenderExposure 1 1
205209
RenderTonemapType 1 1
@@ -240,6 +244,7 @@ RenderHeroProbeResolution 1 512
240244
RenderHeroProbeDistance 1 6
241245
RenderHeroProbeUpdateRate 1 2
242246
RenderHeroProbeConservativeUpdateMultiplier 1 8
247+
RenderCAS 1 0
243248
RenderCASSharpness 1 0
244249
RenderExposure 1 1
245250
RenderTonemapType 1 1
@@ -280,6 +285,7 @@ RenderHeroProbeResolution 1 512
280285
RenderHeroProbeDistance 1 8
281286
RenderHeroProbeUpdateRate 1 2
282287
RenderHeroProbeConservativeUpdateMultiplier 1 8
288+
RenderCAS 1 1
283289
RenderCASSharpness 1 0.4
284290
RenderExposure 1 1
285291
RenderTonemapType 1 1
@@ -320,6 +326,7 @@ RenderHeroProbeResolution 1 1024
320326
RenderHeroProbeDistance 1 16
321327
RenderHeroProbeUpdateRate 1 1
322328
RenderHeroProbeConservativeUpdateMultiplier 1 4
329+
RenderCAS 1 1
323330
RenderCASSharpness 1 0.4
324331
RenderExposure 1 1
325332
RenderTonemapType 1 1
@@ -360,6 +367,7 @@ RenderHeroProbeResolution 1 2048
360367
RenderHeroProbeDistance 1 16
361368
RenderHeroProbeUpdateRate 1 1
362369
RenderHeroProbeConservativeUpdateMultiplier 1 4
370+
RenderCAS 1 1
363371
RenderCASSharpness 1 0.4
364372
RenderExposure 1 1
365373
RenderTonemapType 1 1

0 commit comments

Comments
 (0)