From d4312ccb1a73acecc57394b2c5230083b1f8b6a1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 24 Apr 2021 14:31:11 +0300 Subject: [PATCH] Rearrange postprocessing shaders Postprocess.glsl has been renamed to flat_effect.glsl and made more generic so it can be used in non-postprocessing effects too. --- builtin_data/_ambientocclusion.glsl | 1 + builtin_data/_ambientocclusion_combine.glsl | 3 ++- builtin_data/_ambientocclusion_occlude.glsl | 5 +++-- builtin_data/_bloom.glsl | 1 + builtin_data/_bloom_blur.glsl | 5 +++-- builtin_data/_bloom_combine.glsl | 3 ++- builtin_data/_colorcurve.glsl | 7 +++++-- shaderlib/{postprocess.glsl => flat_effect.glsl} | 5 ----- 8 files changed, 17 insertions(+), 13 deletions(-) rename shaderlib/{postprocess.glsl => flat_effect.glsl} (61%) diff --git a/builtin_data/_ambientocclusion.glsl b/builtin_data/_ambientocclusion.glsl index 89d13357..dca636bb 100644 --- a/builtin_data/_ambientocclusion.glsl +++ b/builtin_data/_ambientocclusion.glsl @@ -2,6 +2,7 @@ const int max_samples = 32; uniform mat4 projection_matrix; +uniform sampler2D source; uniform sampler2D depth; uniform sampler2D occlusion; uniform sampler2D rotate; diff --git a/builtin_data/_ambientocclusion_combine.glsl b/builtin_data/_ambientocclusion_combine.glsl index 616bada9..88929066 100644 --- a/builtin_data/_ambientocclusion_combine.glsl +++ b/builtin_data/_ambientocclusion_combine.glsl @@ -1,7 +1,8 @@ -import postprocess; +import flat_effect; import _ambientocclusion; #pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; void main() { vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r)); diff --git a/builtin_data/_ambientocclusion_occlude.glsl b/builtin_data/_ambientocclusion_occlude.glsl index e1900323..260f1efa 100644 --- a/builtin_data/_ambientocclusion_occlude.glsl +++ b/builtin_data/_ambientocclusion_occlude.glsl @@ -1,7 +1,8 @@ -import postprocess; +import flat_effect; import _ambientocclusion; #pragma MSP stage(fragment) +layout(location=0) out float frag_out; void main() { vec4 rv = texture(rotate, gl_FragCoord.xy/4.0)*2.0-1.0; @@ -21,5 +22,5 @@ void main() count += 1.0; } } - frag_color = vec4(1.0-occlusion_sum/count, 0.0, 0.0, 1.0); + frag_out = 1.0-occlusion_sum/count; } diff --git a/builtin_data/_bloom.glsl b/builtin_data/_bloom.glsl index 262cb29b..fe3dd6e4 100644 --- a/builtin_data/_bloom.glsl +++ b/builtin_data/_bloom.glsl @@ -1,3 +1,4 @@ +uniform sampler2D source; uniform sampler2D blurred; uniform vec2 delta; uniform BloomParams diff --git a/builtin_data/_bloom_blur.glsl b/builtin_data/_bloom_blur.glsl index ce1cf755..0207506d 100644 --- a/builtin_data/_bloom_blur.glsl +++ b/builtin_data/_bloom_blur.glsl @@ -1,10 +1,11 @@ -import postprocess; +import flat_effect; import _bloom; #pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; void main() { - frag_color = vec4(0.0, 0.0, 0.0, 0.0); + frag_color = vec4(0.0); for(int i=0; i<=size*2; ++i) frag_color += texture(source, texcoord+delta*float(i-size))*factors[i]; } diff --git a/builtin_data/_bloom_combine.glsl b/builtin_data/_bloom_combine.glsl index 641459be..be561af1 100644 --- a/builtin_data/_bloom_combine.glsl +++ b/builtin_data/_bloom_combine.glsl @@ -1,7 +1,8 @@ -import postprocess; +import flat_effect; import _bloom; #pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; void main() { frag_color = mix(texture(source, texcoord), texture(blurred, texcoord), strength); diff --git a/builtin_data/_colorcurve.glsl b/builtin_data/_colorcurve.glsl index 23b5577d..9b6ae362 100644 --- a/builtin_data/_colorcurve.glsl +++ b/builtin_data/_colorcurve.glsl @@ -1,13 +1,16 @@ -import postprocess; +import flat_effect; -uniform sampler1D curve; uniform ToneMapping { float exposure; vec3 brightness_response; }; +uniform sampler2D source; +uniform sampler1D curve; + #pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; void main() { vec4 incoming = texture(source, texcoord); diff --git a/shaderlib/postprocess.glsl b/shaderlib/flat_effect.glsl similarity index 61% rename from shaderlib/postprocess.glsl rename to shaderlib/flat_effect.glsl index c868bd11..0377b8a6 100644 --- a/shaderlib/postprocess.glsl +++ b/shaderlib/flat_effect.glsl @@ -1,5 +1,3 @@ -uniform sampler2D source; - #pragma MSP stage(vertex) layout(location=0) in vec4 vertex; void main() @@ -8,6 +6,3 @@ void main() out vec2 texcoord = vertex.xy*0.5+0.5; passthrough; } - -#pragma MSP stage(fragment) -layout(location=0) out vec4 frag_color; -- 2.43.0