Mercurial > hg > forks > gldragon
view shader.frag @ 37:73a785323e8a
Rendering cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 01 Dec 2019 23:52:19 +0200 |
parents | d2839cbfaad8 |
children | 71f6c5cc8eec |
line wrap: on
line source
varying vec3 snormal; varying vec3 svertex; uniform int nlights; float maxdot(vec3 sveca, vec3 svecb) { return max(dot(sveca, svecb), 0.0); } vec4 mclamp(vec4 svec) { return clamp(svec, 0.0, 1.0); } void main(void) { vec3 snormal = normalize(snormal); vec3 srcVec = normalize(-svertex); //vec4 poo = vec4(0.0, 0.0, 0.0, 0.0); vec4 poo = gl_FragCoord; //poo += vec4(snormal.x, snormal.y, snormal.z, 0.0); vec4 finalColor = vec4(poo.x * 0.1, poo.y * 0.001, poo.z, 1.0); for (int i = 0; i < nlights; i++) { vec3 lightVec = normalize(gl_LightSource[i].position.xyz - svertex); vec3 refVec = normalize(-reflect(lightVec, snormal)); vec4 ambient = gl_FrontLightProduct[i].ambient; vec4 diffuse = mclamp(gl_FrontLightProduct[i].diffuse * maxdot(snormal, lightVec)); vec4 specular = mclamp( gl_FrontLightProduct[i].specular * pow(maxdot(refVec, srcVec), gl_FrontMaterial.shininess)); finalColor += ambient + diffuse + specular; } gl_FragColor = gl_FrontLightModelProduct.sceneColor + finalColor; }