Cloud Renderer

class CloudRenderer

Class for real-time volumetric cloud rendering.

There should exist a “trueSKY space”, where the origin(0,0,0 Cartesian) is at global mean sea level, and an arbitrary point on the Earth’s surface. The Z axis points up, the X and Y axes are arbitrary (for reasons described below). To avoid singularities, this point, and the orientation of its axes should be represented by a double-precision quaternion, which represents the rotation from (say) latitude and longitude zero with X pointing East and Y pointing North.

The Volume Window is a deformed cuboid, its upper and lower surfaces matching the Earth’s curvature. On the GPU, it is a 3D texture.

This trueSKY space moves in steps equivalent to one horizontal texel. The function CloudRenderer::MoveCloudWindowCentreTexel(x,y) does this. This should be done when the chosen viewpoint (this is up to you) moves more than a texel in any horizontal direction. This way, we need only update the edges as the window moves.

Public Types

typedef std::map<int, VolumeQueryResult> VolumeQueryResults
typedef std::map<int, LineQueryResult> LineQueryResults

Public Functions

CloudRenderer(simul::clouds::Environment *e, platform::core::MemoryInterface *mem)

Constructor: An external keyframer is provided, and an optional memory manager.

virtual ~CloudRenderer()

Destructor.

void SetPointLight(int id, vec3 pos, float min_radius, float max_radius, vec3 irradiance)

Place a point light source.

VolumeQueryResult GetPointQuery(int id, vec3 pos_km)

Set, or create a cloud query. This returns the previous results of the same query.

VolumeQueryResult GetPointQuery(int id) const

Get results of a cloud query.

int GetQueryIdForViewId(int view_id) const

Get the query id for the specified view. If Render() has been called for the view, the query should have a valid set of results for the last frame rendered.

LineQueryResult GetLineQuery(int id, vec3 pos1_km, vec3 pos2_km)

Set, or create a line query. This returns the previous results of the same query.

LineQueryResult GetLineQuery(int id) const

Get results of a line query.

void SetMaxSlices(int viewport_id, int maxs)

Cloud rendering detail is determined by the number of slices. If not set the value from the CloudKeyframer will be used (GetDefaultNumSlices), but each viewport id can have a separate setting.

int GetMaxSlices(int viewport_id)

Cloud rendering detail is determined by the number of slices. See SetMaxSlices.

void RecompileShaders()

Platform-dependent function to reload the shaders - only use this for debug purposes.

virtual void RestoreDeviceObjects(platform::crossplatform::RenderPlatform *renderPlatform)

Platform-dependent function to generate device objects for the renderer.

virtual void InvalidateDeviceObjects()

Call this Platform-dependent function when the 3D device has been lost.

void AsynchronousUpdate(platform::crossplatform::DeviceContext &deviceContext, float real_time)
virtual void PreRenderUpdate(platform::crossplatform::GraphicsDeviceContext &deviceContext, float real_time)

Once per-frame update. Do this before any rendering each frame. Called by WeatherRenderer.

virtual bool Render(platform::crossplatform::GraphicsDeviceContext &deviceContext, float exposure, TrueSkyRenderMode renderMode, platform::crossplatform::NearFarPass nearFarPass, platform::crossplatform::Texture *depth_tex, const sky::ScatteringVolume *scatteringVolume, bool write_alpha, const vec4 &viewportTextureRegionXYWH, const platform::crossplatform::AmortizationStruct &amortizationStruct, clouds::TwoResFramebuffer *fb, sky::LocalFadeTextures *localFadeTextures, platform::crossplatform::Texture *ambientCubemap)

Render function to draw clouds to the current render target.

virtual void RenderCloudShadowTexture(platform::crossplatform::GraphicsDeviceContext &deviceContext)

The cloud shadow texture: centred on the viewer, aligned to the sun. Output is km in front of or behind the view pos where shadow starts

virtual void RenderPrecipitationVolumeTexture(platform::crossplatform::GraphicsDeviceContext &deviceContext)
virtual void RenderRainbowLookupTexture(platform::crossplatform::GraphicsDeviceContext &deviceContext)
virtual void RenderQueries(platform::crossplatform::GraphicsDeviceContext &deviceContext)

Draw the queries in 3D for debugging purposes.

void RenderCloudVolumes(platform::crossplatform::GraphicsDeviceContext &deviceContext, CloudKeyframer *ck)

Render the cloud volumes for debugging purposes.

void RenderCloudGrid(platform::crossplatform::GraphicsDeviceContext &deviceContext, CloudKeyframer *ck)

Render the cloud grid for debugging purposes.

void RenderShapeMasks(platform::crossplatform::GraphicsDeviceContext &deviceContext, CloudKeyframer *ck)
virtual void RenderDebugInfo(platform::crossplatform::GraphicsDeviceContext &deviceContext, int width, int height)
virtual const char *GetDebugText() const

Get some per-frame text information for debugging.

void RenderLayerCrossSection(platform::crossplatform::GraphicsDeviceContext &deviceContext, sky::uid uid, bool side_elevation)

Show the cloud volumes onscreen by cross section.

void RenderCrossSections(platform::crossplatform::GraphicsDeviceContext &context, bool use_offsets = true, bool showLayerTextures = true, bool showVolumeTextures = true, bool debugValues = true)
void RenderAuxiliaryTextures(platform::crossplatform::GraphicsDeviceContext &context)
void RenderAABBWireframe(platform::crossplatform::GraphicsDeviceContext &context)
void ShowCloudRaytracingLightingTextures(platform::crossplatform::GraphicsDeviceContext &context)
inline void SetLightingQueryResult(const LightingQueryResult &_lightingQueryResult)

Show the cloud volume window on the lat-long sphere.

void Reset()
void SetIlluminationTexture(platform::crossplatform::Texture*)
void SetLightTableTexture(platform::crossplatform::Texture*)
inline virtual simul::clouds::BaseGpuCloudGenerator *GetBaseGpuCloudGenerator()

Get a pointer to the Cloud Generator.

virtual simul::clouds::BaseGpuCloudGenerator *CreateGpuCloudGenerator(platform::core::MemoryInterface *m)
platform::crossplatform::Quaterniond GetSiderealTransform()
void SetEnvironment(simul::clouds::Environment *e)

Set the sky interface.

CloudGeometryHelper *GetCloudGeometryHelper(int view_id)

Returns a new geometry helper.

virtual platform::crossplatform::Texture *GetRandomTexture3D()

Get the random 3D texture.

bool IsCameraAboveCloudBase(platform::math::Vector3 cam_pos) const

Return true if the camera is above the cloudbase altitude.

float GetSunOcclusion(platform::crossplatform::GraphicsDeviceContext &deviceContext, platform::math::Vector3 cam_pos)

Get a value for how much the sun is blocked from the clouds.

void SetEnableStorms(bool s)

Where supported, enable lightning generation.

void SetNoiseTextureProperties(int size, int freq, int octaves, float persistence)

Adjust the noise texture.

virtual const float *GetCloudScales() const

Get the xyz scales of the clouds in metres.

void InitialiseCloudShadowData()

Get an API-dependent identifier for the cloud’s 2D shadow.

const sky::CloudShadowData &GetCloudShadowData()
void SetMaxFadeDistanceKm(float dist_km)

Distance for fade texture lookups:

void SetMaxFadeAltitudeKm(float ma_km)

Altitude for fade texture lookups:

void ExportCloudVolume(unsigned char *target)
CloudRenderingOptions &GetCloudRenderingOptions()

Get a pointer to the current cloud rendering options.

void SetCloudRenderingOptions(const CloudRenderingOptions &c)

Set new cloud rendering options.

CloudWindow &GetCloudWindow()
float GetPrecipitation() const
float GetRainToSnow() const
inline GlobalWeatherRenderer *GetGlobalWeatherRenderer()
inline WindowUpdater &GetWindowUpdater()
CloudLayer *GetCloudLayer(sky::uid u)
inline platform::crossplatform::Texture *GetLightTableTexture()

Get a pointer to the current light table texture.

vec4 GetCloudLightResponse() const
inline const VolumeQueryResults &GetVolumeQueries()
inline const LineQueryResults &GetLineQueries()
void DrawRandom3D(platform::crossplatform::GraphicsDeviceContext &deviceContext, int width, int height)
void DrawNoise3D(platform::crossplatform::GraphicsDeviceContext &deviceContext, int width, int height, int *out_mip)
void DrawSmallWorley(platform::crossplatform::GraphicsDeviceContext &deviceContext, int width, int height)
void DrawLargeWorley(platform::crossplatform::GraphicsDeviceContext &deviceContext, int width, int height)
void DrawShadow(platform::crossplatform::GraphicsDeviceContext &deviceContext, int width, int height)