File: ambient_occlusion8.frag

package info (click to toggle)
meshlab 2022.02%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 47,348 kB
  • sloc: cpp: 536,635; ansic: 27,783; sh: 539; makefile: 36
file content (90 lines) | stat: -rw-r--r-- 3,523 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/****************************************************************************
* MeshLab                                                           o o     *
* An extendible mesh processor                                    o     o   *
*                                                                _   O  _   *
* Copyright(C) 2005, 2009                                          \/)\/    *
* Visual Computing Lab                                            /\/|      *
* ISTI - Italian National Research Council                           |      *
*                                                                    \      *
* All rights reserved.                                                      *
*                                                                           *
* This program is free software; you can redistribute it and/or modify      *
* it under the terms of the GNU General Public License as published by      *
* the Free Software Foundation; either version 2 of the License, or         *
* (at your option) any later version.                                       *
*                                                                           *
* This program is distributed in the hope that it will be useful,           *
* but WITHOUT ANY WARRANTY; without even the implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/

#version 110

uniform sampler3D vTexture;
uniform sampler3D nTexture;
uniform sampler2DShadow dTexture;

uniform vec3 viewDirection;
uniform mat4 mvprMatrix;

uniform float numTexPages;
uniform float viewpSize;
uniform float texSize;

vec4 project(vec4 coords)
{
   coords = mvprMatrix * coords; // clip space [-1 .. 1]   
   return vec4(coords.xyz * 0.5+0.5, coords.w);
}

vec4 occlusionQuery(float zLevel, float zLevelMax)
{  
      vec4 R = vec4(0.0, 0.0, 0.0, 1.0);

      float zcoord = zLevel/zLevelMax;
      zcoord += 1.0/(zLevelMax*2.0);

      vec3 c3D = vec3(gl_FragCoord.xy/viewpSize, zcoord);

      vec4 N = texture3D(nTexture, c3D);
      vec4 P = project(texture3D(vTexture, c3D)) * (viewpSize/texSize);
      
      if ( shadow2DProj(dTexture, P).r > 0.5 )
         R.r = max(dot(N.xyz, viewDirection), 0.0);
         
      return R;
}

float getPotSize (float npotSize)
{
   float potSize = 0.0;

   if (npotSize <= 2.0)
      potSize = npotSize;

   if (npotSize > 2.0 && npotSize <= 4.0)
      potSize = 4.0;

   if (npotSize > 4.0 && npotSize <= 8.0)
      potSize = 8.0;
   
   return potSize;
}

void main(void)
{
   float potTexPages = getPotSize(numTexPages);

      if(numTexPages > 0.) gl_FragData[0] = occlusionQuery(0., potTexPages);
      if(numTexPages > 1.) gl_FragData[1] = occlusionQuery(1., potTexPages);
      if(numTexPages > 2.) gl_FragData[2] = occlusionQuery(2., potTexPages);
      if(numTexPages > 3.) gl_FragData[3] = occlusionQuery(3., potTexPages);
      if(numTexPages > 4.) gl_FragData[4] = occlusionQuery(4., potTexPages);
      if(numTexPages > 5.) gl_FragData[5] = occlusionQuery(5., potTexPages);
      if(numTexPages > 6.) gl_FragData[6] = occlusionQuery(6., potTexPages);
      if(numTexPages > 7.) gl_FragData[7] = occlusionQuery(7., potTexPages);
	
}