diff options
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 16 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 17 |
2 files changed, 20 insertions, 13 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 5594c085974..5ed47cda8f5 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -765,20 +765,18 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la } if (lamp->mode & LA_ONLYSHADOW) { - GPUNodeLink *rgb; + GPUNodeLink *shadrgb; GPU_link(mat, "shade_only_shadow", i, shadfac, - GPU_dynamic_uniform(&lamp->dynenergy, GPU_DYNAMIC_LAMP_DYNENERGY, lamp->ob), &shadfac); - - GPU_link(mat, "shade_mul", shi->rgb, GPU_uniform(lamp->shadow_color), &rgb); - GPU_link(mat, "mtex_rgb_invert", rgb, &rgb); + GPU_dynamic_uniform(&lamp->dynenergy, GPU_DYNAMIC_LAMP_DYNENERGY, lamp->ob), + GPU_uniform(lamp->shadow_color), &shadrgb); if (!(lamp->mode & LA_NO_DIFF)) { - GPU_link(mat, "shade_only_shadow_diffuse", shadfac, rgb, + GPU_link(mat, "shade_only_shadow_diffuse", shadrgb, shi->rgb, shr->diff, &shr->diff); } if (!(lamp->mode & LA_NO_SPEC)) - GPU_link(mat, "shade_only_shadow_specular", shadfac, shi->specrgb, + GPU_link(mat, "shade_only_shadow_specular", shadrgb, shi->specrgb, shr->spec, &shr->spec); add_user_list(&mat->lamps, lamp); @@ -890,6 +888,10 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr) free_object_duplilist(lb); } } + + /* prevent only shadow lamps from producing negative colors.*/ + GPU_link(shi->gpumat, "shade_clamp_positive", shr->spec, &shr->spec); + GPU_link(shi->gpumat, "shade_clamp_positive", shr->diff, &shr->diff); } static void texture_rgb_blend(GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg, int blendtype, GPUNodeLink **in) diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index a224f8e979a..44119d4a913 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -1921,19 +1921,24 @@ void ramp_rgbtobw(vec3 color, out float outval) outval = color.r*0.3 + color.g*0.58 + color.b*0.12; } -void shade_only_shadow(float i, float shadfac, float energy, out float outshadfac) +void shade_only_shadow(float i, float shadfac, float energy, vec3 shadcol, out vec3 outshadrgb) { - outshadfac = i*energy*(1.0 - shadfac); + outshadrgb = i*energy*(1.0 - shadfac)*(vec3(1.0)-shadcol); } -void shade_only_shadow_diffuse(float shadfac, vec3 rgb, vec4 diff, out vec4 outdiff) +void shade_only_shadow_diffuse(vec3 shadrgb, vec3 rgb, vec4 diff, out vec4 outdiff) { - outdiff = diff - vec4(rgb*shadfac, 0.0); + outdiff = diff - vec4(rgb*shadrgb, 0.0); } -void shade_only_shadow_specular(float shadfac, vec3 specrgb, vec4 spec, out vec4 outspec) +void shade_only_shadow_specular(vec3 shadrgb, vec3 specrgb, vec4 spec, out vec4 outspec) { - outspec = spec - vec4(specrgb*shadfac, 0.0); + outspec = spec - vec4(specrgb*shadrgb, 0.0); +} + +void shade_clamp_positive(vec4 col, out vec4 outcol) +{ + outcol = max(col, vec4(0.0)); } void test_shadowbuf(vec3 rco, sampler2DShadow shadowmap, mat4 shadowpersmat, float shadowbias, float inp, out float result) |