Tip on Luminance

#1
Dear Terasology Community,

I'm trying to create a lamp block, something that you click to turn on/off. However, not much luck so far regarding the block's self-luminance. I've tried the following approaches:

- If I just add the "luminance:15" property to the .block file, I do not seem to be able to remove it later - say, when capturing a block activate event (block.setLuminance((byte) 0) - and the block is always illuminated.
- If I add a LightComponent to my block's prefab, I have a lot of control over the block's lighting properties and I can even remove this component later, effectively "turning it off". However, but the block surfaces themselves remain unlit all the time.
- I found that the MeshComponent does have the selfLuminance property; however, even if I add the MeshComponent to my block's prefab with some "selfLuminance:15" property, the block's surfaces are always dark.

Thanks and all the best
 

Cervator

Org Co-Founder & Project Lead
Contributor
Design
Logistics
SpecOps
#2
Hey @bmpcardoso :)

So you've come across two distinct lighting approaches:
  1. Block light based on the block attribute "luminance" - this is the oldest system and probably just adds to the block light per block space then the renderer takes that into account. It is always global to a block type so you can't have different instances of a block vary
  2. Entity-based light based on the LightComponent. This renders differently and not necessarily perfectly based on the mesh attached to the entity that's lighting up
We do have a lamp over in the Signalling module that used to light up perfectly when given some sort of charge from a wire network. I don't recall exactly how it worked or did its thing, but I think it literally switched the block between two variants: a lamp block that's off and a lamp block that is on (and has luminance set). Then the related system logic just swapped between the two blocks accordingly.

I'm not an expert on this but hopefully that gets you started :)
 
#3
Hi @Cervator, thanks for the reply!

I have implemented a working solution as you suggested: two blocks, one with 15 luminance and the other with 1. When activated, I just switch the blocks. Nice and simple. :)

However, I noticed something interesting. If I place a block with luminance > 0 in the world via code and then remove it in-game, the luminiscence will be removed as expected. However, if I replace a luminance > 0 block with another with luminance = 0 via code, the engine will keep the light in the world, as if the second block had the same luminance value as the first. Removing the 0 luminance block in-game will also not change this, as the light point will remain in the empty place...

After some browsing through the code, I believe that the engine creates LightComponents only for luminance > 0 blocks. Because I cannot find said components on the blocks' entities, I'm guessing that the engine "attaches" those components to world locations. So when I replace the block via code, the existing LightComponent is not removed and keeps there shedding its light unless the block is replaced before by another block with luminance > 0. Curious... :)
 

Cervator

Org Co-Founder & Project Lead
Contributor
Design
Logistics
SpecOps
#4
Interesting!

There is a somewhat tricky area when you have an entity at a given block position, and then switch the block. Similar situations occur when trying to do stuff like plant growth (switching the growth stage indicated via block). We may need to clarify how to best do that and/or fix any related bugs in the area.

If you submit an issue on GitHub documenting your use case and observed behavior so we can see if it can be confirmed as a bug and fixed, or at least get you some more intel on how to handle it better. You could also hop on chat sometime and see if you catch somebody who is more of an expert at it than me :)