mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-09 16:33:50 +00:00
* Emissive system refactor (#58130) The emissives system is the system that both lets computer screens and vendors glow in the dark and lets mobs and items block those glows. The current implementation relies on using filters to let mobs and items mask out the glow in the dark overlays on some structures. This is difficult to extend properly without massively increasing maptick. This PR changes the emissives system to use BYONDs native image layering to mask emissive overlays. This should prove to be a more extensible option. tldr; There exists a system that lets computer screens glow on the dark and lets mobs and items block the glow. It isn't very extensible and this PR attempts to make it more extensible. How emissive overlays used to work Currently emissive overlays and the emissive blockers that mask those overlays are handled using a system of inter-masking planes. The emissive overlays and the emissive blockers are placed on separate, hidden plane masters. These are essentially rendering layers and groups. The emissive blocker plane is then used to mask the emissive overlay plane which effectively allows the emissive blockers to block the emissive overlays from being seen. After is has been masked the emissive overlay plane is used to mask the lighting plane, essentially creating holes in the shadows wherever an unblocked glowing thing exists. Why this is a potential problem This system works fine. In fact it works great! The computer screens glow, any person or item that winds up on a computer blocks the glow, and everything just works. However, this system runs into some issues when you try to extend it to work on things other than structures. Namely, the current system only supports emissive overlays on structures and emissive overlays that are completely unblockable by any means. As a result, several interesting uses to the system require extending the system. As a result, if you want to apply emissive overlays to items (which exist between structures and mobs) or emissive overlays to turfs (which exist below structures) you must extend the emissives system to get the emissive overlays and emissive blockers to properly function. Doing this naively, by adding extra emissive overlay and emissive blocker planes and applying all of the relevant masking filters, is not exactly performant. Maptick is a major contributor to lag and the higher the maptick the more free lag you, the player, get delivered fresh to your client. Trying the naive method resulted in #55782 (1f1b58bb26), an attempt to add glowing carpet to the game. Since the PR revolved around adding glowing carpet it had to extend the emissives system to allow for emissive turfs and emissive blocking structures. Extending the system was done naively as described above and you can see the results. 1.5 times the maptick across the board. Ouch. So, we know that extending the system in it's current form is impractical. At least if done naively. Thus we are stuck. tldr; The emissive system currently uses inter-plane masking to allow for emissive blockers to function. This is difficult to reasonably extend without murdering maptick. See #56496 (1f1b58bb26) for the results of naively extending this system. How emissive overlays are going to work Alright, so we know that the current system of using planes to let the emissive blockers mask the emissive overlays is difficult to extend in it's current form. The solution is to change how the system works so that it can be extended in a more efficient manner. What we want is a system that allows one set of images to be out masked by another set of images and for the first set of images to be capable of masking the light plane. Preferably, we would also like the ability to interleave the masking effect between emissives and emissive blockers with almost arbitrary layering. Conveniently, this layering and masking is something BYOND already does to normal items and objects. If we put the emissive overlays and the emissive blockers on the same plane we can use their layers to interleave them almost arbitrarily like any normal structures and items! All we need is a way to mask away the emissive blockers from the resulting rendered plane and we can mask the lighting plane with the remaining emissive overlays. Luckily, BYOND has provided a single filter that is capable of this task. The color matrix filter. This filter can be used to apply a color matrix to an image! Provided that the emissive overlays and the emissive blockers are different colors we can use a color matrix filter to effectively mask out the emissive blockers from the plane! The resulting emissive plane can be applied as an alpha mask to the lighting plane as it used to, to the same effect. The best part is, we get layering practically for free! This is exactly what this PR does. It converts the emissives system from the old plane and masking based blocking to a new layer-based system which uses BYONDs native layer handling to mask the emissive overlays. * Emissive system refactor Co-authored-by: TemporalOroboros <TemporalOroboros@gmail.com>
120 lines
5.3 KiB
Plaintext
120 lines
5.3 KiB
Plaintext
///Object doesn't use any of the light systems. Should be changed to add a light source to the object.
|
|
#define NO_LIGHT_SUPPORT 0
|
|
///Light made with the lighting datums, applying a matrix.
|
|
#define STATIC_LIGHT 1
|
|
///Light made by masking the lighting darkness plane.
|
|
#define MOVABLE_LIGHT 2
|
|
///Light made by masking the lighting darkness plane, and is directional.
|
|
#define MOVABLE_LIGHT_DIRECTIONAL 3
|
|
|
|
///Is a movable light source attached to another movable (its loc), meaning that the lighting component should go one level deeper.
|
|
#define LIGHT_ATTACHED (1<<0)
|
|
|
|
//Bay lighting engine shit, not in /code/modules/lighting because BYOND is being shit about it
|
|
/// frequency, in 1/10ths of a second, of the lighting process
|
|
#define LIGHTING_INTERVAL 5
|
|
|
|
#define MINIMUM_USEFUL_LIGHT_RANGE 1.4
|
|
|
|
/// type of falloff to use for lighting; 1 for circular, 2 for square
|
|
#define LIGHTING_FALLOFF 1
|
|
/// use lambertian shading for light sources
|
|
#define LIGHTING_LAMBERTIAN 0
|
|
/// height off the ground of light sources on the pseudo-z-axis, you should probably leave this alone
|
|
#define LIGHTING_HEIGHT 1
|
|
/// Value used to round lumcounts, values smaller than 1/129 don't matter (if they do, thanks sinking points), greater values will make lighting less precise, but in turn increase performance, VERY SLIGHTLY.
|
|
#define LIGHTING_ROUND_VALUE (1 / 64)
|
|
|
|
/// icon used for lighting shading effects
|
|
#define LIGHTING_ICON 'icons/effects/lighting_object.dmi'
|
|
|
|
/// If the max of the lighting lumcounts of each spectrum drops below this, disable luminosity on the lighting objects.
|
|
/// Set to zero to disable soft lighting. Luminosity changes then work if it's lit at all.
|
|
#define LIGHTING_SOFT_THRESHOLD 0
|
|
|
|
/// If I were you I'd leave this alone.
|
|
#define LIGHTING_BASE_MATRIX \
|
|
list \
|
|
( \
|
|
1, 1, 1, 0, \
|
|
1, 1, 1, 0, \
|
|
1, 1, 1, 0, \
|
|
1, 1, 1, 0, \
|
|
0, 0, 0, 1 \
|
|
) \
|
|
|
|
///How many tiles standard fires glow.
|
|
#define LIGHT_RANGE_FIRE 3
|
|
|
|
#define LIGHTING_PLANE_ALPHA_VISIBLE 255
|
|
#define LIGHTING_PLANE_ALPHA_NV_TRAIT 245
|
|
#define LIGHTING_PLANE_ALPHA_MOSTLY_VISIBLE 192
|
|
/// For lighting alpha, small amounts lead to big changes. even at 128 its hard to figure out what is dark and what is light, at 64 you almost can't even tell.
|
|
#define LIGHTING_PLANE_ALPHA_MOSTLY_INVISIBLE 128
|
|
#define LIGHTING_PLANE_ALPHA_INVISIBLE 0
|
|
|
|
//lighting area defines
|
|
/// dynamic lighting disabled (area stays at full brightness)
|
|
#define DYNAMIC_LIGHTING_DISABLED 0
|
|
/// dynamic lighting enabled
|
|
#define DYNAMIC_LIGHTING_ENABLED 1
|
|
/// dynamic lighting enabled even if the area doesn't require power
|
|
#define DYNAMIC_LIGHTING_FORCED 2
|
|
/// dynamic lighting enabled only if starlight is.
|
|
#define DYNAMIC_LIGHTING_IFSTARLIGHT 3
|
|
#define IS_DYNAMIC_LIGHTING(A) A.dynamic_lighting
|
|
|
|
|
|
//code assumes higher numbers override lower numbers.
|
|
#define LIGHTING_NO_UPDATE 0
|
|
#define LIGHTING_VIS_UPDATE 1
|
|
#define LIGHTING_CHECK_UPDATE 2
|
|
#define LIGHTING_FORCE_UPDATE 3
|
|
|
|
#define FLASH_LIGHT_DURATION 2
|
|
#define FLASH_LIGHT_POWER 3
|
|
#define FLASH_LIGHT_RANGE 3.8
|
|
|
|
// Emissive blocking.
|
|
/// Uses vis_overlays to leverage caching so that very few new items need to be made for the overlay. For anything that doesn't change outline or opaque area much or at all.
|
|
#define EMISSIVE_BLOCK_GENERIC 1
|
|
/// Uses a dedicated render_target object to copy the entire appearance in real time to the blocking layer. For things that can change in appearance a lot from the base state, like humans.
|
|
#define EMISSIVE_BLOCK_UNIQUE 2
|
|
|
|
/// The color matrix applied to all emissive overlays. Should be solely dependent on alpha and not have RGB overlap with [EM_BLOCK_COLOR].
|
|
#define EMISSIVE_COLOR list(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 1,1,1,0)
|
|
/// A globaly cached version of [EMISSIVE_COLOR] for quick access.
|
|
GLOBAL_LIST_INIT(emissive_color, EMISSIVE_COLOR)
|
|
/// The color matrix applied to all emissive blockers. Should be solely dependent on alpha and not have RGB overlap with [EMISSIVE_COLOR].
|
|
#define EM_BLOCK_COLOR list(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,0)
|
|
/// A globaly cached version of [EM_BLOCK_COLOR] for quick access.
|
|
GLOBAL_LIST_INIT(em_block_color, EM_BLOCK_COLOR)
|
|
/// The color matrix used to mask out emissive blockers on the emissive plane. Alpha should default to zero, be solely dependent on the RGB value of [EMISSIVE_COLOR], and be independant of the RGB value of [EM_BLOCK_COLOR].
|
|
#define EM_MASK_MATRIX list(0,0,0,1/3, 0,0,0,1/3, 0,0,0,1/3, 0,0,0,0, 1,1,1,0)
|
|
/// A globaly cached version of [EM_MASK_MATRIX] for quick access.
|
|
GLOBAL_LIST_INIT(em_mask_matrix, EM_MASK_MATRIX)
|
|
|
|
/// Returns the red part of a #RRGGBB hex sequence as number
|
|
#define GETREDPART(hexa) hex2num(copytext(hexa, 2, 4))
|
|
|
|
/// Returns the green part of a #RRGGBB hex sequence as number
|
|
#define GETGREENPART(hexa) hex2num(copytext(hexa, 4, 6))
|
|
|
|
/// Returns the blue part of a #RRGGBB hex sequence as number
|
|
#define GETBLUEPART(hexa) hex2num(copytext(hexa, 6, 8))
|
|
|
|
/// Parse the hexadecimal color into lumcounts of each perspective.
|
|
#define PARSE_LIGHT_COLOR(source) \
|
|
do { \
|
|
if (source.light_color != COLOR_WHITE) { \
|
|
var/__light_color = source.light_color; \
|
|
source.lum_r = GETREDPART(__light_color) / 255; \
|
|
source.lum_g = GETGREENPART(__light_color) / 255; \
|
|
source.lum_b = GETBLUEPART(__light_color) / 255; \
|
|
} else { \
|
|
source.lum_r = 1; \
|
|
source.lum_g = 1; \
|
|
source.lum_b = 1; \
|
|
}; \
|
|
} while (FALSE)
|