| 1 |
uniform sampler2D normalDepthMap; |
|---|
| 2 |
uniform sampler2D edgeMap; |
|---|
| 3 |
uniform float first; |
|---|
| 4 |
uniform float width; |
|---|
| 5 |
uniform float height; |
|---|
| 6 |
|
|---|
| 7 |
void main( void ) |
|---|
| 8 |
{ |
|---|
| 9 |
vec2 dx = vec2(1.0/width, 0.0); |
|---|
| 10 |
vec2 dy = vec2(0.0, 1.0/height); |
|---|
| 11 |
//vec2 center = gl_TexCoord[1].st; |
|---|
| 12 |
vec2 center = vec2(gl_FragCoord.x/width, gl_FragCoord.y/height); |
|---|
| 13 |
|
|---|
| 14 |
vec4 ul, ur, ll, lr; |
|---|
| 15 |
|
|---|
| 16 |
ul = texture2D(normalDepthMap, center -dx + dy); |
|---|
| 17 |
ur = texture2D(normalDepthMap, center + dx + dy); |
|---|
| 18 |
ll = texture2D(normalDepthMap, center - dx + dy); |
|---|
| 19 |
lr = texture2D(normalDepthMap, center + dx - dy); |
|---|
| 20 |
|
|---|
| 21 |
// calculate discontinuities |
|---|
| 22 |
vec3 discontinuity = vec3(0.0, 0.0, 0.0); |
|---|
| 23 |
|
|---|
| 24 |
//(Maybe should decode normals from [0,1] to [-1, 1], but works well the way it is done below) |
|---|
| 25 |
float dot0 = dot(ul.xyz, lr.xyz); |
|---|
| 26 |
float dot1 = dot(ur.xyz, ll.xyz); |
|---|
| 27 |
discontinuity.x = 0.5*(dot0+dot1); |
|---|
| 28 |
|
|---|
| 29 |
float depth_discont0 = 1.0-abs(ul.w - lr.w); |
|---|
| 30 |
float depth_discont1 = 1.0-abs(ur.w - ll.w); |
|---|
| 31 |
|
|---|
| 32 |
discontinuity.y = depth_discont0*depth_discont1; |
|---|
| 33 |
|
|---|
| 34 |
discontinuity.z = abs(discontinuity.x*discontinuity.y); |
|---|
| 35 |
|
|---|
| 36 |
//combine the generated edge map with the previous edge map |
|---|
| 37 |
vec4 prevEdge = texture2D(edgeMap, center); |
|---|
| 38 |
discontinuity.z = max(discontinuity.z - (1.0-first)*(1.0 - prevEdge.z), 0.0); |
|---|
| 39 |
gl_FragColor = vec4(discontinuity.z, discontinuity.z, discontinuity.z, 1.0); |
|---|
| 40 |
|
|---|
| 41 |
} |
|---|