Rise
The Vieneo Province
Loading...
Searching...
No Matches
SignalLightAttenuation.h
Go to the documentation of this file.
1#pragma once
3#include <algorithm>
4#include <cmath>
5
7{
8 inline DirectX::XMFLOAT4 Factor(const RiseMath::Color& emission, float transmission)
9 {
10 // Preserve the authored clear-air color and squared flare texture.
11 // SRC_COLOR blending squares the shader output, so sqrt(T) applies
12 // fog/cloud extinction once: (texture * color)^2 * T, not ... * T^2.
13 const DWORD packed = emission;
14 const float scale = std::sqrt((std::max)(0.f, (std::min)(1.f, transmission))) / 255.f;
15 return {float((packed >> 16) & 255) * scale, float((packed >> 8) & 255) * scale,
16 float(packed & 255) * scale, emission.a};
17 }
18
19 // Native additive bulbs use the same visibility policy as the legacy
20 // signal sprites, without squaring their authored texture/color profile.
21 inline float EmissionTransmission(float transmission, bool isSimulator)
22 {
23 const float t = (std::max)(0.f, (std::min)(1.f, transmission));
24 return isSimulator ? t * t : t;
25 }
26
27 inline void Apply(Rendering::RenderDevice& device, const RiseMath::Color& emission,
28 float transmission, bool isSimulator)
29 {
30 // The caller has already set the original attenuated, packed color.
31 // Retain that exact baseline (including quantization) in the simulator.
32 if (isSimulator) return;
33 // Apply after the caller's TEXTUREFACTOR state so extinction retains
34 // float precision instead of being rounded to an intermediate DWORD.
35 device.Draws().Fixed().textureFactor = Factor(emission, transmission);
36 }
37}
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
FixedState11 & Fixed()
DrawContext11 & Draws()
void Apply(Rendering::RenderDevice &device, const RiseMath::Color &emission, float transmission, bool isSimulator)
DirectX::XMFLOAT4 Factor(const RiseMath::Color &emission, float transmission)
float EmissionTransmission(float transmission, bool isSimulator)
DirectX::XMFLOAT4 textureFactor