Skip to content

Add Lights objects to .animated sections - #1328

Draft
adfriz wants to merge 7 commits into
leezer3:masterfrom
adfriz:lights-objects
Draft

adfriz wants to merge 7 commits into
leezer3:masterfrom
adfriz:lights-objects

Conversation

@adfriz

@adfriz adfriz commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Add 2 type of light source, spot and point.

I follow how blender light object settings, so it may more physically correct

can be tested in .animated file with:

[Light]
Type = Point or Spot
Position = X, Y, Z
Direction = X, Y, Z
Color = R, G, B
Range = RangeInMeters
Visual = true or false
Power = Watts
Exposure = Value
Normalize = true or false
Radius = Value
SoftFalloff = true or false
Angle = Degrees
Softness = Value
ShowCone = true or false
Shadow = true or false

Can use standard animation functions and parameters (Optional)

TranslateXFunction = ...
TranslateYFunction = ...
TranslateZFunction = ...
RotateXFunction = ...
RotateYFunction = ...
RotateZFunction = ...
and others...

Parameter Details:

  • Type: Light type. Point (omnidirectional) or Spot (focused). Default: Point.
  • Position: Coordinates (X, Y, Z) of the light source.
  • Direction: Directing vector (X, Y, Z) for the Spot light beam, accept decimal/float, can be negative for the opposite direction, can be mixed for diagonal direction.
  • Color: Light color in RGB format (values 0-255).
  • Range: Coverage boundary of the light in meters.
  • Power: Light output in Watts. Default: 12.5663706.
  • Exposure: Exposure adjustment multiplier for the light source. Default: 0.0.
  • Normalize: Normalizes power distribution. Accepts true/false or 1/0. if set false, this should show how bright the power in the real life
  • Radius: Physical size of the light source in meters for specular glow calculation. Non-negative. Default: 0.0.
  • SoftFalloff: Enables smooth fadeout attenuation near the range limit. Accepts true/false or 1/0.
  • Angle: Cone beam angle for Spot light in degrees. Default: 45.0. Internally calculates SpotCutoff = Cos((Angle / 2) * PI / 180). Sets how wide the spot light is.
  • Softness: Edge penumbra softness for Spot light (0.0 to 1.0). Default: 1.0.
  • ShowCone / Visual: Toggle showing the visual debug/helper cone in the scene. Accepts true/false or 1/0.
  • Shadow: Toggle whether the light source casts shadows. Accepts true/false or 1/0. Currently not show any shadow....

Light Animation:
A [Light] block generates an independent animated object containing the light. It supports all standard animation script properties (functions, directions, and damping) defined directly inside the [Light] block.

preview:

Screen.Recording.2026-06-05.165220.mp4
Screen.Recording.2026-06-05.1902002.mp4

Although it works... this still very work in progress, like the settings light limit does not have label yet... and i put it under the max sounds section.


i feel like we must set a roadmap priority, i mean if we keep adding feature but the stuff under the hood not built for it, it feels not efficient.

like with this light object feature, although it works... the renderer not build for this kind of feature and from what i can understand the renderer still a basic forward render, if we need modern feature, we must change the renderer to maybe clustered forward?

or other priority like using newer opentk or moving to other bindings like silk net ?

@adfriz

adfriz commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

@leezer3 what do you think?

@leezer3

leezer3 commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Basically this is what in this country we'd call the chicken and egg paradox. (I'm never sure how well these translate)- You need working examples of something (or at least a specification) in order to design sensibly the systems needed to actually make it work; this is in part why I've been working on MSTS content, as this gives a set of features with an already dssigned specification.

If you don't have this, what you tend to end up with is a massive teetering tower where each new feature gets bodged on to the last.

@adfriz

adfriz commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the insight leezer3, i understand my PR could be a tech debt if i just submit it as working feature without a concrete base. i also don't want any of my PR to be a burden, like "here is a new feature, goodbye" and left it in the dust.

So, is openbve will follow MSTS specs as basis? like open rails?


A note: If anyone wants to improve or extend any of my PR, either still open or draft PR. The license should use simplified BSD-2 license.

  - Added early exit if no active lights.
  - Made spotlight attenuation calculations branchless.
  - Precalculated division constants.
  - Added frustum culling for active scene lights.
  - Added per-object closest 16 lights binding when total lights > 16.
  - Cached bound dynamic lights list and view matrix to skip redundant GL.ProgramUniform calls.
  - Removed unused CastShadow property and shadow = 1 parsing.
@leezer3

leezer3 commented Jun 8, 2026

Copy link
Copy Markdown
Owner

For reference, this is a MSTS / OpenRails light:

Light (
   Comment( light head Left )
   Type ( 0 )
   Conditions (
    Headlight ( 2 )
    Unit ( 2 )
    Control ( 2 )
   )
   Cycle ( 0 )
   FadeIn ( 0.5 )
   FadeOut ( 0.5 )
   States ( 1
    State (
     Duration ( 0.0 )
     LightColour ( ffffcb8d )
     Position ( 0.57 1.62 8.52 )
     Azimuth ( 0 0 0 )
     Elevation ( -43 -43 -43)
     Transition ( 0 )
     Radius ( 1.0 )
    )
   )

I'm not sure on this, but it feels as if there are too many parameters exposed :)
As you've noted above, the engine isn't exactly the greatest, and I wonder if we need these at least in the short term.


Honestly, I don't exactly know exactly where the roadmap is going, and I suppose that is some of the problem.
What I'm keen to avoid though is just ramming extra parameters into the existing files when it'd be more sensible to design something new for the job.

I'm intending to re-write the CSV / B3D parser soon into something more akin to the block parsers, both to make it read cleaner and to get it to a known good licence state.

@leezer3 leezer3 mentioned this pull request Aug 7, 2026
# Conflicts:
#	source/ObjectViewer/Graphics/NewRendererS.cs
#	source/OpenBVE/Graphics/NewRenderer.cs
#	source/RouteViewer/NewRendererR.cs
@leezer3

leezer3 commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Coming back to this one after #1436

Thinking about this laterally, how about defining lights via their own XML file?
Allow inclusion of the light via an animated file as per an object.

Also allow attaching a light to a car, either via an XML tag in the 'new' format, or via additional say Lights lines in extensions.cfg etc.

Your animated object class then holds an array of lights, as does the rail car itself.

@leezer3

leezer3 commented Sep 28, 2026

Copy link
Copy Markdown
Owner

More thinking....

If we take a 'standard' train from the UK, this would need ~2 light sources as an absolute minimum. This would be:

  • Headlights
  • Tail light

A good number of trains will have 3 or 4 light sources, that being high / low level headlights plus tail lights.


We also want to think about a hierarchy of light sources- The light source itself I think needs some sort of Type parameter.

Something along these lines:

  • Headlights (highest priority)
  • Tail lights + running lights (second highest priority)
  • Scenic lights (third highest)
  • Station lights (fourth highest)
  • Ambient lights, low priority, as I'm certain the moment this is added to the main builds, someone will add streetlights every 25m or something- There's an indonesian route somewhere with fluttering flags which does this....

@ginga81

ginga81 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Japanese players have expressed a desire to see an effect where the shadows of lights are cast across pillars in subway stations.
I would like to convey that request here.
I am currently creating Shinkansen line, but Japanese railway stations are often brightly illuminated by fluorescent or LED lighting such as mine.
I also think it would be great to see the light from individual fixtures spilling out through the train windows.
Screenshot from 2026-09-28 20-35-59
Screenshot from 2026-09-28 20-37-33

@leezer3

leezer3 commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Further design thoughts:
It may possibly be useful to designate a light, or light types as casting shadows / not as the case may be.

Going back to my list above, tail lights and ambient lights might well get away with not casting shadows at all.

The other possibility I can think of would be to disable shadow-casting for short range lights (say under 10m or so). This would allow your streetlight with a small local cone to skip much of the shadow code.

@adfriz

adfriz commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

All of your suggestion is good.

i also have thoughts for the static lights to have auto on/off based on time of day.

but... i think this lights object pr is lower priority. i mean its obvious we will use a lot of light objects especially in routes if this pr done.


but the underlying renderer not designed for this much of lights, need full rework...

We need new renderer architecture, currently our renderer is a standard forward renderer, fortunately i have some resources for this, https://github.com/Angelo1211/HybridRenderingEngine , https://github.com/DaveH355/clustered-shading , https://www.aortiz.me/2018/12/21/CG.html

all of them are MIT licensed, so its safe to use, just need attribution.

My plan to use the forward+ or tiled forward rendering.

But there also some sacrifice, like we need to limit some feature for macos because they cant use compute shader.

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.

3 participants