Bug 4421 - rgbGen lightingDiffuse doesn't work correctly on world surfaces
Status: RESOLVED FIXED
Alias: None
Product: ioquake3
Classification: Unclassified
Component: Video
Version: unspecified
Hardware: All All
: P3 normal
Assignee: Zachary J. Slater
QA Contact: ioquake3 bugzilla mailing list
URL:
Depends on:
Blocks:
 
Reported: 2009-12-21 18:41 EST by Evan Goers
Modified: 2011-03-14 13:28:20 EDT
3 users (show)

See Also:


Attachments
Test map with rotating diffuse-lit cube in the center. (5.51 KB, application/octet-stream)
2011-02-09 02:59 EST, Evan Goers
diffuselight.diff (351 bytes, patch)
2011-02-11 14:03 EST, gimhael
New version of the test map. (5.10 KB, application/octet-stream)
2011-02-11 21:32 EST, Evan Goers

Description Evan Goers 2009-12-21 18:41:58 EST
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).
Comment 1 gimhael 2010-03-09 12:18:47 EST
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.
Comment 2 Thilo Schulz 2011-02-08 11:09:18 EST
Reopen this bug when you provide a testmap where I can test this problem. Until then close.
Comment 3 Evan Goers 2011-02-09 02:59:56 EST
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.
Comment 4 gimhael 2011-02-11 14:03:04 EST
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...
Comment 5 Evan Goers 2011-02-11 21:32:49 EST
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).
Comment 6 Evan Goers 2011-02-11 21:33:35 EST
(Re-opening here because it didn't work before.)
Comment 7 gimhael 2011-02-22 09:22:06 EST
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 ?
Comment 8 Evan Goers 2011-02-25 16:32:11 EST
(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
Comment 9 Thilo Schulz 2011-03-14 13:28:20 EDT
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.