diff options
author | Sven Gothel <[email protected]> | 2012-02-18 16:59:52 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-02-18 16:59:52 +0100 |
commit | 390ef63a8da4c3e89b2f61526b641b1b2b82f42d (patch) | |
tree | ba0fd8f3294bc9af8381796efd4a91c871615c86 /src/demos/dualDepthPeeling/shader | |
parent | d7e533dca5c70d7c07d56457764e733085136c0a (diff) |
unify shader names(2)
Diffstat (limited to 'src/demos/dualDepthPeeling/shader')
26 files changed, 505 insertions, 0 deletions
diff --git a/src/demos/dualDepthPeeling/shader/dual_peeling_blend.fp b/src/demos/dualDepthPeeling/shader/dual_peeling_blend.fp new file mode 100644 index 0000000..3ba7cf9 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/dual_peeling_blend.fp @@ -0,0 +1,17 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Dual Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +uniform samplerRECT TempTex; + +void main(void) +{ + gl_FragColor = textureRect(TempTex, gl_FragCoord.xy); + // for occlusion query + if (gl_FragColor.a == 0) discard; +} diff --git a/src/demos/dualDepthPeeling/shader/dual_peeling_blend.vp b/src/demos/dualDepthPeeling/shader/dual_peeling_blend.vp new file mode 100644 index 0000000..1d0edfc --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/dual_peeling_blend.vp @@ -0,0 +1,13 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Dual Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +void main(void) +{ + gl_Position = gl_ModelViewMatrix * gl_Vertex; +} diff --git a/src/demos/dualDepthPeeling/shader/dual_peeling_final.fp b/src/demos/dualDepthPeeling/shader/dual_peeling_final.fp new file mode 100644 index 0000000..ec57117 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/dual_peeling_final.fp @@ -0,0 +1,28 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Dual Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +uniform samplerRECT DepthBlenderTex; +uniform samplerRECT FrontBlenderTex; +uniform samplerRECT BackBlenderTex; + +void main(void) +{ + vec4 frontColor = textureRect(FrontBlenderTex, gl_FragCoord.xy); + vec3 backColor = textureRect(BackBlenderTex, gl_FragCoord.xy).rgb; + float alphaMultiplier = 1.0 - frontColor.w; + + // front + back + gl_FragColor.rgb = frontColor + backColor * alphaMultiplier; + + // front blender + //gl_FragColor.rgb = frontColor + vec3(alphaMultiplier); + + // back blender + //gl_FragColor.rgb = backColor; +} diff --git a/src/demos/dualDepthPeeling/shader/dual_peeling_final.vp b/src/demos/dualDepthPeeling/shader/dual_peeling_final.vp new file mode 100644 index 0000000..1d0edfc --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/dual_peeling_final.vp @@ -0,0 +1,13 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Dual Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +void main(void) +{ + gl_Position = gl_ModelViewMatrix * gl_Vertex; +} diff --git a/src/demos/dualDepthPeeling/shader/dual_peeling_init.fp b/src/demos/dualDepthPeeling/shader/dual_peeling_init.fp new file mode 100644 index 0000000..1c6234a --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/dual_peeling_init.fp @@ -0,0 +1,13 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Dual Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +void main(void) +{ + gl_FragColor.xy = vec2(-gl_FragCoord.z, gl_FragCoord.z); +} diff --git a/src/demos/dualDepthPeeling/shader/dual_peeling_init.vp b/src/demos/dualDepthPeeling/shader/dual_peeling_init.vp new file mode 100644 index 0000000..583aad4 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/dual_peeling_init.vp @@ -0,0 +1,13 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Dual Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +void main(void) +{ + gl_Position = ftransform(); +} diff --git a/src/demos/dualDepthPeeling/shader/dual_peeling_peel.fp b/src/demos/dualDepthPeeling/shader/dual_peeling_peel.fp new file mode 100644 index 0000000..2d61b89 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/dual_peeling_peel.fp @@ -0,0 +1,67 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Dual Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +#extension ARB_draw_buffers : require + +uniform samplerRECT DepthBlenderTex; +uniform samplerRECT FrontBlenderTex; + +#define MAX_DEPTH 1.0 + +vec4 ShadeFragment(); + +void main(void) +{ + // window-space depth interpolated linearly in screen space + float fragDepth = gl_FragCoord.z; + + vec2 depthBlender = textureRect(DepthBlenderTex, gl_FragCoord.xy).xy; + vec4 forwardTemp = textureRect(FrontBlenderTex, gl_FragCoord.xy); + + // Depths and 1.0-alphaMult always increase + // so we can use pass-through by default with MAX blending + gl_FragData[0].xy = depthBlender; + + // Front colors always increase (DST += SRC*ALPHA_MULT) + // so we can use pass-through by default with MAX blending + gl_FragData[1] = forwardTemp; + + // Because over blending makes color increase or decrease, + // we cannot pass-through by default. + // Each pass, only one fragment writes a color greater than 0 + gl_FragData[2] = vec4(0.0); + + float nearestDepth = -depthBlender.x; + float farthestDepth = depthBlender.y; + float alphaMultiplier = 1.0 - forwardTemp.w; + + if (fragDepth < nearestDepth || fragDepth > farthestDepth) { + // Skip this depth in the peeling algorithm + gl_FragData[0].xy = vec2(-MAX_DEPTH); + return; + } + + if (fragDepth > nearestDepth && fragDepth < farthestDepth) { + // This fragment needs to be peeled again + gl_FragData[0].xy = vec2(-fragDepth, fragDepth); + return; + } + + // If we made it here, this fragment is on the peeled layer from last pass + // therefore, we need to shade it, and make sure it is not peeled any farther + vec4 color = ShadeFragment(); + gl_FragData[0].xy = vec2(-MAX_DEPTH); + + if (fragDepth == nearestDepth) { + gl_FragData[1].xyz += color.rgb * color.a * alphaMultiplier; + gl_FragData[1].w = 1.0 - alphaMultiplier * (1.0 - color.a); + } else { + gl_FragData[2] += color; + } +} diff --git a/src/demos/dualDepthPeeling/shader/dual_peeling_peel.vp b/src/demos/dualDepthPeeling/shader/dual_peeling_peel.vp new file mode 100644 index 0000000..b49aeff --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/dual_peeling_peel.vp @@ -0,0 +1,16 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Dual Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +vec3 ShadeVertex(); + +void main(void) +{ + gl_Position = ftransform(); + gl_TexCoord[0].xyz = ShadeVertex(); +} diff --git a/src/demos/dualDepthPeeling/shader/front_peeling_blend.fp b/src/demos/dualDepthPeeling/shader/front_peeling_blend.fp new file mode 100644 index 0000000..81385aa --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/front_peeling_blend.fp @@ -0,0 +1,15 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +uniform samplerRECT TempTex; + +void main(void) +{ + gl_FragColor = textureRect(TempTex, gl_FragCoord.xy); +} diff --git a/src/demos/dualDepthPeeling/shader/front_peeling_blend.vp b/src/demos/dualDepthPeeling/shader/front_peeling_blend.vp new file mode 100644 index 0000000..817857b --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/front_peeling_blend.vp @@ -0,0 +1,13 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +void main(void) +{ + gl_Position = gl_ModelViewMatrix * gl_Vertex; +} diff --git a/src/demos/dualDepthPeeling/shader/front_peeling_final.fp b/src/demos/dualDepthPeeling/shader/front_peeling_final.fp new file mode 100644 index 0000000..dbc9a65 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/front_peeling_final.fp @@ -0,0 +1,17 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +uniform samplerRECT ColorTex; +uniform vec3 BackgroundColor; + +void main(void) +{ + vec4 frontColor = textureRect(ColorTex, gl_FragCoord.xy); + gl_FragColor.rgb = frontColor + BackgroundColor * frontColor.a; +} diff --git a/src/demos/dualDepthPeeling/shader/front_peeling_final.vp b/src/demos/dualDepthPeeling/shader/front_peeling_final.vp new file mode 100644 index 0000000..817857b --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/front_peeling_final.vp @@ -0,0 +1,13 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +void main(void) +{ + gl_Position = gl_ModelViewMatrix * gl_Vertex; +} diff --git a/src/demos/dualDepthPeeling/shader/front_peeling_init.fp b/src/demos/dualDepthPeeling/shader/front_peeling_init.fp new file mode 100644 index 0000000..fdaaa79 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/front_peeling_init.fp @@ -0,0 +1,16 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +vec4 ShadeFragment(); + +void main(void) +{ + vec4 color = ShadeFragment(); + gl_FragColor = vec4(color.rgb * color.a, 1.0 - color.a); +} diff --git a/src/demos/dualDepthPeeling/shader/front_peeling_init.vp b/src/demos/dualDepthPeeling/shader/front_peeling_init.vp new file mode 100644 index 0000000..b005d0c --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/front_peeling_init.vp @@ -0,0 +1,16 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +vec3 ShadeVertex(); + +void main(void) +{ + gl_Position = ftransform(); + gl_TexCoord[0].xyz = ShadeVertex(); +} diff --git a/src/demos/dualDepthPeeling/shader/front_peeling_peel.fp b/src/demos/dualDepthPeeling/shader/front_peeling_peel.fp new file mode 100644 index 0000000..7f58b3e --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/front_peeling_peel.fp @@ -0,0 +1,25 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +uniform samplerRECT DepthTex; + +vec4 ShadeFragment(); + +void main(void) +{ + // Bit-exact comparison between FP32 z-buffer and fragment depth + float frontDepth = textureRect(DepthTex, gl_FragCoord.xy).r; + if (gl_FragCoord.z <= frontDepth) { + discard; + } + + // Shade all the fragments behind the z-buffer + vec4 color = ShadeFragment(); + gl_FragColor = vec4(color.rgb * color.a, color.a); +} diff --git a/src/demos/dualDepthPeeling/shader/front_peeling_peel.vp b/src/demos/dualDepthPeeling/shader/front_peeling_peel.vp new file mode 100644 index 0000000..b005d0c --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/front_peeling_peel.vp @@ -0,0 +1,16 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Depth Peeling +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +vec3 ShadeVertex(); + +void main(void) +{ + gl_Position = ftransform(); + gl_TexCoord[0].xyz = ShadeVertex(); +} diff --git a/src/demos/dualDepthPeeling/shader/shade.fp b/src/demos/dualDepthPeeling/shader/shade.fp new file mode 100644 index 0000000..94f8dcc --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/shade.fp @@ -0,0 +1,40 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency Fragment Shader +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +uniform float Alpha; + +#define COLOR_FREQ 30.0 +#define ALPHA_FREQ 30.0 + +#if 1 +vec4 ShadeFragment() +{ + float xWorldPos = gl_TexCoord[0].x; + float yWorldPos = gl_TexCoord[0].y; + float diffuse = gl_TexCoord[0].z; + + vec4 color; + float i = floor(xWorldPos * COLOR_FREQ); + float j = floor(yWorldPos * ALPHA_FREQ); + color.rgb = (fmod(i, 2.0) == 0) ? vec3(.4,.85,.0) : vec3(1.0); + //color.a = (fmod(j, 2.0) == 0) ? Alpha : 0.2; + color.a = Alpha; + + color.rgb *= diffuse; + return color; +} +#else +vec4 ShadeFragment() +{ + vec4 color; + color.rgb = vec3(.4,.85,.0); + color.a = Alpha; + return color; +} +#endif diff --git a/src/demos/dualDepthPeeling/shader/shade.vp b/src/demos/dualDepthPeeling/shader/shade.vp new file mode 100644 index 0000000..2f0a4ba --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/shade.vp @@ -0,0 +1,14 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency Vertex Shader +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +vec3 ShadeVertex() +{ + float diffuse = abs(normalize(gl_NormalMatrix * gl_Normal).z); + return vec3(gl_Vertex.xy, diffuse); +} diff --git a/src/demos/dualDepthPeeling/shader/wavg_final.fp b/src/demos/dualDepthPeeling/shader/wavg_final.fp new file mode 100644 index 0000000..034491c --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/wavg_final.fp @@ -0,0 +1,29 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Average Color +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +uniform samplerRECT ColorTex0; +uniform samplerRECT ColorTex1; +uniform vec3 BackgroundColor; + +void main(void) +{ + vec4 SumColor = textureRect(ColorTex0, gl_FragCoord.xy); + float n = textureRect(ColorTex1, gl_FragCoord.xy).r; + + if (n == 0.0) { + gl_FragColor.rgb = BackgroundColor; + return; + } + + vec3 AvgColor = SumColor.rgb / SumColor.a; + float AvgAlpha = SumColor.a / n; + + float T = pow(1.0-AvgAlpha, n); + gl_FragColor.rgb = AvgColor * (1 - T) + BackgroundColor * T; +} diff --git a/src/demos/dualDepthPeeling/shader/wavg_final.vp b/src/demos/dualDepthPeeling/shader/wavg_final.vp new file mode 100644 index 0000000..5c07236 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/wavg_final.vp @@ -0,0 +1,13 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Average Color +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +void main(void) +{ + gl_Position = gl_ModelViewMatrix * gl_Vertex; +} diff --git a/src/demos/dualDepthPeeling/shader/wavg_init.fp b/src/demos/dualDepthPeeling/shader/wavg_init.fp new file mode 100644 index 0000000..e50aeb0 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/wavg_init.fp @@ -0,0 +1,19 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Average Color +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +#extension ARB_draw_buffers : require + +vec4 ShadeFragment(); + +void main(void) +{ + vec4 color = ShadeFragment(); + gl_FragData[0] = vec4(color.rgb * color.a, color.a); + gl_FragData[1] = vec4(1.0); +} diff --git a/src/demos/dualDepthPeeling/shader/wavg_init.vp b/src/demos/dualDepthPeeling/shader/wavg_init.vp new file mode 100644 index 0000000..3d3d25a --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/wavg_init.vp @@ -0,0 +1,16 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Average Color +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +vec3 ShadeVertex(); + +void main(void) +{ + gl_Position = ftransform(); + gl_TexCoord[0].xyz = ShadeVertex(); +} diff --git a/src/demos/dualDepthPeeling/shader/wsum_final.fp b/src/demos/dualDepthPeeling/shader/wsum_final.fp new file mode 100644 index 0000000..76c0293 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/wsum_final.fp @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Weighted Sums +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +uniform samplerRECT ColorTex; +uniform vec3 BackgroundColor; + +// Sum(A_i * C_i) + C_bg * (1 - Sum(A_i)) +void main(void) +{ + vec4 S = textureRect(ColorTex, gl_FragCoord.xy); + gl_FragColor.rgb = S.rgb + BackgroundColor * (1.0 - S.a); +} diff --git a/src/demos/dualDepthPeeling/shader/wsum_final.vp b/src/demos/dualDepthPeeling/shader/wsum_final.vp new file mode 100644 index 0000000..8264811 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/wsum_final.vp @@ -0,0 +1,13 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Weighted Sums +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +void main(void) +{ + gl_Position = gl_ModelViewMatrix * gl_Vertex; +} diff --git a/src/demos/dualDepthPeeling/shader/wsum_init.fp b/src/demos/dualDepthPeeling/shader/wsum_init.fp new file mode 100644 index 0000000..5cccb14 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/wsum_init.fp @@ -0,0 +1,16 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Weighted Sums +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +vec4 ShadeFragment(); + +void main(void) +{ + vec4 color = ShadeFragment(); + gl_FragColor = vec4(color.rgb * color.a, color.a); +} diff --git a/src/demos/dualDepthPeeling/shader/wsum_init.vp b/src/demos/dualDepthPeeling/shader/wsum_init.vp new file mode 100644 index 0000000..5445325 --- /dev/null +++ b/src/demos/dualDepthPeeling/shader/wsum_init.vp @@ -0,0 +1,16 @@ +//-------------------------------------------------------------------------------------- +// Order Independent Transparency with Weighted Sums +// +// Author: Louis Bavoil +// Email: [email protected] +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +vec3 ShadeVertex(); + +void main(void) +{ + gl_Position = ftransform(); + gl_TexCoord[0].xyz = ShadeVertex(); +} |