|
Revision 7347
(checked in by robert, 1 year ago)
|
Added depth peeling shaders from Steffen Frey
|
| Line | |
|---|
| 1 |
/* |
|---|
| 2 |
Steffen Frey |
|---|
| 3 |
Fachpraktikum Graphik-Programmierung 2007 |
|---|
| 4 |
Institut fuer Visualisierung und Interaktive Systeme |
|---|
| 5 |
Universitaet Stuttgart |
|---|
| 6 |
*/ |
|---|
| 7 |
|
|---|
| 8 |
uniform sampler2D normalDepthMap; |
|---|
| 9 |
|
|---|
| 10 |
uniform float width; |
|---|
| 11 |
uniform float height; |
|---|
| 12 |
varying vec3 normalPerVertex; |
|---|
| 13 |
varying float depthInCamera; |
|---|
| 14 |
|
|---|
| 15 |
uniform bool first; |
|---|
| 16 |
|
|---|
| 17 |
void main() |
|---|
| 18 |
{ |
|---|
| 19 |
vec2 texCoord = vec2(gl_FragCoord.x/width, gl_FragCoord.y/height); |
|---|
| 20 |
float prevDepth = texture2D(normalDepthMap, texCoord).w; |
|---|
| 21 |
|
|---|
| 22 |
//peel away depth layers |
|---|
| 23 |
if(!first && depthInCamera <= prevDepth + 0.0005) |
|---|
| 24 |
discard; |
|---|
| 25 |
|
|---|
| 26 |
//normalize the per fragment normal |
|---|
| 27 |
vec3 normal = normalize(normalPerVertex); |
|---|
| 28 |
|
|---|
| 29 |
// Encode normals: [-1,1] to [0,1] |
|---|
| 30 |
//normal = (normal+1.0)*0.5; |
|---|
| 31 |
normal = abs(normal); |
|---|
| 32 |
|
|---|
| 33 |
// Output color and depth |
|---|
| 34 |
gl_FragColor = vec4(normal, depthInCamera); |
|---|
| 35 |
gl_FragDepth = depthInCamera; |
|---|
| 36 |
} |
|---|