From f0f35687d652640c0bd202b100478d27d3b43f6b Mon Sep 17 00:00:00 2001 From: ffreyer Date: Sat, 10 Apr 2021 20:26:47 +0200 Subject: [PATCH] fix light calc with backlight --- assets/shader/standard.frag | 2 +- src/GLVisualize/visualize/surface.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/shader/standard.frag b/assets/shader/standard.frag index 83a9ab00..c37d03e4 100644 --- a/assets/shader/standard.frag +++ b/assets/shader/standard.frag @@ -75,9 +75,9 @@ vec3 blinnphong(vec3 N, vec3 V, vec3 L, vec3 color){ float spec_coeff = pow(max(dot(H, N), 0.0), shininess); if (diff_coeff <= 0.0 || isnan(spec_coeff)) spec_coeff = 0.0; + // final lighting model return vec3( - ambient * color + diffuse * diff_coeff * color + specular * spec_coeff ); diff --git a/src/GLVisualize/visualize/surface.jl b/src/GLVisualize/visualize/surface.jl index 22a0c506..456af4cd 100644 --- a/src/GLVisualize/visualize/surface.jl +++ b/src/GLVisualize/visualize/surface.jl @@ -64,8 +64,8 @@ function light_calc(x::Bool) vec3 L = normalize(o_lightdir); vec3 N = normalize(o_normal); vec3 light1 = blinnphong(N, o_camdir, L, color.rgb); - color = vec4(light1, color.a) + - backlight * vec4(blinnphong(N, o_camdir, -L, color.rgb), color.a); + vec3 light2 = blinnphong(N, o_camdir, -L, color.rgb); + color = vec4(ambient * color.rgb + light1 + backlight * light2, color.a); """ else ""