@@ -71,13 +71,13 @@ version => <<'EOF',
7171EOF
7272light => <<'EOF' ,
7373/* modified from https://community.khronos.org/t/help-with-gouraud-phong-shading-in-shaders/73192/2 */
74- void light(int lightIndex, vec4 position, vec3 norm, out vec4 diffuse, out vec4 spec) {
74+ void light(int lightIndex, vec4 position, vec3 norm, vec4 in_diffuse, out vec4 diffuse, out vec4 spec) {
7575 vec3 n = normalize(norm);
7676 vec3 s = vec3(normalize(gl_LightSource[lightIndex].position - position));
7777 vec4 v = normalize(-position);
7878 vec4 r = vec4(reflect(-s, n), 1);
7979 float sDotN = max(dot(s, n), 0.0);
80- diffuse = gl_LightSource[lightIndex].diffuse * gl_FrontMaterial.diffuse * sDotN;
80+ diffuse = gl_LightSource[lightIndex].diffuse * in_diffuse * sDotN;
8181 spec = gl_LightSource[lightIndex].specular * gl_FrontMaterial.specular * pow(max(dot(r,v), 0.0), gl_FrontMaterial.shininess);
8282}
8383EOF
@@ -101,9 +101,12 @@ fs_in_light_decl => <<'EOF',
101101varying vec3 vNormal;
102102varying vec4 vPosition;
103103EOF
104+ fs_diffuse_material => <<'EOF' ,
105+ vec4 in_diffuse = gl_FrontMaterial.diffuse;
106+ EOF
104107fs_out_light => <<'EOF' ,
105108 vec4 diffuse, spec;
106- light(0, vPosition, gl_FrontFacing ? vNormal : -vNormal, diffuse, spec);
109+ light(0, vPosition, gl_FrontFacing ? vNormal : -vNormal, in_diffuse, diffuse, spec);
107110 gl_FragColor = gl_FrontLightProduct[0].ambient + diffuse + spec;
108111EOF
109112);
@@ -447,10 +450,10 @@ void main() {
447450%s%s
448451}
449452EOF
450- my $fragment_shader = sprintf <<'EOF' , @SHADERBITS {qw( version fs_in_light_decl light fs_out_light) };
453+ my $fragment_shader = sprintf <<'EOF' , @SHADERBITS {qw( version fs_in_light_decl light fs_diffuse_material fs_out_light) };
451454%s%s%s
452455void main() {
453- %s
456+ %s%s
454457}
455458EOF
456459my %SPHERE ;
0 commit comments