Merge branch 'master' into blender2.8
[blender.git] / source / blender / gpu / shaders / gpu_shader_basic_frag.glsl
index e1cd7e0684c91d19a91bf44e9b738fe619f2b1a0..ad4182340d63153d744880cc4269be7ad5148cdc 100644 (file)
 #define STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP        11
 
 #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
+#if defined(USE_FLAT_NORMAL)
+varying vec3 eyespace_vert_pos;
+#else
 varying vec3 varying_normal;
-
+#endif
 #ifndef USE_SOLID_LIGHTING
 varying vec3 varying_position;
 #endif
@@ -88,7 +91,7 @@ void main()
                        discard;
        }
        else if (stipple_id == STIPPLE_CHECKER_8PX) {
-               int result = int(mod(int(gl_FragCoord.x)/8 + int(gl_FragCoord.y) / 8, 2));
+               int result = int(mod(int(gl_FragCoord.x) / 8 + int(gl_FragCoord.y) / 8, 2));
                if (result != 0)
                        discard;
        }
@@ -137,7 +140,11 @@ void main()
 
 #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
        /* compute normal */
+#if defined(USE_FLAT_NORMAL)
+       vec3 N = normalize(cross(dFdx(eyespace_vert_pos), dFdy(eyespace_vert_pos)));
+#else
        vec3 N = normalize(varying_normal);
+#endif
 
 #ifdef USE_TWO_SIDED
        if (!gl_FrontFacing)
@@ -158,7 +165,7 @@ void main()
                /* diffuse light */
                vec3 light_diffuse = gl_LightSource[i].diffuse.rgb;
                float diffuse_bsdf = max(dot(N, light_direction), 0.0);
-               L_diffuse += light_diffuse*diffuse_bsdf;
+               L_diffuse += light_diffuse * diffuse_bsdf;
 
 #ifndef NO_SPECULAR
                /* specular light */
@@ -166,7 +173,7 @@ void main()
                vec3 H = gl_LightSource[i].halfVector.xyz;
 
                float specular_bsdf = pow(max(dot(N, H), 0.0), gl_FrontMaterial.shininess);
-               L_specular += light_specular*specular_bsdf;
+               L_specular += light_specular * specular_bsdf;
 #endif
        }
 #else
@@ -174,7 +181,7 @@ void main()
 
 #ifndef NO_SPECULAR
        /* view vector computation, depends on orthographics or perspective */
-       vec3 V = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position): vec3(0.0, 0.0, -1.0);
+       vec3 V = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position) : vec3(0.0, 0.0, -1.0);
 #endif
 
        for (int i = 0; i < NUM_SCENE_LIGHTS; i++) {
@@ -205,14 +212,14 @@ void main()
                        float distance = length(d);
 
                        intensity /= gl_LightSource[i].constantAttenuation +
-                               gl_LightSource[i].linearAttenuation * distance +
-                               gl_LightSource[i].quadraticAttenuation * distance * distance;
+                                    gl_LightSource[i].linearAttenuation * distance +
+                                    gl_LightSource[i].quadraticAttenuation * distance * distance;
                }
 
                /* diffuse light */
                vec3 light_diffuse = gl_LightSource[i].diffuse.rgb;
                float diffuse_bsdf = max(dot(N, light_direction), 0.0);
-               L_diffuse += light_diffuse*diffuse_bsdf*intensity;
+               L_diffuse += light_diffuse * diffuse_bsdf * intensity;
 
 #ifndef NO_SPECULAR
                /* specular light */
@@ -220,7 +227,7 @@ void main()
                vec3 H = normalize(light_direction - V);
 
                float specular_bsdf = pow(max(dot(N, H), 0.0), gl_FrontMaterial.shininess);
-               L_specular += light_specular*specular_bsdf*intensity;
+               L_specular += light_specular * specular_bsdf * intensity;
 #endif
        }
 #endif
@@ -250,7 +257,7 @@ void main()
        vec3 L = gl_FrontLightModelProduct.sceneColor.rgb + L_diffuse;
 
 #ifndef NO_SPECULAR
-       L += L_specular*gl_FrontMaterial.specular.rgb;
+       L += L_specular * gl_FrontMaterial.specular.rgb;
 #endif
 
        /* write out fragment color */