annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
1 varying vec3 snormal;
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
2 varying vec3 svertex;
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
3 uniform int nlights;
65
71f6c5cc8eec Add 'ftime' uniform for shaders, which is time in milliseconds from start of rendering loop.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
4 uniform float ftime;
28
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
5
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
6
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
7 float maxdot(vec3 sveca, vec3 svecb)
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
8 {
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
9 return max(dot(sveca, svecb), 0.0);
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
10 }
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
11
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
12
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
13 vec4 mclamp(vec4 svec)
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
14 {
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
15 return clamp(svec, 0.0, 1.0);
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
16 }
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
17
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
18
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
19 void main(void)
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
28
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
21 vec3 snormal = normalize(snormal);
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
22 vec3 srcVec = normalize(-svertex);
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
23 //vec4 poo = vec4(0.0, 0.0, 0.0, 0.0);
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
24 vec4 poo = gl_FragCoord;
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
25 //poo += vec4(snormal.x, snormal.y, snormal.z, 0.0);
65
71f6c5cc8eec Add 'ftime' uniform for shaders, which is time in milliseconds from start of rendering loop.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
26 vec4 finalColor = vec4(poo.x * 0.1, poo.y * 0.001, poo.z + sin(ftime * 0.001), 1.0);
28
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
27
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
28 for (int i = 0; i < nlights; i++)
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
29 {
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
30 vec3 lightVec = normalize(gl_LightSource[i].position.xyz - svertex);
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
31 vec3 refVec = normalize(-reflect(lightVec, snormal));
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
28
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
33 vec4 ambient = gl_FrontLightProduct[i].ambient;
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
34 vec4 diffuse = mclamp(gl_FrontLightProduct[i].diffuse * maxdot(snormal, lightVec));
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
35 vec4 specular = mclamp(
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
36 gl_FrontLightProduct[i].specular *
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
37 pow(maxdot(refVec, srcVec), gl_FrontMaterial.shininess));
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
38
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
39 finalColor += ambient + diffuse + specular;
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
40 }
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
41
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
42 gl_FragColor = gl_FrontLightModelProduct.sceneColor + finalColor;
d2839cbfaad8 Some work on the default shaders.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
43 }