Table of Contents

Class SkyboxGenerator

Namespace
Stride.CommunityToolkit.Skyboxes
Assembly
Stride.CommunityToolkit.Skyboxes.dll

Provides functionality to generate a skybox with diffuse and specular lighting parameters from a given texture.

public static class SkyboxGenerator
Inheritance
SkyboxGenerator

Remarks

This class handles the conversion of a texture to a cubemap, performs spherical harmonics filtering for diffuse lighting, and prefilters the texture for specular lighting using GGX reflection. The original logic is from Stride.Assets.Skyboxes

Methods

Generate(Skybox, SkyboxGeneratorContext, Texture, int?)

Generates a skybox using the provided texture and context, applying both diffuse and specular lighting.

public static Skybox Generate(Skybox skybox, SkyboxGeneratorContext context, Texture skyboxTexture, int? specularCubeMapSize = null)

Parameters

skybox Skybox

The skybox instance to apply the generated parameters to.

context SkyboxGeneratorContext

The context required for rendering, which includes services and draw context.

skyboxTexture Texture

The texture used to generate the skybox cubemap. Must be a cubemap or a 2D texture.

specularCubeMapSize int?

Size of the prefiltered specular cubemap, in pixels. Leave null to match the source cubemap, which is the default and is usually what you want - see the remarks. Any value given is rounded to the nearest power of two and floored at 64.

Returns

Skybox

The modified Skybox with diffuse and specular lighting applied.

Remarks

The method performs the following:

  1. Converts the provided texture into a cubemap with a computed resolution based on the texture width.
  2. Applies Lambertian spherical harmonics filtering for diffuse lighting.
  3. Performs GGX prefiltering for specular lighting and generates a cubemap for reflection purposes.

Why the specular cubemap defaults to the source size. Stride's own asset pipeline defaults this to 64, but that is not a free choice here. RadiancePrefilteringGGXNoCompute only copies the sharpest mip straight across when Log2(input.Width / output.Width) < input.MipLevelCount; otherwise it rescales through an image scaler instead. A source cubemap with no mip chain has a level count of one, so that condition holds only when the two widths are equal. Matching the source keeps the roughness-zero mirror level pixel-exact; shrinking it resamples that level and visibly softens reflections. Pass a smaller size deliberately when a large source would otherwise cost more memory than the reflection is worth.

Ownership. The returned skybox holds a GPU cubemap that is not released automatically and does not belong to any content manager. Generating skyboxes repeatedly - once per scene load, say - leaks one each time. To release it:

var cubeMap = skybox.SpecularLightingParameters.Get(SkyboxKeys.CubeMap);
cubeMap?.Dispose();

Exceptions

ArgumentNullException

If any argument is null.

ArgumentException

If skyboxTexture is neither a cubemap nor a 2D texture.