Using rgbGen lightingDiffuse on a shader stage for a shader that is used in a level results in either a totally black surface or a surface that is supposedly lit by diffuse lighting.
I tested this on a map I made that featured a func_rotating entity made up of brushes. I didn't want to use lightmaps on it, as it would look strange in-game. I also didn't want to approximate the light as that never turns out right either. So, I tried rgbGen lightingDiffuse on the shaders for the func_rotating, and it worked, somewhat. Sometimes it appeared to work, other times it would turn completely black at random and stay that way for several seconds.
If this were fixed we could have dynamic lighting on things such as func_door and func_rotating, instead of having to approximate light or have static lightmaps on them(which always look strange in motion).
You should get consistent diffuse lighting when you call
R_SetupEntityLighting( &tr.refdef, ent );
before R_DlightBmodel(...) in R_AddBrushModelSurfaces, but the renderer will only use a single light intensity and direction for the whole model, so it is best not used on large models.
Created attachment 2587[details]
Test map with rotating diffuse-lit cube in the center.
Attached a test map. It is a box map with a rotating cube in the center. The rotating cube has a shader with rgbGen lightingDiffuse on all sides. There are four lights in the map, one at each corner.
At first, the cube will probably be black. Shooting or moving around should make it grab a color from somewhere, but it will stay that color until something else happens. This is the bug as described.
Created attachment 2606[details]
diffuselight.diff
This patch fixes the diffuse entitiy lighting, but in your test map you will see only the ambient light, because the engine can only use the light at the model origin for the whole model, and as the model is exactly in the center of the lights, the directional light component is zero...
Created attachment 2608[details]
New version of the test map.
Well, that patch works. The cube now properly receives dynlights, like when shooting, etc.
I made a new version of the test map with all but 1 light removed. Please test this version with this patch. The cube looks evenly lit across all sides(still not affected by the light except for ambient).
The center of the cube is still pitch black in the light grid, so there is no directional light :(
This means that either the light radius is too small or that there is no light inside of the cube because the cube blocks the light ! Do you know if it's possible to exclude a model from the light stage of q3map2 (or turn it transparent) by some shader tricks ?
(In reply to comment #7)
> The center of the cube is still pitch black in the light grid, so there is no
> directional light :(
>
> This means that either the light radius is too small or that there is no light
> inside of the cube because the cube blocks the light ! Do you know if it's
> possible to exclude a model from the light stage of q3map2 (or turn it
> transparent) by some shader tricks ?
Well, I increased the light value with no change in the cube's behavior. The lightgrid is actually acting quite strange. If you move to different parts of the room, you get colors like red, purple, and green.
I used the following for q3map2:
q3map2 -bsp -meta
q3map2 -vis
q3map2 -light -fast
Your patch definitely is an improvement and seems to be correct. I've applied it in r1933. If there's anything else that needs fixing in this respect, just reopen this bug.
Created attachment 2587 [details] Test map with rotating diffuse-lit cube in the center. Attached a test map. It is a box map with a rotating cube in the center. The rotating cube has a shader with rgbGen lightingDiffuse on all sides. There are four lights in the map, one at each corner. At first, the cube will probably be black. Shooting or moving around should make it grab a color from somewhere, but it will stay that color until something else happens. This is the bug as described.
Created attachment 2606 [details] diffuselight.diff This patch fixes the diffuse entitiy lighting, but in your test map you will see only the ambient light, because the engine can only use the light at the model origin for the whole model, and as the model is exactly in the center of the lights, the directional light component is zero...
Created attachment 2608 [details] New version of the test map. Well, that patch works. The cube now properly receives dynlights, like when shooting, etc. I made a new version of the test map with all but 1 light removed. Please test this version with this patch. The cube looks evenly lit across all sides(still not affected by the light except for ambient).