postgiF.glsl 2.69 KB
Newer Older
1
2
3
/** 
 * @file postgiF.glsl
 *
4
 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 * Second Life Viewer Source Code
 * Copyright (C) 2007, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
23
 * $/LicenseInfo$
24
25
 */

26
27
/*[EXTRA_CODE_HERE]*/

28
 #ifdef DEFINE_GL_FRAGCOLOR
29
30
out vec4 frag_color;
#else
31
#define frag_color gl_FragColor
32
#endif
33
 
34
35
36
37
38
39
40
41
42
43
44
45
uniform sampler2DRect depthMap;
uniform sampler2DRect normalMap;
uniform sampler2DRect giLightMap;
uniform sampler2D	noiseMap;

uniform vec2 kern[32];
uniform float dist_factor;
uniform vec2 delta;
uniform int kern_length;
uniform float kern_scale;
uniform vec3 blur_quad;

46
VARYING vec2 vary_fragcoord;
47
48
49
50

uniform mat4 inv_proj;
uniform vec2 screen_res;

51
vec4 getPosition(vec2 pos_screen);
52
53
54

void main() 
{
55
56
	vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz;
	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
57
58
59
60
61
62
63
64
65
66
67
	vec3 pos = getPosition(vary_fragcoord.xy).xyz;
	
	vec3 ccol = texture2DRect(giLightMap, vary_fragcoord.xy).rgb;
	vec2 dlt = kern_scale * delta/(1.0+norm.xy*norm.xy);
	dlt /= max(-pos.z*dist_factor, 1.0);
	float defined_weight = kern[0].x;
	vec3 col = vec3(0.0);
	
	for (int i = 0; i < kern_length; i++)
	{
		vec2 tc = vary_fragcoord.xy + kern[i].y*dlt;
68
69
		vec3 sampNorm = texture2DRect(normalMap, tc.xy).xyz;
		sampNorm = vec3((sampNorm.xy-0.5)*2.0,sampNorm.z); // unpack norm
70
	    
71
		float d = dot(norm.xyz, sampNorm);
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
		
		if (d > 0.8)
		{
			vec3 samppos = getPosition(tc.xy).xyz;
			samppos -= pos;
			if (dot(samppos,samppos) < -0.05*pos.z)
			{
	    		col += texture2DRect(giLightMap, tc).rgb*kern[i].x;
				defined_weight += kern[i].x;
			}
		}
	}

	col /= defined_weight;
	
	//col = ccol;
	
	col = col*col*blur_quad.x + col*blur_quad.y + blur_quad.z;
	
91
	frag_color.rgb = col;
92
93
94
95
96
97

#ifdef IS_AMD_CARD
	// If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts.
	vec2 dummy1 = kern[0];
	vec2 dummy2 = kern[31];
#endif
98
}