Mercurial > hg > forks > gldragon
comparison shader.frag @ 28:d2839cbfaad8
Some work on the default shaders.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Nov 2019 08:39:48 +0200 |
parents | 1404dfcee7b8 |
children | 71f6c5cc8eec |
comparison
equal
deleted
inserted
replaced
27:097184bd34a8 | 28:d2839cbfaad8 |
---|---|
1 void main() | 1 varying vec3 snormal; |
2 varying vec3 svertex; | |
3 uniform int nlights; | |
4 | |
5 | |
6 float maxdot(vec3 sveca, vec3 svecb) | |
2 { | 7 { |
3 gl_FragColor = vec4( | 8 return max(dot(sveca, svecb), 0.0); |
4 gl_FragCoord.x * 0.1, | 9 } |
5 gl_FragCoord.y * 0.001, | |
6 0.0, | |
7 1.0); | |
8 }; | |
9 | 10 |
11 | |
12 vec4 mclamp(vec4 svec) | |
13 { | |
14 return clamp(svec, 0.0, 1.0); | |
15 } | |
16 | |
17 | |
18 void main(void) | |
19 { | |
20 vec3 snormal = normalize(snormal); | |
21 vec3 srcVec = normalize(-svertex); | |
22 //vec4 poo = vec4(0.0, 0.0, 0.0, 0.0); | |
23 vec4 poo = gl_FragCoord; | |
24 //poo += vec4(snormal.x, snormal.y, snormal.z, 0.0); | |
25 vec4 finalColor = vec4(poo.x * 0.1, poo.y * 0.001, poo.z, 1.0); | |
26 | |
27 for (int i = 0; i < nlights; i++) | |
28 { | |
29 vec3 lightVec = normalize(gl_LightSource[i].position.xyz - svertex); | |
30 vec3 refVec = normalize(-reflect(lightVec, snormal)); | |
31 | |
32 vec4 ambient = gl_FrontLightProduct[i].ambient; | |
33 vec4 diffuse = mclamp(gl_FrontLightProduct[i].diffuse * maxdot(snormal, lightVec)); | |
34 vec4 specular = mclamp( | |
35 gl_FrontLightProduct[i].specular * | |
36 pow(maxdot(refVec, srcVec), gl_FrontMaterial.shininess)); | |
37 | |
38 finalColor += ambient + diffuse + specular; | |
39 } | |
40 | |
41 gl_FragColor = gl_FrontLightModelProduct.sceneColor + finalColor; | |
42 } |