Page MenuHome

Material viewport shading receives light from light sources on other layers when they have a texture assigned
Closed, ResolvedPublic


System Information
MacBook Pro Retina, Mid 2012

Blender Version
Broken: 2.72 RC

Exact steps for others to reproduce the error
Open the file and you will see that light source is on layer 1 and object is on layer 2. Only layer 2 is active so the light source shouldn't influence the viewport, but it does. This happens only when light source has a texture assigned.

Event Timeline

Andrej Ivanis (aivanis) updated the task description. (Show Details)
Andrej Ivanis (aivanis) raised the priority of this task from to Needs Triage by Developer.
Andrej Ivanis (aivanis) set Type to Bug.
Bastien Montagne (mont29) triaged this task as Normal priority.

This simple patch fixes it:

1diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
2index 81dcd9c..c613040 100644
3--- a/source/blender/gpu/intern/gpu_material.c
4+++ b/source/blender/gpu/intern/gpu_material.c
5@@ -677,7 +677,9 @@ static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **
6 GPU_image(mtex->tex->ima, &mtex->tex->iuser, false),
7 GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
8 &tex_rgb);
9- texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb);
10+ texture_rgb_blend(mat, tex_rgb, *rgb,
11+ GPU_dynamic_uniform((float*)&lamp->dynenergy, GPU_DYNAMIC_LAMP_DYNENERGY, lamp->ob),
12+ GPU_uniform(&mtex->colfac), mtex->blendtype, rgb);
13 }
14 }
15 }

Not really at ease with OGL, though, so Sergey or Antony, need your blessing here. :)

This is not so good, colors are already multiplied by the energy (lamp->dyncol is calculated form lamp->col which is premultiplied by the energy), so if we do that, we will get the multiplication twice. Solution is to do the multiplication after texture application in the shader.