Rise
The Vieneo Province
Loading...
Searching...
No Matches
ShipLightSprites.h
Go to the documentation of this file.
1#pragma once
3#include <algorithm>
4#include <cmath>
5#include <cstring>
6
8{
9 constexpr float MaxSize = 256.f;
10
11 inline float Size(float baseSize, float power, float facing)
12 {
13 // Only beams are directional. Bulbs, strobes and beacons are visible
14 // from any unobstructed camera; geometry supplies their occlusion.
15 if (power == 2.f) return baseSize * 4.f * std::pow(std::clamp(facing, 0.f, 1.f), 8.f);
16 return baseSize * ((power == .5f || power == 1.5f) ? 2.f : 1.f);
17 }
18
20 {
21 public:
23 float transmission, bool enabled = true) : device(device), active(enabled)
24 {
25 if (!active) return;
26 using namespace Rendering;
27 auto& fixed = device.Draws().Fixed();
28 factor = fixed.textureFactor;
29 alpha = fixed.stages[0].alpha;
30 alpha1 = fixed.stages[0].alpha1;
33 fixed.stages[0].alpha = TextureOp11::Select1;
34 fixed.stages[0].alpha1 = TextureArg11::Factor;
35 // Preserve the flare's soft wings and saturate a broader bright
36 // core. Apply cloud/fog transmission AFTER this boost,
37 // through alpha, so even the saturated core fades correctly.
38 constexpr float intensity = 6.f;
39 const float visibility = std::clamp(transmission, 0.f, 1.f);
40 fixed.textureFactor = {emission.r * intensity, emission.g * intensity, emission.b * intensity, visibility};
41 }
43 {
44 if (!active) return;
46 auto& fixed = device.Draws().Fixed();
47 fixed.textureFactor = factor;
48 fixed.stages[0].alpha = alpha;
49 fixed.stages[0].alpha1 = alpha1;
50 }
51 StrobeGlare(const StrobeGlare&) = delete;
53 private:
55 bool active;
57 DirectX::XMFLOAT4 factor{};
60 };
61
62 inline DWORD SizeBits(float value)
63 {
64 DWORD bits;
65 std::memcpy(&bits, &value, sizeof(bits));
66 return bits;
67 }
68
69 // Use the engine's camera-facing point quad and the shared flare texture.
70 // Set the limit explicitly: DX11's default 64-pixel clamp otherwise shrinks
71 // the nearby ship flares to a quarter of their requested diameter.
73 {
74 using namespace Rendering;
86 device.SetTexture(0, texture);
99 }
100}
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
FixedState11 & Fixed()
DrawContext11 & Draws()
HRESULT GetRenderState(DWORD state, DWORD *value) const
HRESULT SetRenderState(DWORD state, DWORD value)
HRESULT SetTextureStageState(DWORD stage, DWORD state, DWORD value)
HRESULT SetTexture(DWORD stage, RenderTexture *texture)
HRESULT SetSamplerState(DWORD sampler, DWORD state, DWORD value)
Rendering::TextureArg11 alpha1
StrobeGlare(Rendering::RenderDevice &device, const RiseMath::Color &emission, float transmission, bool enabled=true)
Rendering::TextureOp11 alpha
Rendering::RenderDevice & device
StrobeGlare & operator=(const StrobeGlare &)=delete
StrobeGlare(const StrobeGlare &)=delete
constexpr uint32_t SRCCOLOR
constexpr uint32_t ONE
constexpr uint32_t SRCALPHA
constexpr uint32_t ADD
constexpr uint32_t LESSEQUAL
constexpr uint32_t POINT
constexpr uint32_t LINEAR
constexpr uint32_t SRCBLEND
constexpr uint32_t POINTSPRITEENABLE
constexpr uint32_t ALPHABLENDENABLE
constexpr uint32_t ALPHATESTENABLE
constexpr uint32_t DESTBLEND
constexpr uint32_t POINTSIZE_MIN
constexpr uint32_t LIGHTING
constexpr uint32_t ZFUNC
constexpr uint32_t ZWRITEENABLE
constexpr uint32_t BLENDOP
constexpr uint32_t POINTSIZE_MAX
constexpr uint32_t MIPFILTER
constexpr uint32_t MAGFILTER
constexpr uint32_t MINFILTER
constexpr uint32_t TFACTOR
constexpr uint32_t TEXTURE
constexpr uint32_t DISABLE
constexpr uint32_t SELECTARG1
constexpr uint32_t MODULATE
constexpr uint32_t COLOROP
constexpr uint32_t COLORARG1
constexpr uint32_t ALPHAARG1
constexpr uint32_t ALPHAOP
constexpr uint32_t TEXCOORDINDEX
constexpr uint32_t COLORARG2
constexpr uint32_t TEXTURETRANSFORMFLAGS
constexpr uint32_t DISABLE
void Bind(Rendering::RenderDevice &device, Rendering::RenderTexture *texture)
float Size(float baseSize, float power, float facing)
DWORD SizeBits(float value)
constexpr float MaxSize
DirectX::XMFLOAT4 textureFactor