summaryrefslogtreecommitdiff
path: root/example/fragmentshader.glsl
blob: 70c55b5a4c3a12dc91a44e5c361445f3023d5d38 (plain)
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
#version 130
out vec4 outpix;
uniform vec3 campos;
uniform vec3 lightpos;
//varing blends them it is transformed to world space
varying vec4 fragpos;
varying vec4 fragnormal;
void main() 
{
	vec3 lightnormal = normalize((lightpos - vec3(fragpos.x, fragpos.y, fragpos.z)));
	float diffuse = dot(lightnormal, vec3(fragnormal.x, fragnormal.y, fragnormal.z));
	if (diffuse < 0.0) {
		diffuse = 0.0;
	}
	vec3 camnormal = normalize(campos - vec3(fragpos.x, fragpos.y, fragpos.z));
	float reflect = dot(camnormal, fragnormal.xyz);
	diffuse = pow(diffuse, 2.0);
	reflect = pow(reflect, 2.0);
	float light = .4 * reflect + .6 * diffuse;
	//this should be the vertex in camera space without the w value
	//outpix = gl_FragCoord;
	outpix = vec4(light * 1.0,light *  1.0,light * 1.0, 1.0);
	//outpix = vec4(fragpos.x ,fragpos.y ,fragpos.z, 0.5);
	//outpix = vec4(fragnormal.x, fragnormal.y, fragnormal.z, 0.5);
}