shaderSimpleFlat.frag 831 Bytes
Newer Older
1 2
//ShaderSimpleFlat::fragmentShaderText

kvanhoey's avatar
kvanhoey committed
3
PRECISION;
4
VARYING_FRAG vec3 LightDir;
5
VARYING_FRAG vec3 Position;
6 7 8 9 10 11 12
#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
13
uniform vec4 backColor;
14
uniform bool doubleSided;
Sylvain Thery's avatar
Sylvain Thery committed
15

16
FRAG_OUT_DEF;
17

18 19 20 21 22 23 24 25 26
void main()
{
	vec3 DX = dFdx(Position);
	vec3 DY = dFdy(Position);
	vec3 N=normalize(cross(DX,DY));

	vec3 L = normalize (LightDir);

	vec4 finalColor = materialAmbient;
27 28 29
	float lambertTerm = clamp(dot(N,L),0.0,1.0);

	vec4 currentColor = materialDiffuse;
30 31 32

	if (!gl_FrontFacing)
	{
33 34 35
		if (!doubleSided)
			discard;
		currentColor = backColor;
36
	}
37

38
#ifndef WITH_COLOR
39
	finalColor += currentColor * lambertTerm;
40
#else
41
	finalColor += vec4((Color*lambertTerm),0.0) ;
42
#endif
43
	FRAG_OUT=finalColor;
44
}