shaderPhong.frag 1.36 KB
Newer Older
1
2
//ShaderPhong::fragmentShaderText

kvanhoey's avatar
kvanhoey committed
3
PRECISION;
4
5
6
7
8
9
10
11
VARYING_FRAG vec3 EyeVector, Normal, LightDir;
#ifdef WITH_COLOR
VARYING_FRAG vec3 Color;
#endif
uniform vec4 materialDiffuse;
uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
Sylvain Thery's avatar
Sylvain Thery committed
12
13
uniform vec4 backColor;

14
15
16
17
18
FRAG_OUT_DEF;
void main()
{
	vec3 N = normalize (Normal);
	vec3 L = normalize (LightDir);
Sylvain Thery's avatar
Sylvain Thery committed
19
	//float lambertTerm = clamp(dot(N,L),0.0,1.0);
20
21

	vec4 finalColor = materialAmbient;
Sylvain Thery's avatar
Sylvain Thery committed
22
23
24
25
26

#ifdef DOUBLE_SIDED
	float lambertTerm;
	vec4 diffuseColor = materialDiffuse;
	if (!gl_FrontFacing)
27
	{
Sylvain Thery's avatar
Sylvain Thery committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
		N *= -1.0;
		lambertTerm = clamp(dot(N,L),0.0,1.0);
	}
	else
		lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
	finalColor += materialDiffuse * lambertTerm;
#else
	finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
	vec3 E = normalize(EyeVector);
	vec3 R = reflect(-L, N);
	float specular = pow( max(dot(R, E), 0.0), shininess );
	finalColor += materialSpecular * specular;
#else
	float lambertTerm = clamp(dot(N,L),0.0,1.0);
	if (gl_FrontFacing)
45
	{
Sylvain Thery's avatar
Sylvain Thery committed
46
#ifndef WITH_COLOR
47
		finalColor += materialDiffuse * lambertTerm;
Sylvain Thery's avatar
Sylvain Thery committed
48
#else
49
		finalColor += vec4((Color*lambertTerm),0.0) ;
Sylvain Thery's avatar
Sylvain Thery committed
50
#endif
51
52
53
54
55
		vec3 E = normalize(EyeVector);
		vec3 R = reflect(-L, N);
		float specular = pow( max(dot(R, E), 0.0), shininess );
		finalColor += materialSpecular * specular;
	}
Sylvain Thery's avatar
Sylvain Thery committed
56
57
58
59
	else
	{
		finalColor = backColor;
	}
Sylvain Thery's avatar
Sylvain Thery committed
60
#endif
61
	FRAG_OUT=finalColor;
62
}