-
Notifications
You must be signed in to change notification settings - Fork 70
need a reliable way to detect if a given surface is one of a bsp model #302
Description
Render is basically doing this to pick which glsl code to use to render a given texture:
if lightmapping is enabled and surface has lightmap:
render_with_lightmap_as_map()
else if entity is not world:
render_with_lightgrid_as_model()
else:
render_with_lightgrid_as_map()Real code there:
Daemon/src/engine/renderer/tr_shade.cpp
Lines 3058 to 3070 in 42e408a
| if ( !r_vertexLighting->integer && tess.lightmapNum >= 0 && tess.lightmapNum <= tr.lightmaps.currentElements ) | |
| { | |
| Render_lightMapping( stage ); | |
| } | |
| else if ( backEnd.currentEntity != &tr.worldEntity ) | |
| { | |
| // FIXME: This can be reached if r_vertexLighting == 0 and tess.lightmapNum is invalid which doesn't seem right | |
| Render_vertexLighting_DBS_entity( stage ); | |
| } | |
| else | |
| { | |
| Render_vertexLighting_DBS_world( stage ); | |
| } |
The issue is:
If a bsp model has light map, light mapping is enabled the model is rendered with the same code used to render the whole map in all case, which is good.
But if such bsp model is not a world model (for example a func_rotating entity), if light mapping is disabled, such bsp model is rendered with the c++ code and glsl code for the non-bsp models (like player models, weapons…).
So basically we have this:
| kind | world | lm enabled | lm disabled |
|---|---|---|---|
| bsp model | yes | lightmap world | lightgrid world |
| bsp model | no | lightmap world | lightgrid entity |
| game model | no | lightgrid entity | lightgrid entity |
When bsp models are rendered as game models, such unwanted glsl computation may be done, like rim lighting.
Although, we see non-world bsp model are handled fine by both lightmap, lightgrid world and lightgrid entity shaders, meaning there is maybe not a strong need for so much copypaste (see #301 for ongoing merge effort).
To improve the code I would like to have a reliable way to know if a model is a bsp model or not. I don't think it's reliable to detect if surface has lightmap since map may be built without.
To make the bug obvious, I temporarily modified the lightgrid entity glsl shader (vertexLighting_DBS_entity_fp.glsl) to set red channel to full, this to paint in red every surface rendered by this code.
Light map enabled:
Light map disabled:
Light map enabled:
Light map disabled:
Light map enabled:
Light map disabled:





