diff options
author | Phil Gosch <phil@saphirestudio.at> | 2017-09-27 14:29:26 +0300 |
---|---|---|
committer | Phil Gosch <phil@saphirestudio.at> | 2017-09-27 14:29:26 +0300 |
commit | 5cdd4388ffaad5ade916dba3c18e2bc679e19747 (patch) | |
tree | 1f97d9db29a22d6b75d9b6debe42f400eaf2296c /source/blender/gpu/shaders/gpu_shader_material.glsl | |
parent | 99c3d1106e3ff73e2111781d8e38307b2164d57c (diff) | |
parent | 0f793ee6060301ad97e8c4c1ffe8f0913fc990ea (diff) |
Merge remote-tracking branch 'origin/master' into soc-2016-uv_tools
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_material.glsl')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index ef2060122e0..f14db57a26a 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2625,7 +2625,7 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad { /* ambient light */ // TODO: set ambient light to an appropriate value - vec3 L = vec3(mix(0.1, 0.03, metallic)) * base_color.rgb; + vec3 L = mix(0.1, 0.03, metallic) * mix(base_color.rgb, subsurface_color.rgb, subsurface * (1.0 - metallic)); float eta = (2.0 / (1.0 - sqrt(0.08 * specular))) - 1.0; @@ -2636,14 +2636,11 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad vec3 Tangent = T; if (T == vec3(0.0)) { // if no tangent is set, use a default tangent - Tangent = vec3(1.0, 0.0, 0.0); - if (N.x != 0.0 || N.y != 0.0) { - vec3 N_xz = normalize(vec3(N.x, 0.0, N.z)); - - vec3 axis = normalize(cross(vec3(0.0, 0.0, 1.0), N_xz)); - float angle = acos(dot(vec3(0.0, 0.0, 1.0), N_xz)); - - Tangent = normalize(rotate_vector(vec3(1.0, 0.0, 0.0), axis, angle)); + if(N.x != N.y || N.x != N.z) { + Tangent = vec3(N.z-N.y, N.x-N.z, N.y-N.x); // (1,1,1) x N + } + else { + Tangent = vec3(N.z-N.y, N.x+N.z, -N.y-N.x); // (-1,1,1) x N } } @@ -2663,10 +2660,11 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad /* directional lights */ for (int i = 0; i < NUM_LIGHTS; i++) { vec3 light_position_world = gl_LightSource[i].position.xyz; - vec3 light_position = normalize(gl_NormalMatrix * light_position_world); + vec3 light_position = normalize(light_position_world); vec3 H = normalize(light_position + V); + vec3 light_diffuse = gl_LightSource[i].diffuse.rgb; vec3 light_specular = gl_LightSource[i].specular.rgb; float NdotL = dot(N, light_position); @@ -2711,8 +2709,9 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad // sheen vec3 Fsheen = schlick_fresnel(LdotH) * sheen * Csheen; - diffuse_and_specular_bsdf = (M_1_PI * mix(Fd, ss, subsurface) * base_color.rgb + Fsheen) - * (1.0 - metallic) + Gs * Fs * Ds; + vec3 diffuse_bsdf = (mix(Fd * base_color.rgb, ss * subsurface_color.rgb, subsurface) + Fsheen) * light_diffuse; + vec3 specular_bsdf = Gs * Fs * Ds * light_specular; + diffuse_and_specular_bsdf = diffuse_bsdf * (1.0 - metallic) + specular_bsdf; } diffuse_and_specular_bsdf *= max(NdotL, 0.0); @@ -2729,11 +2728,11 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad float Fr = fresnel_dielectric_cos(LdotH, 1.5); //mix(0.04, 1.0, FH); float Gr = smithG_GGX(CNdotL, 0.25) * smithG_GGX(CNdotV, 0.25); - clearcoat_bsdf = clearcoat * Gr * Fr * Dr * vec3(0.25); + clearcoat_bsdf = clearcoat * Gr * Fr * Dr * vec3(0.25) * light_specular; } clearcoat_bsdf *= max(CNdotL, 0.0); - L += light_specular * (diffuse_and_specular_bsdf + clearcoat_bsdf); + L += diffuse_and_specular_bsdf + clearcoat_bsdf; } result = vec4(L, 1.0); |