diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-02-07 16:45:39 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-02-07 16:45:39 +0300 |
commit | 72dd1ba3fe67206680ef3540b681d944e8bb4872 (patch) | |
tree | 6e4a2fe9be3ee265422faf1ce49c3155b64b62cf /source | |
parent | bd0223b8fefe1bf21f9cd2b444256775b5540227 (diff) |
Fix T47349: incorrect Cycles fresnel and layer weight with GLSL materials.
Patch by Ralf Hölzemer.
Diffstat (limited to 'source')
3 files changed, 9 insertions, 7 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 51d4706d91e..3682f7e0625 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2413,27 +2413,29 @@ void node_add_shader(vec4 shader1, vec4 shader2, out vec4 shader) /* fresnel */ -void node_fresnel(float ior, vec3 N, vec3 I, out float result) +void node_fresnel(float ior, vec3 N, vec3 I, mat4 toworld, out float result) { /* handle perspective/orthographic */ vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0)? normalize(I): vec3(0.0, 0.0, -1.0); + vec3 normal = (toworld*vec4(N, 0.0)).xyz; float eta = max(ior, 0.00001); - result = fresnel_dielectric(I_view, N, (gl_FrontFacing)? eta: 1.0/eta); + result = fresnel_dielectric(I_view, normal, (gl_FrontFacing)? eta: 1.0/eta); } /* layer_weight */ -void node_layer_weight(float blend, vec3 N, vec3 I, out float fresnel, out float facing) +void node_layer_weight(float blend, vec3 N, vec3 I, mat4 toworld, out float fresnel, out float facing) { /* fresnel */ float eta = max(1.0 - blend, 0.00001); vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0)? normalize(I): vec3(0.0, 0.0, -1.0); + vec3 normal = (toworld*vec4(N, 0.0)).xyz; - fresnel = fresnel_dielectric(I_view, N, (gl_FrontFacing)? 1.0/eta : eta ); + fresnel = fresnel_dielectric(I_view, normal, (gl_FrontFacing)? 1.0/eta : eta ); /* facing */ - facing = abs(dot(I_view, N)); + facing = abs(dot(I_view, normal)); if(blend != 0.5) { blend = clamp(blend, 0.0, 0.99999); blend = (blend < 0.5)? 2.0*blend: 0.5/(1.0 - blend); diff --git a/source/blender/nodes/shader/nodes/node_shader_fresnel.c b/source/blender/nodes/shader/nodes/node_shader_fresnel.c index 59d798dc80c..9d6efb0af53 100644 --- a/source/blender/nodes/shader/nodes/node_shader_fresnel.c +++ b/source/blender/nodes/shader/nodes/node_shader_fresnel.c @@ -44,7 +44,7 @@ static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeE if (!in[1].link) in[1].link = GPU_builtin(GPU_VIEW_NORMAL); - return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION)); + return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_MATRIX)); } /* node type definition */ diff --git a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c index 832ce582b4b..78f22224070 100644 --- a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c +++ b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c @@ -46,7 +46,7 @@ static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *UNUSED(node), b if (!in[1].link) in[1].link = GPU_builtin(GPU_VIEW_NORMAL); - return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION)); + return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_MATRIX)); } /* node type definition */ |