view shader.frag @ 107:2b30217a3c39 default tip

Fix verbose build echos.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 29 Feb 2024 21:48:47 +0200
parents 71f6c5cc8eec
children
line wrap: on
line source

varying vec3 snormal;
varying vec3 svertex;
uniform int nlights;
uniform float ftime;


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 + sin(ftime * 0.001), 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;
}