diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2019-11-07 15:14:15 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2019-11-27 17:50:54 +0300 |
commit | 9d7f65630b206385c03d997aa308dbe36c60298f (patch) | |
tree | 2cda98bf56d5184d4896d5dc6f971cc42fd4f057 /source/blender/draw/engines/eevee/shaders | |
parent | 17b63db4e2721f5cf8389c3354460771d8348c50 (diff) |
EEVEE: GLSL Renderpasses
Most of the renderpasses in EEVEE used post-processing on the CPU. For
final image rendering this is sufficient, but when we want to display
the data to the user we don't want to transfer to the CPU to do post
processing to then upload it back to the GPU to display the result.
This patch moves the renderpass postprocessing to a GLSL shader.
This is the first step to do, before we will enable the renderpasses in the viewport.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6206
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl b/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl new file mode 100644 index 00000000000..8a543f13fbc --- /dev/null +++ b/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl @@ -0,0 +1,63 @@ +#define SCE_PASS_Z (1 << 1) +#define SCE_PASS_AO (1 << 6) +#define SCE_PASS_NORMAL (1 << 8) +#define SCE_PASS_MIST (1 << 14) +#define SCE_PASS_SUBSURFACE_DIRECT (1 << 28) +#define SCE_PASS_SUBSURFACE_COLOR (1 << 30) + +#define ACCUMULATED_COLOR_PASSES (SCE_PASS_SUBSURFACE_DIRECT | SCE_PASS_SUBSURFACE_COLOR) +#define ACCUMULATED_VALUE_PASSES (SCE_PASS_MIST) +uniform int renderpassType; +uniform int currentSample; +uniform sampler2D inputBuffer; + +out vec4 fragColor; + +void main() +{ + ivec2 texel = ivec2(gl_FragCoord.xy); + + if (renderpassType == SCE_PASS_Z) { + float depth = texelFetch(depthBuffer, texel, 0).r; + if (depth == 1.0f) { + depth = 1e10; + } + else { + depth = -get_view_z_from_depth(depth); + } + fragColor.r = depth; + } + + else if (renderpassType == SCE_PASS_AO) { + float ao_accum = texelFetch(inputBuffer, texel, 0).r; + fragColor = vec4(vec3(min(1.0, ao_accum / currentSample)), 1.0); + } + + else if (renderpassType == SCE_PASS_NORMAL) { + vec2 encoded_normal = texelFetch(inputBuffer, texel, 0).rg; + /* decode the normals only when they are valid. otherwise the result buffer will be filled with + * NaN's */ + if (any(notEqual(encoded_normal, vec2(0.0)))) { + vec3 decoded_normal = normal_decode(texelFetch(inputBuffer, texel, 0).rg, vec3(0.0)); + vec3 world_normal = mat3(ViewMatrixInverse) * decoded_normal; + fragColor = vec4(world_normal, 0.0); + } + else { + fragColor = vec4(0.0); + } + } + + else if ((renderpassType & ACCUMULATED_VALUE_PASSES) != 0) { + float accumulated_value = texelFetch(inputBuffer, texel, 0).r; + fragColor.r = accumulated_value / currentSample; + } + + else if ((renderpassType & ACCUMULATED_COLOR_PASSES) != 0) { + vec3 accumulated_color = texelFetch(inputBuffer, texel, 0).rgb; + fragColor.rgb = accumulated_color / currentSample; + } + + else { + fragColor = vec4(1.0, 0.0, 1.0, 1.0); + } +}
\ No newline at end of file |