Skip to content

Fix lighting for movable BSP entities#1897

Open
slipher wants to merge 1 commit intoDaemonEngine:masterfrom
slipher:lightbspmodel
Open

Fix lighting for movable BSP entities#1897
slipher wants to merge 1 commit intoDaemonEngine:masterfrom
slipher:lightbspmodel

Conversation

@slipher
Copy link
Member

@slipher slipher commented Feb 16, 2026

BSP model surfaces were wrongly flagged with the bspSurface bit which only works for fixed-location world surfaces. This flag was causing the code to skip setting up the model matrix for the lightMapping shader, meaning normals and dynamic light positions were not correct.

So stop flagging BSP models as bspSurface. Also skip the other things in R_AddWorldSurface, besides R_AddDrawSurf, because they are useless or redundant.

Fixes Unvanquished/Unvanquished#3474.

BSP model surfaces were wrongly flagged with the `bspSurface` bit which
only works for fixed-location world surfaces. This flag was causing the
code to skip setting up the model matrix for the lightMapping shader,
meaning normals and dynamic light positions were not correct.

So stop flagging BSP models as `bspSurface`. Also skip the other things
in R_AddWorldSurface, besides R_AddDrawSurf, because they are useless or
redundant.

This means that BSP entities (e.g. doors) will now generally be lit with
grid lighting rather than lightmaps.

Fixes Unvanquished/Unvanquished#3474.
@illwieckz
Copy link
Member

illwieckz commented Feb 16, 2026

This has the unwanted side effect of forcing all BSP models to be rendered with the lightgrid instead of their lightmap.

Actually, I want to implement that feature of being able to render some BSP models with the lightgrid (it's useful for movers like doors or trains, to not move with their shadows), but we better not enforce that.

BSP models are BSP surfaces and they are not wrongly flagged with the bspSurface bit, but we need more metadata to handle the various use cases:

  • non-model bsp surface
  • lightmapped model bsp surface
  • lightgrid model bsp surface

As a start we may only focus on those two uses cases (to only fix the bug you found) :

  • non-model bsp surface
  • model bsp surface

Either we add more booleans, either we turn bspSurface into a bit field.

@illwieckz
Copy link
Member

Such bitfield can have three values (better names can be found):

  • BSP_SURFACE (all BSP surfaces would get this bit)
  • BSP_MODEL (only BSP models would get this bit)
  • BSP_LIGHTMAP (all BSP surfaces would get this bit for a start, configurable in the future)

To fix the bug you found we would check that BSP_SURFACE is set but BSP_MODEL is not set, and since BSP_LIGHTMAP would always be set the lightmapping would still be correct.

And in the future we would implement a code path to not set BSP_LIGHTMAP on some models (likely a map entity option) to disable the lightmap on a given model and enforce the lightgrid for it.

@illwieckz
Copy link
Member

The Vega map has many doors and can be used to test this. Among those doors is a vertical door with a known visible shadow moving with the door (that's the kind of door I would like to have an option to force the lightgrid on it).

@slipher
Copy link
Member Author

slipher commented Feb 16, 2026

This has the unwanted side effect of forcing all BSP models to be rendered with the lightgrid instead of their lightmap.

I'm aware of that. I had written it in the commit message, but forgot to push the latest version.

Lighting the models with the light grid seems like a correct default to me, since in general they are intended to move, meaning the fixed lightmap is wrong. Stuff is usually a BSP model rather than part of the main world model because it needs to move. Maybe there are some cases that don't move, but the gamelogic would have to flag those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BSP models are not transformed for lighting calculations

2 participants