File: planeEnvironmentMapping.frag

package info (click to toggle)
sofa-framework 1.0~beta4-11
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 88,820 kB
  • ctags: 27,300
  • sloc: cpp: 151,126; ansic: 2,387; xml: 581; sh: 417; makefile: 68
file content (75 lines) | stat: -rw-r--r-- 2,172 bytes parent folder | download | duplicates (5)
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
varying vec3 normalVec;
varying vec3 viewVec;

uniform sampler2D planeTexture;
uniform float altitude;
uniform int axis; //0 = +X, 1 = +Y, 2 = +Z, 3 = -X, 4 = -Y, 5 = -Z
uniform float border_gamma, border_alpha;

varying vec4 diffuse, ambient, specular;
varying vec3 lightDir /* , halfVector */ , normalView;
//varying float dist;


vec3 reflect(vec3 I, vec3 N)
{
  return I - 2.0 * N * dot(N, I);
}

void main()
{
	float reflect_factor = 1.0;
	
	//Phong
	vec3 n,halfV;
	float NdotL,NdotHV;
	vec4 color = ambient;
	//float att,spotEffect;
	
	/* a fragment shader can't write a verying variable, hence we need
	a new variable to store the normalized interpolated normal */
	n = normalize(normalView);
	
	/* compute the dot product between normal and ldir */
	NdotL = max(dot(n,normalize(lightDir)),0.0);

	if (NdotL > 0.0) {
	
		/*spotEffect = dot(normalize(gl_LightSource[0].spotDirection), normalize(-lightDir));
		if (spotEffect > gl_LightSource[0].spotCosCutoff) {
			spotEffect = pow(spotEffect, gl_LightSource[0].spotExponent);
			att = spotEffect / (gl_LightSource[0].constantAttenuation +
					gl_LightSource[0].linearAttenuation * dist +
					gl_LightSource[0].quadraticAttenuation * dist * dist);*/
				
			color += /*att * */ (diffuse * NdotL) ;
			
		//}
	}
	
	//end phong
	//color = gl_Color;
	
	// Perform a simple 2D texture look up.
	//vec3 base_color = gl_Color.xyz;//texture2D(planeTexture, reflectVec.xz).rgb;

	vec3 unitNormalVec = normalize(normalVec);
	vec3 unitViewVec = normalize(viewVec);
	color.a = color.a + (border_alpha - color.a)* (pow( 1.0 - abs(dot(unitNormalVec,unitViewVec)), border_gamma));

	color.rgb *= color.a;

	vec3 reflectVec = reflect(viewVec, normalVec);
	
	if (reflectVec.z>0.0)
	{
		// Perform a cube map look up.
	  color.rgb += texture2D(planeTexture, reflectVec.xy*( altitude/reflectVec.z )+vec2(0.5,0.5)).rgb * specular.rgb;

	}

	// Write the final pixel.
	//gl_FragColor = vec4((color.xyz*alpha_color2)+cube_color,alpha_color2); //vec4( mix(base_color, cube_color, reflect_factor), 1.0);
	gl_FragColor = color; //vec4((color.xyz*color.w)+cube_color,color.w); //vec4( mix(base_color, cube_color, reflect_factor), 1.0);

}