Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
ShipLightSprites.h
Go to the documentation of this file.
1
#pragma once
2
#include "
../Rendering/ClientRenderer11.h
"
3
#include <algorithm>
4
#include <cmath>
5
#include <cstring>
6
7
namespace
ShipLightSprites
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
19
class
StrobeGlare
20
{
21
public
:
22
StrobeGlare
(
Rendering::RenderDevice
&
device
,
const
RiseMath::Color
& emission,
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;
31
device
.
GetRenderState
(
RenderState::SRCBLEND
, &
sourceBlend
);
32
device
.
SetRenderState
(
RenderState::SRCBLEND
,
Blend::SRCALPHA
);
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
}
42
~StrobeGlare
()
43
{
44
if
(!
active
)
return
;
45
device
.
SetRenderState
(
Rendering::RenderState::SRCBLEND
,
sourceBlend
);
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
;
52
StrobeGlare
&
operator=
(
const
StrobeGlare
&) =
delete
;
53
private
:
54
Rendering::RenderDevice
&
device
;
55
bool
active
;
56
DWORD
sourceBlend
= 0;
57
DirectX::XMFLOAT4
factor
{};
58
Rendering::TextureOp11
alpha
=
Rendering::TextureOp11::Disable
;
59
Rendering::TextureArg11
alpha1
=
Rendering::TextureArg11::Texture
;
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.
72
inline
void
Bind
(
Rendering::RenderDevice
& device,
Rendering::RenderTexture
* texture)
73
{
74
using namespace
Rendering
;
75
device.
SetRenderState
(
RenderState::POINTSPRITEENABLE
, TRUE);
76
device.
SetRenderState
(
RenderState::POINTSIZE_MIN
,
SizeBits
(1.f));
77
device.
SetRenderState
(
RenderState::POINTSIZE_MAX
,
SizeBits
(
MaxSize
));
78
device.
SetRenderState
(
RenderState::LIGHTING
, FALSE);
79
device.
SetRenderState
(
RenderState::ALPHATESTENABLE
, FALSE);
80
device.
SetRenderState
(
RenderState::ALPHABLENDENABLE
, TRUE);
81
device.
SetRenderState
(
RenderState::BLENDOP
,
BlendOperation::ADD
);
82
device.
SetRenderState
(
RenderState::SRCBLEND
,
Blend::SRCCOLOR
);
83
device.
SetRenderState
(
RenderState::DESTBLEND
,
Blend::ONE
);
84
device.
SetRenderState
(
RenderState::ZFUNC
,
Compare::LESSEQUAL
);
85
device.
SetRenderState
(
RenderState::ZWRITEENABLE
, FALSE);
86
device.
SetTexture
(0, texture);
87
device.
SetTextureStageState
(0,
TextureState::COLOROP
,
TextureOperation::MODULATE
);
88
device.
SetTextureStageState
(0,
TextureState::COLORARG1
,
TextureArgument::TEXTURE
);
89
device.
SetTextureStageState
(0,
TextureState::COLORARG2
,
TextureArgument::TFACTOR
);
90
device.
SetTextureStageState
(0,
TextureState::ALPHAOP
,
TextureOperation::SELECTARG1
);
91
device.
SetTextureStageState
(0,
TextureState::ALPHAARG1
,
TextureArgument::TEXTURE
);
92
device.
SetTextureStageState
(0,
TextureState::TEXCOORDINDEX
, 0);
93
device.
SetTextureStageState
(0,
TextureState::TEXTURETRANSFORMFLAGS
,
TextureTransform::DISABLE
);
94
device.
SetTextureStageState
(1,
TextureState::COLOROP
,
TextureOperation::DISABLE
);
95
device.
SetTextureStageState
(1,
TextureState::ALPHAOP
,
TextureOperation::DISABLE
);
96
device.
SetSamplerState
(0,
SamplerState::MAGFILTER
,
Filter::LINEAR
);
97
device.
SetSamplerState
(0,
SamplerState::MINFILTER
,
Filter::LINEAR
);
98
device.
SetSamplerState
(0,
SamplerState::MIPFILTER
,
Filter::POINT
);
99
}
100
}
ClientRenderer11.h
DWORD
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
Definition
Controls.cpp:5032
Rendering::DrawContext11::Fixed
FixedState11 & Fixed()
Definition
DrawContext11.h:35
Rendering::RenderDevice
Definition
ClientRenderer11.h:92
Rendering::RenderDevice::Draws
DrawContext11 & Draws()
Definition
ClientRenderer11.h:96
Rendering::RenderDevice::GetRenderState
HRESULT GetRenderState(DWORD state, DWORD *value) const
Definition
ClientRenderer11.cpp:113
Rendering::RenderDevice::SetRenderState
HRESULT SetRenderState(DWORD state, DWORD value)
Definition
ClientRenderer11.cpp:127
Rendering::RenderDevice::SetTextureStageState
HRESULT SetTextureStageState(DWORD stage, DWORD state, DWORD value)
Definition
ClientRenderer11.cpp:234
Rendering::RenderDevice::SetTexture
HRESULT SetTexture(DWORD stage, RenderTexture *texture)
Definition
ClientRenderer11.cpp:251
Rendering::RenderDevice::SetSamplerState
HRESULT SetSamplerState(DWORD sampler, DWORD state, DWORD value)
Definition
ClientRenderer11.cpp:225
Rendering::RenderTexture
Definition
ClientRenderer11.h:32
ShipLightSprites::StrobeGlare::active
bool active
Definition
ShipLightSprites.h:55
ShipLightSprites::StrobeGlare::alpha1
Rendering::TextureArg11 alpha1
Definition
ShipLightSprites.h:59
ShipLightSprites::StrobeGlare::StrobeGlare
StrobeGlare(Rendering::RenderDevice &device, const RiseMath::Color &emission, float transmission, bool enabled=true)
Definition
ShipLightSprites.h:22
ShipLightSprites::StrobeGlare::alpha
Rendering::TextureOp11 alpha
Definition
ShipLightSprites.h:58
ShipLightSprites::StrobeGlare::sourceBlend
DWORD sourceBlend
Definition
ShipLightSprites.h:56
ShipLightSprites::StrobeGlare::factor
DirectX::XMFLOAT4 factor
Definition
ShipLightSprites.h:57
ShipLightSprites::StrobeGlare::device
Rendering::RenderDevice & device
Definition
ShipLightSprites.h:54
ShipLightSprites::StrobeGlare::operator=
StrobeGlare & operator=(const StrobeGlare &)=delete
ShipLightSprites::StrobeGlare::StrobeGlare
StrobeGlare(const StrobeGlare &)=delete
ShipLightSprites::StrobeGlare::~StrobeGlare
~StrobeGlare()
Definition
ShipLightSprites.h:42
Rendering::Blend::SRCCOLOR
constexpr uint32_t SRCCOLOR
Definition
ClientTypes11.h:192
Rendering::Blend::ONE
constexpr uint32_t ONE
Definition
ClientTypes11.h:189
Rendering::Blend::SRCALPHA
constexpr uint32_t SRCALPHA
Definition
ClientTypes11.h:190
Rendering::BlendOperation::ADD
constexpr uint32_t ADD
Definition
ClientTypes11.h:198
Rendering::Compare::LESSEQUAL
constexpr uint32_t LESSEQUAL
Definition
ClientTypes11.h:207
Rendering::Filter::POINT
constexpr uint32_t POINT
Definition
ClientTypes11.h:258
Rendering::Filter::LINEAR
constexpr uint32_t LINEAR
Definition
ClientTypes11.h:256
Rendering::RenderState::SRCBLEND
constexpr uint32_t SRCBLEND
Definition
ClientTypes11.h:80
Rendering::RenderState::POINTSPRITEENABLE
constexpr uint32_t POINTSPRITEENABLE
Definition
ClientTypes11.h:71
Rendering::RenderState::ALPHABLENDENABLE
constexpr uint32_t ALPHABLENDENABLE
Definition
ClientTypes11.h:15
Rendering::RenderState::ALPHATESTENABLE
constexpr uint32_t ALPHATESTENABLE
Definition
ClientTypes11.h:18
Rendering::RenderState::DESTBLEND
constexpr uint32_t DESTBLEND
Definition
ClientTypes11.h:39
Rendering::RenderState::POINTSIZE_MIN
constexpr uint32_t POINTSIZE_MIN
Definition
ClientTypes11.h:70
Rendering::RenderState::LIGHTING
constexpr uint32_t LIGHTING
Definition
ClientTypes11.h:55
Rendering::RenderState::ZFUNC
constexpr uint32_t ZFUNC
Definition
ClientTypes11.h:112
Rendering::RenderState::ZWRITEENABLE
constexpr uint32_t ZWRITEENABLE
Definition
ClientTypes11.h:113
Rendering::RenderState::BLENDOP
constexpr uint32_t BLENDOP
Definition
ClientTypes11.h:23
Rendering::RenderState::POINTSIZE_MAX
constexpr uint32_t POINTSIZE_MAX
Definition
ClientTypes11.h:69
Rendering::SamplerState::MIPFILTER
constexpr uint32_t MIPFILTER
Definition
ClientTypes11.h:127
Rendering::SamplerState::MAGFILTER
constexpr uint32_t MAGFILTER
Definition
ClientTypes11.h:123
Rendering::SamplerState::MINFILTER
constexpr uint32_t MINFILTER
Definition
ClientTypes11.h:126
Rendering::TextureArgument::TFACTOR
constexpr uint32_t TFACTOR
Definition
ClientTypes11.h:246
Rendering::TextureArgument::TEXTURE
constexpr uint32_t TEXTURE
Definition
ClientTypes11.h:245
Rendering::TextureOperation::DISABLE
constexpr uint32_t DISABLE
Definition
ClientTypes11.h:229
Rendering::TextureOperation::SELECTARG1
constexpr uint32_t SELECTARG1
Definition
ClientTypes11.h:232
Rendering::TextureOperation::MODULATE
constexpr uint32_t MODULATE
Definition
ClientTypes11.h:230
Rendering::TextureState::COLOROP
constexpr uint32_t COLOROP
Definition
ClientTypes11.h:146
Rendering::TextureState::COLORARG1
constexpr uint32_t COLORARG1
Definition
ClientTypes11.h:144
Rendering::TextureState::ALPHAARG1
constexpr uint32_t ALPHAARG1
Definition
ClientTypes11.h:134
Rendering::TextureState::ALPHAOP
constexpr uint32_t ALPHAOP
Definition
ClientTypes11.h:136
Rendering::TextureState::TEXCOORDINDEX
constexpr uint32_t TEXCOORDINDEX
Definition
ClientTypes11.h:154
Rendering::TextureState::COLORARG2
constexpr uint32_t COLORARG2
Definition
ClientTypes11.h:145
Rendering::TextureState::TEXTURETRANSFORMFLAGS
constexpr uint32_t TEXTURETRANSFORMFLAGS
Definition
ClientTypes11.h:155
Rendering::TextureTransform::DISABLE
constexpr uint32_t DISABLE
Definition
ClientTypes11.h:275
Rendering
Definition
AdDiagnostics11.cpp:16
Rendering::TextureArg11
TextureArg11
Definition
FixedFunction11.h:22
Rendering::TextureArg11::Factor
@ Factor
Definition
FixedFunction11.h:22
Rendering::TextureArg11::Texture
@ Texture
Definition
FixedFunction11.h:22
Rendering::TextureOp11
TextureOp11
Definition
FixedFunction11.h:21
Rendering::TextureOp11::Select1
@ Select1
Definition
FixedFunction11.h:21
Rendering::TextureOp11::Disable
@ Disable
Definition
FixedFunction11.h:21
ShipLightSprites
Definition
ShipLightSprites.h:8
ShipLightSprites::Bind
void Bind(Rendering::RenderDevice &device, Rendering::RenderTexture *texture)
Definition
ShipLightSprites.h:72
ShipLightSprites::Size
float Size(float baseSize, float power, float facing)
Definition
ShipLightSprites.h:11
ShipLightSprites::SizeBits
DWORD SizeBits(float value)
Definition
ShipLightSprites.h:62
ShipLightSprites::MaxSize
constexpr float MaxSize
Definition
ShipLightSprites.h:9
Rendering::FixedState11::textureFactor
DirectX::XMFLOAT4 textureFactor
Definition
FixedFunction11.h:71
RiseMath::Color
Definition
ClientMath.h:67
RiseMath::Color::b
float b
Definition
ClientMath.h:68
RiseMath::Color::g
float g
Definition
ClientMath.h:68
RiseMath::Color::r
float r
Definition
ClientMath.h:68
Viewscreen
ShipLightSprites.h
Generated on
for Rise by
1.18.0