Skip to content

Commit ef4b74e

Browse files
author
Rye
authored
Merge pull request #3005 from secondlife/rye/postperf
Reduce number of full screen copies during renderFinalize
2 parents 4686f72 + 687930d commit ef4b74e

22 files changed

+657
-535
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/SMAANeighborhoodBlendF.glsl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ in vec2 vary_texcoord0;
3131
in vec4 vary_offset;
3232

3333
uniform sampler2D diffuseRect;
34+
uniform sampler2D emissiveRect;
3435
uniform sampler2D blendTex;
3536
#if SMAA_REPROJECTION
3637
uniform sampler2D velocityTex;
3738
#endif
39+
uniform sampler2D depthMap;
3840

3941
#define float4 vec4
4042
#define float2 vec2
@@ -51,13 +53,19 @@ float4 SMAANeighborhoodBlendingPS(float2 texcoord,
5153

5254
void main()
5355
{
54-
frag_color = SMAANeighborhoodBlendingPS(vary_texcoord0,
56+
vec4 diff = SMAANeighborhoodBlendingPS(vary_texcoord0,
5557
vary_offset,
5658
diffuseRect,
5759
blendTex
5860
#if SMAA_REPROJECTION
5961
, velocityTex
6062
#endif
6163
);
64+
#ifndef NO_GLOW
65+
diff.rgb += texture2D(emissiveRect, vary_texcoord0).rgb;
66+
#endif
67+
frag_color = diff;
68+
69+
gl_FragDepth = texture(depthMap, vary_texcoord0.xy).r;
6270
}
6371

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ out vec4 frag_color;
2929

3030
uniform sampler2D diffuseRect;
3131
uniform sampler2D depthMap;
32+
uniform sampler2D emissiveRect;
3233

3334
uniform float focal_distance;
3435
uniform float blur_constant;
@@ -66,12 +67,13 @@ void main()
6667
vec4 p = inv_proj*ndc;
6768
float depth = p.z/p.w;
6869

69-
vec4 diff = texture(diffuseRect, vary_fragcoord.xy);
70+
vec4 diff = texture(diffuseRect, tc);
7071

7172
float sc = calc_cof(depth);
7273
sc = min(sc, max_cof);
7374
sc = max(sc, -max_cof);
7475

75-
frag_color.rgb = diff.rgb;
76+
vec4 bloom = texture2D(emissiveRect, tc);
77+
frag_color.rgb = diff.rgb + bloom.rgb;
7678
frag_color.a = sc/max_cof*0.5+0.5;
7779
}

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 & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,12 @@ out vec4 frag_color;
3030
uniform sampler2D diffuseRect;
3131
uniform sampler2D depthMap;
3232

33-
uniform vec2 screen_res;
3433
in vec2 vary_fragcoord;
3534

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-
7635
void main()
7736
{
7837
vec4 diff = texture(diffuseRect, vary_fragcoord.xy);
7938

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-
8739
frag_color = diff;
8840

8941
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/app_settings/shaders/class1/interface/glowcombineF.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ out vec4 frag_color;
2929

3030
uniform sampler2D diffuseRect;
3131
uniform sampler2D emissiveRect;
32+
uniform sampler2D depthMap;
3233

3334
in vec2 tc;
3435

3536
void main()
3637
{
3738
frag_color = texture(diffuseRect, tc) + texture(emissiveRect, tc);
39+
gl_FragDepth = texture(depthMap, tc.xy).r;
3840
}

0 commit comments

Comments
 (0)