-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add a quality option - remove the ping-pong code, we'll disable for GPU that don't work instead. - improve quality by doing a better first downscale (using a 5x5 gaussian). - improve performance by using a 9 tap filter instead of 13 for in most cases - fix usages of setMinMaxLevels as it resets the base level to "min"
- Loading branch information
1 parent
9c0fb67
commit 9f62dc2
Showing
18 changed files
with
397 additions
and
245 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,98 @@ | ||
material { | ||
name : bloomDownsample2x, | ||
parameters : [ | ||
{ | ||
type : sampler2d, | ||
name : source, | ||
precision: medium | ||
}, | ||
{ | ||
type : float, | ||
name : level | ||
}, | ||
{ | ||
type : float, | ||
name : threshold | ||
}, | ||
{ | ||
type : float, | ||
name : fireflies | ||
}, | ||
{ | ||
type : float, | ||
name : invHighlight | ||
} | ||
], | ||
variables : [ | ||
vertex | ||
], | ||
domain : postprocess, | ||
depthWrite : false, | ||
depthCulling : false | ||
} | ||
|
||
vertex { | ||
void postProcessVertex(inout PostProcessVertexInputs postProcess) { | ||
postProcess.vertex.xy = uvToRenderTargetUV(postProcess.normalizedUV); | ||
} | ||
} | ||
|
||
fragment { | ||
|
||
void dummy(){} | ||
|
||
void threshold(inout vec3 c) { | ||
// threshold everything below 1.0 | ||
c = max(vec3(0.0), c - 1.0); | ||
// crush everything above 1 | ||
highp float f = max3(c); | ||
c *= 1.0 / (1.0 + f * materialParams.invHighlight); | ||
} | ||
|
||
void postProcess(inout PostProcessInputs postProcess) { | ||
float lod = materialParams.level; | ||
|
||
highp vec2 size = vec2(textureSize(materialParams_source, int(lod))); | ||
highp vec2 texelSize = vec2(1.0) / size; | ||
|
||
// Castaño, 2013, "Shadow Mapping Summary Part 1" | ||
// 3x3 gaussian filter with 4 linear samples | ||
vec2 offset = vec2(0.5); | ||
highp vec2 uv = (variable_vertex.xy * size) + offset; | ||
highp vec2 base = (floor(uv) - offset) * texelSize; | ||
highp vec2 st = fract(uv); | ||
vec2 uw = vec2(3.0 - 2.0 * st.x, 1.0 + 2.0 * st.x); | ||
vec2 vw = vec2(3.0 - 2.0 * st.y, 1.0 + 2.0 * st.y); | ||
highp vec2 u = vec2((2.0 - st.x) / uw.x - 1.0, st.x / uw.y + 1.0) * texelSize.x; | ||
highp vec2 v = vec2((2.0 - st.y) / vw.x - 1.0, st.y / vw.y + 1.0) * texelSize.y; | ||
vec3 c0 = textureLod(materialParams_source, base + vec2(u.x, v.x), lod).rgb; | ||
vec3 c1 = textureLod(materialParams_source, base + vec2(u.y, v.x), lod).rgb; | ||
vec3 c2 = textureLod(materialParams_source, base + vec2(u.x, v.y), lod).rgb; | ||
vec3 c3 = textureLod(materialParams_source, base + vec2(u.y, v.y), lod).rgb; | ||
|
||
float w0 = uw.x * vw.x * (1.0 / 16.0); | ||
float w1 = uw.y * vw.x * (1.0 / 16.0); | ||
float w2 = uw.x * vw.y * (1.0 / 16.0); | ||
float w3 = uw.y * vw.y * (1.0 / 16.0); | ||
|
||
if (materialParams.fireflies > 0.0) { | ||
w0 /= (1.0 + max3(c0)); | ||
w1 /= (1.0 + max3(c1)); | ||
w2 /= (1.0 + max3(c2)); | ||
w3 /= (1.0 + max3(c3)); | ||
float w = 1.0 / (w0 + w1 + w2 + w3); | ||
w0 *= w; | ||
w1 *= w; | ||
w2 *= w; | ||
w3 *= w; | ||
} | ||
|
||
vec3 c = c0 * w0 + c1 * w1 + c2 * w2 + c3 * w3; | ||
|
||
if (materialParams.threshold > 0.0) { | ||
threshold(c); | ||
} | ||
|
||
postProcess.color.rgb = c; | ||
} | ||
} |
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,65 @@ | ||
material { | ||
name : bloomDownsample9, | ||
parameters : [ | ||
{ | ||
type : sampler2d, | ||
name : source, | ||
precision: medium | ||
} | ||
], | ||
variables : [ | ||
vertex | ||
], | ||
domain : postprocess, | ||
depthWrite : false, | ||
depthCulling : false | ||
} | ||
|
||
vertex { | ||
void postProcessVertex(inout PostProcessVertexInputs postProcess) { | ||
postProcess.vertex.xy = uvToRenderTargetUV(postProcess.normalizedUV); | ||
} | ||
} | ||
|
||
fragment { | ||
|
||
void dummy(){} | ||
|
||
// see https://www.shadertoy.com/view/cslczj | ||
// 6x6 downsampling kernel implemented via 9 bilinear samples | ||
|
||
void postProcess(inout PostProcessInputs postProcess) { | ||
highp vec2 uv = variable_vertex.xy; | ||
highp vec2 size = vec2(1.0) / vec2(textureSize(materialParams_source, 0)); | ||
|
||
float o = 1.5 + 0.261629; | ||
float wa = 7.46602 / 32.0; | ||
float wb = 1.0 - wa * 2.0; | ||
float wab = wa * wb; | ||
float waa = wa * wa; | ||
float wbb = wb * wb; | ||
|
||
size *= o; | ||
|
||
vec3 c = textureLod(materialParams_source, uv + vec2(0.0) , 0.0).rgb; | ||
vec3 l = textureLod(materialParams_source, uv + vec2(-size.x, 0.0), 0.0).rgb; | ||
vec3 r = textureLod(materialParams_source, uv + vec2( size.x, 0.0), 0.0).rgb; | ||
vec3 b = textureLod(materialParams_source, uv + vec2( 0.0,-size.y), 0.0).rgb; | ||
vec3 t = textureLod(materialParams_source, uv + vec2( 0.0, size.y), 0.0).rgb; | ||
vec3 lb = textureLod(materialParams_source, uv + vec2(-size.x,-size.y), 0.0).rgb; | ||
vec3 rb = textureLod(materialParams_source, uv + vec2( size.x,-size.y), 0.0).rgb; | ||
vec3 lt = textureLod(materialParams_source, uv + vec2(-size.x, size.y), 0.0).rgb; | ||
vec3 rt = textureLod(materialParams_source, uv + vec2( size.x, size.y), 0.0).rgb; | ||
|
||
postProcess.color.rgb = | ||
(c * wbb + | ||
(l * wab + | ||
(r * wab + | ||
(b * wab + | ||
(t * wab + | ||
(lb * waa + | ||
(rb * waa + | ||
(lt * waa + | ||
(rt * waa))))))))); | ||
} | ||
} |
Oops, something went wrong.