Cloud Renderer

class simul::clouds::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::MoveCloudWindow(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 Functions

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

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

virtual ~CloudRenderer()


META_BeginProperties Whether the edge noise effect speed is relative to simulation time If it is relative to real time META_EndProperties 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 cloud query. This returns the previous results of the same query.

Get the results of a previously created lighting 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.

virtual void RecompileShaders()

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

virtual void RestoreDeviceObjects(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.

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

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

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

Render function to draw clouds to the current render target.

virtual void RenderCloudShadowTexture(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 RenderQueries(crossplatform::GraphicsDeviceContext &deviceContext)

Draw the queries in 3D for debugging purposes.

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

Render the cloud volumes for debugging purposes.

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

Render the cloud grid for debugging purposes.

virtual const char *GetDebugText() const

Get some per-frame text information for debugging.

virtual void RenderCrossSections(crossplatform::GraphicsDeviceContext &context)

Show the cloud volumes onscreen by cross section.

inline void SetLightingQueryResult(const LightingQueryResult &_lightingQueryResult)

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

inline virtual simul::clouds::BaseGpuCloudGenerator *GetBaseGpuCloudGenerator()

Get a pointer to the Cloud Generator.

void SetEnvironment(simul::clouds::Environment *e)

Set the sky interface.

CloudGeometryHelper *GetCloudGeometryHelper(int view_id)

Returns a new geometry helper.

virtual crossplatform::Texture *GetRandomTexture3D()

Get the random 3D texture.

bool IsCameraAboveCloudBase(math::Vector3 cam_pos) const

Return true if the camera is above the cloudbase altitude.

float GetSunOcclusion(crossplatform::GraphicsDeviceContext &deviceContext, 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 MakeCloudShadowTexture()

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

void SetMaxFadeDistanceKm(float dist_km)

Distance for fade texture lookups:

void SetMaxFadeAltitudeKm(float ma_km)

Altitude for fade texture lookups:

CloudRenderingOptions &GetCloudRenderingOptions()

Get a pointer to the current cloud rendering options.

void SetCloudRenderingOptions(const CloudRenderingOptions &c)

Set new cloud rendering options.

Public Static Functions

static void EnsureEffectsAreBuilt(crossplatform::RenderPlatform *renderPlatform)

If possible, build all shader effect variations.