Rise
The Vieneo Province
Loading...
Searching...
No Matches
CloudRenderer11.h
Go to the documentation of this file.
1#pragma once
3#include "CloudPass11.h"
4#include "FogBeams11.h"
5#include "CloudClearance11.h"
7#include <DirectXMath.h>
8#include <mutex>
9#include <atomic>
10
11namespace Rendering
12{
14 {
15 public:
16 using Vector=DirectX::XMFLOAT3;
17 using Color=DirectX::XMFLOAT4;
18 using Matrix=DirectX::XMFLOAT4X4;
20 static constexpr unsigned MaxHeadlights=FogBeams11::MaxLights;
21 HRESULT Initialize(ID3D11Device* device,const std::filesystem::path& shaderDirectory={});
22 void Reset();
24 // Reconnect notifications can originate outside the render thread.
25 // Consume invalidation before the next draw, which is also how a
26 // simulator exit avoids reusing the last exterior frame.
27 void ResetCloudHistory() {historyResetPending.store(true,std::memory_order_relaxed);}
28 bool Ready() const {return ready && enabled;}
31 const std::string& InitializationStatus() const {return status;}
32 uint32_t Seed() const {return seed;}
33 float ClearAirRadius() const {return clearAirRadius;}
34 // Diagnostic reference path: retain full partial-ray integration.
37 // Rows are v, columns u: surface/base MSL km, visibility km (zero
38 // unavailable), and live precipitation 2..16. No rain visibility penalty.
39 struct RainGrid { int cube=0,u=0,v=0;uint64_t revision=0;std::array<Color,4096> cells{}; };
40 void SetRainGrid(const RainGrid* grid);
41 bool HasRainGrid(uint64_t revision,int cube,int u,int v) const
42 {return rainActive && rainGrid.revision==revision && rainGrid.cube==cube && rainGrid.u==u && rainGrid.v==v;}
43 void UpdateWeather(const CloudWeather::MapPtr& map,double elapsed);
45 void SetLightningEnabled(bool value);
46 void UpdateLightning(const CloudVolume::Parameters& parameters,double elapsed,const CloudVolume::Point& observer={});
48 void SetLocalLightning(const Vector& position,const Color& color,float radiusKm);
49 void SetLocalLightning(const Vector& position,const Color& color,float radiusKm,const Vector& groundPosition);
50 void SetHeadlights(const std::vector<Headlight>& lights);
51 void SetFogDensity(float value) {fogDensity=std::isfinite(value) ? (std::max)(0.f,value) : 0;}
52 void SetFogBeamsEnabled(bool value) {fogBeamsEnabled=value;}
53 bool FogBeamsEnabled() const {return Ready() && fogBeamsEnabled && fogBeams.Ready();}
54 HRESULT PrepareResources(ID3D11DeviceContext* context) {return Ready() && context ? PrepareWeather(context) : E_UNEXPECTED;}
55 HRESULT Render(ID3D11DeviceContext* context,ID3D11RenderTargetView* scene,const SceneDepth11& depth,
56 const D3D11_VIEWPORT& viewport,const Matrix& view,const Matrix& projection,const Vector& planetEye,
57 const CloudVolume::Parameters& params,const Vector& sunlight,const Color& light,const Color& ambient,
58 const Color& airglow=Color(.125f,.375f,.25f,1),const Color& horizonHaze=Color(0,0,0,0),
59 const Color& atmosphereHaze=Color(0,0,0,0),const Color& nightVisionGain=Color(1,1,1,0));
60 CloudPass11& Pass() {return pass;}
61 const Parameters11& Parameters() const {return parameters;}
62 private:
64 {
66 Microsoft::WRL::ComPtr<ID3D11Texture2D> texture;
67 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv;
68 unsigned level=0,row=0;
69 bool complete=false;
70 };
71 HRESULT PrepareWeather(ID3D11DeviceContext* context);
72 HRESULT Fail(const char* step,HRESULT hr);
73 Microsoft::WRL::ComPtr<ID3D11Device> device;
74 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> noise,blackWeather,ground;
75 Microsoft::WRL::ComPtr<ID3D11Texture2D> groundTexture,rainTexture;
76 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> rainView;
78 Microsoft::WRL::ComPtr<ID3D11Texture2D> localBaseTexture;
79 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> localBaseView;
81 bool rainActive=false,rainDirty=false;
84 bool fogBeamsEnabled=true;
85 float fogDensity=1;
87 std::filesystem::path shaderDirectory;
88 std::vector<WeatherTexture> weatherTextures;
96 bool organicOrbit=false;
100 std::atomic<bool> historyResetPending{false};
107 std::vector<Headlight> headlights;
110 std::string status="native cloud renderer not initialized";
111 };
112}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
bool OrganicOrbitAvailable() const
Definition CloudPass11.h:59
bool OrganicFlightAvailable() const
Definition CloudPass11.h:60
HRESULT Render(ID3D11DeviceContext *context, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, const Matrix &view, const Matrix &projection, const Vector &planetEye, const CloudVolume::Parameters &params, const Vector &sunlight, const Color &light, const Color &ambient, const Color &airglow=Color(.125f,.375f,.25f, 1), const Color &horizonHaze=Color(0, 0, 0, 0), const Color &atmosphereHaze=Color(0, 0, 0, 0), const Color &nightVisionGain=Color(1, 1, 1, 0))
HRESULT Fail(const char *step, HRESULT hr)
void SetHeadlights(const std::vector< Headlight > &lights)
Microsoft::WRL::ComPtr< ID3D11Device > device
CloudWeather::Frame WeatherFrame()
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > localBaseView
bool HasRainGrid(uint64_t revision, int cube, int u, int v) const
CloudLightning::Diagnostic lightningDiagnostic
void SetLocalLightning(const Vector &position, const Color &color, float radiusKm)
const Parameters11 & Parameters() const
void SetGroundLighting(const CloudVolume::GroundLighting &lighting)
HRESULT PrepareWeather(ID3D11DeviceContext *context)
CloudLightning::System lightning
bool SetLightningDiagnostic(bool enabled)
std::vector< Headlight > headlights
CloudWeather::Frame weatherFrame
void UpdateLightning(const CloudVolume::Parameters &parameters, double elapsed, const CloudVolume::Point &observer={})
Microsoft::WRL::ComPtr< ID3D11Texture2D > groundTexture
void SetFogBeamsEnabled(bool value)
CloudWeather::MapPtr desiredWeather
CloudVolume::GroundLighting groundLighting
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > rainView
void SetLightningEnabled(bool value)
std::vector< WeatherTexture > weatherTextures
void UpdateWeather(const CloudWeather::MapPtr &map, double elapsed)
CloudWeather::Frame boundWeather
DirectX::XMFLOAT4X4 Matrix
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > noise
static constexpr unsigned MaxHeadlights
void SetRainGrid(const RainGrid *grid)
const std::string & InitializationStatus() const
CloudBaseWeather::GridPtr uploadedLocalBase
void SetFogDensity(float value)
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
std::atomic< bool > historyResetPending
std::filesystem::path shaderDirectory
Microsoft::WRL::ComPtr< ID3D11Texture2D > localBaseTexture
Microsoft::WRL::ComPtr< ID3D11Texture2D > rainTexture
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > ground
void SetClearAirOptimizationEnabled(bool value)
HRESULT PrepareResources(ID3D11DeviceContext *context)
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > blackWeather
bool OrganicAvailable() const
Definition FogBeams11.h:36
static constexpr unsigned MaxLights
Definition FogBeams11.h:17
bool Ready() const
Definition FogBeams11.h:35
Definition grid.h:14
std::shared_ptr< const Grid > GridPtr
constexpr uint32_t DefaultSeed
Definition CloudVolume.h:19
std::shared_ptr< const Map > MapPtr
DirectX::XMFLOAT3 Vector
Definition Math11.h:7
DirectX::XMFLOAT4X4 Matrix
Definition Math11.h:9
std::array< Color, 4096 > cells
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > srv
Microsoft::WRL::ComPtr< ID3D11Texture2D > texture