light

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultShadowBias float32 = 0.001

DefaultShadowBias is the constant depth bias applied to shadow comparisons to reduce shadow acne artifacts.

View Source
const DefaultShadowFar float32 = 200.0

DefaultShadowFar is the default far plane for the directional light's orthographic shadow projection.

View Source
const DefaultShadowHalfExtent float32 = 40.0

DefaultShadowHalfExtent is the default orthographic half-extent (in world units) used for the directional light shadow frustum. Controls how much of the scene around the camera center is captured in the shadow map.

View Source
const DefaultShadowNear float32 = 0.1

DefaultShadowNear is the default near plane for the directional light's orthographic shadow projection.

View Source
const DefaultShadowNormalBiasScale float32 = 3.0

DefaultShadowNormalBiasScale is the multiplier applied to the shadow map texel world-size to compute the normal-offset bias. Higher values push the shadow sample point further along the surface normal, reducing self-shadowing on concave geometry at the cost of slight shadow detachment from contact points. Typical values are 2.0–4.0.

View Source
const DefaultVSMBlurRadius int = 4

DefaultVSMBlurRadius is the default half-width (in texels) of the separable blur applied to the variance shadow map. The paper notes a minimum filter width of at least 4 is required to eliminate aliasing. The full kernel width is 2*radius+1 texels.

View Source
const DefaultVSMLightBleedReduction float32 = 0.3

DefaultVSMLightBleedReduction is the exponent applied to the raw Chebyshev shadow probability to reduce light-bleeding artifacts. Higher values reduce light bleeding at the cost of darker shadow interiors. Typical range: 0.1–0.6.

View Source
const DefaultVSMLightSize float32 = 1.0

DefaultVSMLightSize is the default world-space size of the area light used for PCSS penumbra estimation. Larger values produce wider soft-shadow penumbrae. Only relevant when PCSS (Phase 7) is enabled.

View Source
const DefaultVSMMinVariance float32 = 0.00001

DefaultVSMMinVariance is the minimum variance clamped during Chebyshev's inequality evaluation in the VSM sampling shader. Prevents division by near-zero variance from producing hard shadow edges on perfectly planar geometry.

View Source
const MaxGPULights = 1024

MaxGPULights is the maximum number of lights that can be marshaled into the GPU storage buffer per frame. The CPU-side light list is unbounded; this cap controls only how many lights the GPU evaluates. When the active light count exceeds this budget, the scene's light priority system selects the most impactful lights.

View Source
const MaxLightsPerTile = 256

MaxLightsPerTile is the maximum number of light indices stored per tile in the Forward+ tile light index buffer. If more lights overlap a tile, excess lights are silently dropped.

View Source
const ShadowMapResolution = 2048

ShadowMapResolution is the default width and height in texels of the shadow depth texture. Scenes use this as their initial value but can override it via the WithShadowMapResolution builder option.

View Source
const TileSize = 16

TileSize is the width and height in pixels of each screen-space tile used for Forward+ light culling. The screen is divided into a grid of tiles, each TileSize × TileSize pixels, and lights are assigned to tiles via a compute shader so the fragment shader only evaluates lights relevant to each tile.

Variables

View Source
var GPUBlurParamsSource string

GPUBlurParamsSource is the canonical WGSL definition of the BlurParams struct. Matches GPUBlurParams layout exactly (16 bytes, std430 aligned).

View Source
var GPUCompositionParamsSource string

GPUCompositionParamsSource is the canonical WGSL definition of the CompositionParams struct. Matches GPUCompositionParams layout exactly (16 bytes, std140 aligned).

View Source
var GPUGBufferOutputSource string

GPUGBufferOutputSource is the canonical WGSL definition of the GBufferOutput struct. Matches GPUGBufferOutput layout exactly (48 bytes, std430 aligned).

View Source
var GPUIrradianceProbeSource string

GPUIrradianceProbeSource is the canonical WGSL definition of the IrradianceProbe struct. Matches GPUIrradianceProbe layout exactly (160 bytes, std430 aligned).

View Source
var GPULightCullUniformsSource string

GPULightCullUniformsSource is the canonical WGSL definition of the LightCullUniforms struct. Matches GPULightCullUniforms layout exactly (160 bytes, std430 aligned).

View Source
var GPULightHeaderSource string

GPULightHeaderSource is the canonical WGSL definition of the LightHeader struct. Matches GPULightHeader layout exactly (16 bytes, std430 aligned).

View Source
var GPULightSource string

GPULightSource is the canonical WGSL definition of the Light struct. Matches GPULight layout exactly (64 bytes, std430 aligned).

View Source
var GPUProbeBakeCameraSource string

GPUProbeBakeCameraSource is the canonical WGSL definition of the ProbeBakeCamera struct. Matches GPUProbeBakeCamera layout exactly (80 bytes, std430 aligned).

View Source
var GPUProbeGridParamsSource string

GPUProbeGridParamsSource is the canonical WGSL definition of the ProbeGridParams struct. Matches GPUProbeGridParams layout exactly (64 bytes, std430 aligned).

View Source
var GPUSATParamsSource string

GPUSATParamsSource is the canonical WGSL definition of the SATParams struct. Matches GPUSATParams layout exactly (16 bytes, std430 aligned).

View Source
var GPUSHProjectParamsSource string

GPUSHProjectParamsSource is the canonical WGSL definition of the SHProjectParams struct. Matches GPUSHProjectParams layout exactly (16 bytes, std140 aligned).

View Source
var GPUSSAOParamsSource string

GPUSSAOParamsSource is the canonical WGSL definition of the SSAOParams struct. Matches GPUSSAOParams layout exactly (176 bytes, std430 aligned).

View Source
var GPUSSRParamsSource string

GPUSSRParamsSource is the canonical WGSL definition of the SSRParams struct. Matches GPUSSRParams layout exactly (64 bytes, std140 aligned).

View Source
var GPUShadowDataSource string

GPUShadowDataSource is the canonical WGSL definition of the ShadowData struct. Matches GPUShadowData layout exactly (176 bytes, std430 aligned).

View Source
var GPUShadowUniformSource string

GPUShadowUniformSource is the canonical WGSL definition of the ShadowUniform struct. Matches GPUShadowUniform layout exactly (136 bytes, std430 aligned).

View Source
var GPUTileUniformsSource string

GPUTileUniformsSource is the canonical WGSL definition of the TileUniforms struct. Matches GPUTileUniforms layout exactly (8 bytes).

Functions

func MarshalLightBuffer

func MarshalLightBuffer(lights []Light, ambient [3]float32) []byte

MarshalLightBuffer marshals a slice of enabled lights into a byte buffer suitable for GPU upload. The buffer layout is:

[GPULightHeader (16 bytes)] [GPULight × count (64 bytes each)]

Only enabled lights are included, up to MaxGPULights. Lights beyond the budget are silently dropped; callers should pre-sort by priority if truncation is expected.

Parameters:

  • lights: the full slice of lights to marshal (only enabled lights are included)
  • ambient: the scene ambient color as RGB

Returns:

  • []byte: the marshaled buffer ready for GPU upload

func MarshalProbeBuffer added in v0.2.0

func MarshalProbeBuffer(probes []GPUIrradianceProbe) []byte

MarshalProbeBuffer marshals a slice of irradiance probes into a byte buffer suitable for GPU storage buffer upload. The layout is a tightly-packed array of GPUIrradianceProbe structs.

Parameters:

  • probes: the slice of probes to marshal

Returns:

  • []byte: the marshaled buffer ready for GPU upload

func TileCounts

func TileCounts(screenWidth, screenHeight int) (tileCountX, tileCountY uint32)

TileCounts computes the number of tiles in each dimension for a given screen resolution and the configured TileSize.

Parameters:

  • screenWidth: screen width in pixels
  • screenHeight: screen height in pixels

Returns:

  • tileCountX: number of tile columns
  • tileCountY: number of tile rows

Types

type CompositionHandler added in v0.2.0

type CompositionHandler interface {
	// Enabled returns whether the composition subsystem has been GPU-initialized
	// and is ready for rendering.
	//
	// Returns:
	//   - bool: true if composition GPU resources have been initialized
	Enabled() bool

	// SetEnabled sets whether the composition subsystem is GPU-initialized.
	//
	// Parameters:
	//   - enabled: true to mark as initialized
	SetEnabled(enabled bool)

	// ScreenWidth returns the current screen width in pixels used for texture sizing.
	//
	// Returns:
	//   - int: the screen width
	ScreenWidth() int

	// ScreenHeight returns the current screen height in pixels used for texture sizing.
	//
	// Returns:
	//   - int: the screen height
	ScreenHeight() int

	// ToneMappingEnabled returns whether ACES tone mapping is applied during composition.
	//
	// Returns:
	//   - bool: true if tone mapping is enabled
	ToneMappingEnabled() bool

	// Exposure returns the exposure multiplier applied to HDR values before tone mapping.
	//
	// Returns:
	//   - float32: the current exposure value
	Exposure() float32

	// SetExposure sets the exposure multiplier applied to HDR values before tone mapping.
	//
	// Parameters:
	//   - exposure: the exposure multiplier (1.0 = neutral)
	SetExposure(exposure float32)

	// PipelineKey retrieves the pipeline key associated with the given name.
	// Returns an empty string if the name does not exist.
	//
	// Parameters:
	//   - name: the pipeline name
	//
	// Returns:
	//   - string: the pipeline key, or empty if not found
	PipelineKey(name string) string

	// PipelineKeys returns the full map of pipeline keys.
	//
	// Returns:
	//   - map[string]string: all registered pipeline name-to-key mappings
	PipelineKeys() map[string]string

	// SetPipelineKey stores a pipeline key under the given name.
	//
	// Parameters:
	//   - name: the pipeline name
	//   - key: the pipeline key
	SetPipelineKey(name, key string)

	// Bgp retrieves the bind group provider associated with the given key.
	// Returns nil if the key does not exist.
	//
	// Parameters:
	//   - key: the bind group provider name
	//
	// Returns:
	//   - bind_group_provider.BindGroupProvider: the provider, or nil if not found
	Bgp(key string) bind_group_provider.BindGroupProvider

	// Bgps returns the full map of bind group providers.
	//
	// Returns:
	//   - map[string]bind_group_provider.BindGroupProvider: all registered providers
	Bgps() map[string]bind_group_provider.BindGroupProvider

	// SetBgp stores a bind group provider under the given key.
	//
	// Parameters:
	//   - key: the bind group provider name
	//   - bgp: the bind group provider
	SetBgp(key string, bgp bind_group_provider.BindGroupProvider)

	// HDRTexture returns the RGBA16Float offscreen render target that the lit
	// pass writes to when composition is active.
	//
	// Returns:
	//   - *wgpu.Texture: the HDR texture, or nil if not initialized
	HDRTexture() *wgpu.Texture

	// SetHDRTexture sets the HDR offscreen render target texture.
	//
	// Parameters:
	//   - t: the HDR texture
	SetHDRTexture(t *wgpu.Texture)

	// HDRTextureView returns the texture view for the HDR render target.
	//
	// Returns:
	//   - *wgpu.TextureView: the HDR texture view, or nil if not initialized
	HDRTextureView() *wgpu.TextureView

	// SetHDRTextureView sets the texture view for the HDR render target.
	//
	// Parameters:
	//   - tv: the HDR texture view
	SetHDRTextureView(tv *wgpu.TextureView)

	// MSAATexture returns the multi-sampled RGBA16Float texture used as the
	// lit pass color attachment when MSAA is enabled. Resolves into the HDR texture.
	//
	// Returns:
	//   - *wgpu.Texture: the MSAA texture, or nil if MSAA is off or not initialized
	MSAATexture() *wgpu.Texture

	// SetMSAATexture sets the MSAA resolve source texture.
	//
	// Parameters:
	//   - t: the MSAA texture
	SetMSAATexture(t *wgpu.Texture)

	// MSAATextureView returns the texture view for the MSAA texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the MSAA texture view, or nil if MSAA is off or not initialized
	MSAATextureView() *wgpu.TextureView

	// SetMSAATextureView sets the texture view for the MSAA texture.
	//
	// Parameters:
	//   - tv: the MSAA texture view
	SetMSAATextureView(tv *wgpu.TextureView)

	// DepthTexture returns the depth texture for the offscreen HDR render pass.
	//
	// Returns:
	//   - *wgpu.Texture: the depth texture, or nil if not initialized
	DepthTexture() *wgpu.Texture

	// SetDepthTexture sets the depth texture for the offscreen HDR render pass.
	//
	// Parameters:
	//   - t: the depth texture
	SetDepthTexture(t *wgpu.Texture)

	// DepthTextureView returns the texture view for the offscreen depth texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the depth texture view, or nil if not initialized
	DepthTextureView() *wgpu.TextureView

	// SetDepthTextureView sets the texture view for the offscreen depth texture.
	//
	// Parameters:
	//   - tv: the depth texture view
	SetDepthTextureView(tv *wgpu.TextureView)

	// LinearSampler returns the linear sampler used for sampling the HDR and SSR
	// textures in the composition fragment shader.
	//
	// Returns:
	//   - *wgpu.Sampler: the linear sampler, or nil if not initialized
	LinearSampler() *wgpu.Sampler

	// SetLinearSampler sets the linear sampler for composition texture sampling.
	//
	// Parameters:
	//   - s: the linear sampler
	SetLinearSampler(s *wgpu.Sampler)

	// Resize updates the screen dimensions for texture sizing. Existing
	// textures are not automatically recreated — call the appropriate texture
	// creation method if the dimensions change while the handler is enabled.
	//
	// Parameters:
	//   - width: the new screen width in pixels
	//   - height: the new screen height in pixels
	Resize(width, height int)
}

CompositionHandler defines the interface for the scene's composition and tone mapping subsystem.

The CompositionHandler manages the offscreen HDR render target, the full-screen composition pipeline, and tone mapping configuration. When composition is active, the lit pass renders to an RGBA16Float offscreen texture instead of the swapchain. A final full-screen pass then samples the HDR result along with any SSR texture, applies ACES tone mapping and gamma correction, and writes to the swapchain.

Thread safety is provided by the owning scene's mutex — the handler itself does not perform internal locking.

func NewCompositionHandler added in v0.2.0

func NewCompositionHandler(opts ...CompositionHandlerOption) CompositionHandler

NewCompositionHandler creates a new CompositionHandler with sensible defaults and any provided options applied. GPU resources are not allocated until the owning scene calls the appropriate initialization methods.

Default values:

  • ToneMappingEnabled: true
  • Exposure: 1.0

Parameters:

  • opts: variadic list of CompositionHandlerOption functions to configure the handler

Returns:

  • CompositionHandler: a new handler instance ready to be attached to a scene

type CompositionHandlerOption added in v0.2.0

type CompositionHandlerOption func(*compositionHandlerImpl)

CompositionHandlerOption is a functional option for configuring a CompositionHandler during construction via NewCompositionHandler.

func WithCompositionScreenSize added in v0.2.0

func WithCompositionScreenSize(width, height int) CompositionHandlerOption

WithCompositionScreenSize sets the initial screen dimensions used for HDR texture allocation. These should match the surface dimensions at the time of initialization.

Parameters:

  • width: the screen width in pixels
  • height: the screen height in pixels

Returns:

  • CompositionHandlerOption: a function that applies the screen size option to a compositionHandlerImpl

func WithExposure added in v0.2.0

func WithExposure(exposure float32) CompositionHandlerOption

WithExposure sets the exposure multiplier applied to HDR values before tone mapping. Higher values brighten the final image. A value of 1.0 is neutral.

Parameters:

  • exposure: the exposure multiplier

Returns:

  • CompositionHandlerOption: a function that applies the exposure option to a compositionHandlerImpl

func WithToneMappingEnabled added in v0.2.0

func WithToneMappingEnabled(enabled bool) CompositionHandlerOption

WithToneMappingEnabled enables or disables ACES tone mapping during the composition pass. When disabled, the HDR texture is passed through with only gamma correction applied.

Parameters:

  • enabled: true to enable ACES tone mapping

Returns:

  • CompositionHandlerOption: a function that applies the tone mapping option to a compositionHandlerImpl

type GBufferHandler added in v0.2.0

type GBufferHandler interface {
	// Enabled returns whether the G-Buffer subsystem has been GPU-initialized
	// and is ready for rendering.
	//
	// Returns:
	//   - bool: true if G-Buffer GPU resources have been initialized
	Enabled() bool

	// SetEnabled sets whether the G-Buffer subsystem is GPU-initialized.
	//
	// Parameters:
	//   - enabled: true to mark as initialized
	SetEnabled(enabled bool)

	// ScreenWidth returns the current screen width in pixels used for texture sizing.
	//
	// Returns:
	//   - int: the screen width
	ScreenWidth() int

	// ScreenHeight returns the current screen height in pixels used for texture sizing.
	//
	// Returns:
	//   - int: the screen height
	ScreenHeight() int

	// PipelineKey retrieves the pipeline key associated with the given name.
	// Returns an empty string if the name does not exist.
	//
	// Parameters:
	//   - name: the pipeline name
	//
	// Returns:
	//   - string: the pipeline key, or empty if not found
	PipelineKey(name string) string

	// PipelineKeys returns the full map of pipeline keys.
	//
	// Returns:
	//   - map[string]string: all registered pipeline name-to-key mappings
	PipelineKeys() map[string]string

	// SetPipelineKey stores a pipeline key under the given name.
	//
	// Parameters:
	//   - name: the pipeline name
	//   - key: the pipeline key
	SetPipelineKey(name, key string)

	// PositionTexture returns the RGBA16Float texture storing world-space
	// position (XYZ) and linear depth (W).
	//
	// Returns:
	//   - *wgpu.Texture: the position texture, or nil if not initialized
	PositionTexture() *wgpu.Texture

	// SetPositionTexture sets the position MRT texture.
	//
	// Parameters:
	//   - t: the position texture
	SetPositionTexture(t *wgpu.Texture)

	// PositionTextureView returns the texture view for the position texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the position texture view, or nil if not initialized
	PositionTextureView() *wgpu.TextureView

	// SetPositionTextureView sets the texture view for the position texture.
	//
	// Parameters:
	//   - tv: the position texture view
	SetPositionTextureView(tv *wgpu.TextureView)

	// NormalTexture returns the RGBA16Float texture storing world-space
	// normals (XYZ packed to [0,1]) and roughness (W).
	//
	// Returns:
	//   - *wgpu.Texture: the normal texture, or nil if not initialized
	NormalTexture() *wgpu.Texture

	// SetNormalTexture sets the normal MRT texture.
	//
	// Parameters:
	//   - t: the normal texture
	SetNormalTexture(t *wgpu.Texture)

	// NormalTextureView returns the texture view for the normal texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the normal texture view, or nil if not initialized
	NormalTextureView() *wgpu.TextureView

	// SetNormalTextureView sets the texture view for the normal texture.
	//
	// Parameters:
	//   - tv: the normal texture view
	SetNormalTextureView(tv *wgpu.TextureView)

	// AlbedoTexture returns the RGBA8Unorm texture storing albedo (RGB)
	// and metallic (A).
	//
	// Returns:
	//   - *wgpu.Texture: the albedo texture, or nil if not initialized
	AlbedoTexture() *wgpu.Texture

	// SetAlbedoTexture sets the albedo MRT texture.
	//
	// Parameters:
	//   - t: the albedo texture
	SetAlbedoTexture(t *wgpu.Texture)

	// AlbedoTextureView returns the texture view for the albedo texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the albedo texture view, or nil if not initialized
	AlbedoTextureView() *wgpu.TextureView

	// SetAlbedoTextureView sets the texture view for the albedo texture.
	//
	// Parameters:
	//   - tv: the albedo texture view
	SetAlbedoTextureView(tv *wgpu.TextureView)

	// DepthTexture returns the Depth24Plus texture used for depth testing
	// during the G-Buffer pass.
	//
	// Returns:
	//   - *wgpu.Texture: the depth texture, or nil if not initialized
	DepthTexture() *wgpu.Texture

	// SetDepthTexture sets the depth texture for the G-Buffer pass.
	//
	// Parameters:
	//   - t: the depth texture
	SetDepthTexture(t *wgpu.Texture)

	// DepthTextureView returns the texture view for the G-Buffer depth texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the depth texture view, or nil if not initialized
	DepthTextureView() *wgpu.TextureView

	// SetDepthTextureView sets the texture view for the G-Buffer depth texture.
	//
	// Parameters:
	//   - tv: the depth texture view
	SetDepthTextureView(tv *wgpu.TextureView)

	// Resize updates the screen dimensions for texture sizing. Existing
	// textures are not automatically recreated — call the appropriate texture
	// creation method if the dimensions change while the handler is enabled.
	//
	// Parameters:
	//   - width: the new screen width in pixels
	//   - height: the new screen height in pixels
	Resize(width, height int)
}

GBufferHandler defines the interface for the scene's G-Buffer subsystem.

The GBufferHandler manages the multiple render target (MRT) textures that store per-pixel geometric and material data written during the G-Buffer pre-pass. These textures are consumed by downstream screen-space effect passes such as SSAO and SSR. GPU resources are initialized lazily by the owning scene when GI features are first enabled.

Thread safety is provided by the owning scene's mutex — the handler itself does not perform internal locking.

func NewGBufferHandler added in v0.2.0

func NewGBufferHandler(opts ...GBufferHandlerOption) GBufferHandler

NewGBufferHandler creates a new GBufferHandler with sensible defaults and any provided options applied. GPU resources are not allocated until the owning scene calls the appropriate initialization methods.

Parameters:

  • opts: variadic list of GBufferHandlerOption functions to configure the handler

Returns:

  • GBufferHandler: a new handler instance ready to be attached to a scene

type GBufferHandlerOption added in v0.2.0

type GBufferHandlerOption func(*gBufferHandlerImpl)

GBufferHandlerOption is a functional option for configuring a GBufferHandler during construction via NewGBufferHandler.

func WithGBufferScreenSize added in v0.2.0

func WithGBufferScreenSize(width, height int) GBufferHandlerOption

WithGBufferScreenSize sets the initial screen dimensions used for G-Buffer texture allocation. These should match the surface dimensions at the time of initialization.

Parameters:

  • width: the screen width in pixels
  • height: the screen height in pixels

Returns:

  • GBufferHandlerOption: a function that applies the screen size option to a gBufferHandlerImpl

type GPUBlurParams added in v0.2.0

type GPUBlurParams struct {
	Direction    [2]int32 // (1,0) for horizontal, (0,1) for vertical
	Radius       int32    // half-width of the box filter kernel in texels
	GBufferScale int32    // coordinate multiplier for depth texture lookups (1 = full-res, 2 = half-res SSAO)
}

GPUBlurParams is the GPU-aligned representation of the separable blur compute shader uniform. Controls the blur direction, kernel half-width, and an optional G-Buffer coordinate scale for half-resolution SSAO. Matches the WGSL BlurParams struct layout exactly (see GPUBlurParamsSource). Size: 16 bytes (vec2<i32> + i32 + i32).

Layout:

vec2<i32> direction     (8 bytes, offset  0)
i32       radius        (4 bytes, offset  8)
i32       gbuffer_scale (4 bytes, offset 12)

func (*GPUBlurParams) Marshal added in v0.2.0

func (p *GPUBlurParams) Marshal() []byte

Marshal serializes the GPUBlurParams struct into a byte buffer suitable for GPU upload.

Returns:

  • []byte: 16-byte buffer ready for GPU upload

func (*GPUBlurParams) Size added in v0.2.0

func (p *GPUBlurParams) Size() int

Size returns the size of the GPUBlurParams struct in bytes.

Returns:

  • int: the struct size in bytes (16)

type GPUCompositionParams added in v0.2.0

type GPUCompositionParams struct {
	ToneMappingEnabled uint32
	Exposure           float32
	// contains filtered or unexported fields
}

GPUCompositionParams is the GPU-aligned uniform data for the composition fragment shader. Contains a flag controlling whether ACES tone mapping is applied and an exposure multiplier that scales HDR values before tone mapping. Matches the WGSL CompositionParams struct layout exactly (see GPUCompositionParamsSource). Size: 16 bytes.

Layout:

u32 tone_mapping_enabled  (4 bytes, offset  0)
f32 exposure              (4 bytes, offset  4)
u32 _pad1                 (4 bytes, offset  8)
u32 _pad2                 (4 bytes, offset 12)

func (*GPUCompositionParams) Marshal added in v0.2.0

func (p *GPUCompositionParams) Marshal() []byte

Marshal serializes the GPUCompositionParams struct into a byte buffer suitable for GPU uniform buffer upload.

Returns:

  • []byte: the marshaled buffer ready for GPU upload

func (*GPUCompositionParams) Size added in v0.2.0

func (p *GPUCompositionParams) Size() int

Size returns the size of the GPUCompositionParams struct in bytes.

Returns:

  • int: the size in bytes (16)

type GPUGBufferOutput added in v0.2.0

type GPUGBufferOutput struct {
	Position [4]float32 // offset  0: world XYZ + linear depth in W (16 bytes)
	Normal   [4]float32 // offset 16: world normal XYZ (packed [0,1]) + roughness in W (16 bytes)
	Albedo   [4]float32 // offset 32: albedo RGB + metallic in A (16 bytes)
}

GPUGBufferOutput is the GPU-aligned representation of a single G-Buffer fragment output. Matches the WGSL GBufferOutput struct layout exactly (see GPUGBufferOutputSource). This struct is written by the G-Buffer MRT fragment shader and is not typically uploaded from the CPU, but Marshal/Size are provided for readback and testing. Size: 48 bytes (3 × vec4<f32>).

func (*GPUGBufferOutput) Marshal added in v0.2.0

func (g *GPUGBufferOutput) Marshal() []byte

Marshal serializes the GPUGBufferOutput struct into a byte buffer suitable for GPU readback validation or testing.

Returns:

  • []byte: 48-byte buffer matching the GPU layout

func (*GPUGBufferOutput) Size added in v0.2.0

func (g *GPUGBufferOutput) Size() int

Size returns the size of the GPUGBufferOutput struct in bytes.

Returns:

  • int: the struct size in bytes (48)

type GPUIrradianceProbe added in v0.2.0

type GPUIrradianceProbe struct {
	Position [4]float32  // offset   0: world xyz + status flags in w (0=inactive, 1=active)
	SH_R     [12]float32 // offset  16: L2 SH coefficients for red (indices 0-8 used, 9-11 padding)
	SH_G     [12]float32 // offset  64: L2 SH coefficients for green (indices 0-8 used, 9-11 padding)
	SH_B     [12]float32 // offset 112: L2 SH coefficients for blue (indices 0-8 used, 9-11 padding)
}

GPUIrradianceProbe is the GPU-aligned representation of a single irradiance probe storing L2 spherical harmonics (9 coefficients per RGB channel). Each channel is stored as an array<f32, 12> — the first 9 elements are the SH coefficients and the last 3 are padding to maintain 16-byte alignment. Matches the WGSL IrradianceProbe struct layout exactly (see GPUIrradianceProbeSource). Size: 160 bytes (vec4 + 3 × array<f32, 12>).

Layout:

vec4<f32>       position  (16 bytes, offset   0) — world xyz + status in w
array<f32, 12>  sh_r      (48 bytes, offset  16) — L2 SH red (9 used + 3 pad)
array<f32, 12>  sh_g      (48 bytes, offset  64) — L2 SH green (9 used + 3 pad)
array<f32, 12>  sh_b      (48 bytes, offset 112) — L2 SH blue (9 used + 3 pad)

func (*GPUIrradianceProbe) Marshal added in v0.2.0

func (p *GPUIrradianceProbe) Marshal() []byte

Marshal serializes the GPUIrradianceProbe struct into a byte buffer suitable for GPU storage buffer upload.

Returns:

  • []byte: 160-byte buffer ready for GPU upload

func (*GPUIrradianceProbe) Size added in v0.2.0

func (p *GPUIrradianceProbe) Size() int

Size returns the size of the GPUIrradianceProbe struct in bytes.

Returns:

  • int: the struct size in bytes (160)

type GPULight

type GPULight struct {
	Position     [3]float32 // offset  0: world-space position (point/spot) or unused (directional)
	LightType    uint32     // offset 12: 0 = directional, 1 = point, 2 = spot
	Color        [3]float32 // offset 16: RGB color
	Intensity    float32    // offset 28: scalar multiplier
	Direction    [3]float32 // offset 32: normalized direction (directional/spot) or unused (point)
	LightRange   float32    // offset 44: attenuation cutoff distance
	InnerCone    float32    // offset 48: cos(inner half-angle) for spot
	OuterCone    float32    // offset 52: cos(outer half-angle) for spot
	CastsShadows uint32     // offset 56: 1 = casts shadows, 0 = does not
	// contains filtered or unexported fields
}

GPULight is the GPU-aligned representation of a single light source. Matches the WGSL Light struct layout exactly (see GPULightSource). Size: 64 bytes (std430 / WGSL aligned).

func ToGPULight

func ToGPULight(l Light) GPULight

ToGPULight converts a Light interface value into the GPU-aligned GPULight struct suitable for writing into the light storage buffer.

Parameters:

  • l: the Light to convert

Returns:

  • GPULight: the GPU-aligned representation

func (*GPULight) Marshal

func (g *GPULight) Marshal() []byte

Marshal serializes the GPULight struct into a byte buffer suitable for GPU upload.

Returns:

  • []byte: 64-byte buffer ready for GPU upload

func (*GPULight) Size

func (g *GPULight) Size() int

Size returns the size of the GPULight struct in bytes.

Returns:

  • int: the struct size in bytes (64)

type GPULightCullUniforms

type GPULightCullUniforms struct {
	InvProj      [16]float32 // inverse projection matrix
	ViewMatrix   [16]float32 // camera view matrix
	TileCountX   uint32
	TileCountY   uint32
	ScreenWidth  uint32
	ScreenHeight uint32
	LightCount   uint32
	Near         float32
	Far          float32
	// contains filtered or unexported fields
}

GPULightCullUniforms is the GPU-aligned uniform data for the light culling compute shader. Contains the inverse projection and view matrices needed to reconstruct per-tile frustum planes, plus tile/screen dimensions and the active light count. Matches the WGSL LightCullUniforms struct layout exactly (see GPULightCullUniformsSource). Size: 160 bytes (std430 / WGSL aligned).

Layout:

mat4x4<f32> inv_proj       (64 bytes, offset  0)
mat4x4<f32> view_matrix    (64 bytes, offset 64)
u32         tile_count_x   ( 4 bytes, offset 128)
u32         tile_count_y   ( 4 bytes, offset 132)
u32         screen_width   ( 4 bytes, offset 136)
u32         screen_height  ( 4 bytes, offset 140)
u32         light_count    ( 4 bytes, offset 144)
f32         near           ( 4 bytes, offset 148)
f32         far            ( 4 bytes, offset 152)
u32         _pad           ( 4 bytes, offset 156)

func (*GPULightCullUniforms) Marshal

func (u *GPULightCullUniforms) Marshal() []byte

Marshal serializes GPULightCullUniforms into a 160-byte little-endian buffer suitable for GPU upload.

Returns:

  • []byte: 160-byte buffer ready for GPU upload

func (*GPULightCullUniforms) Size

func (u *GPULightCullUniforms) Size() int

Size returns the size of the GPULightCullUniforms struct in bytes.

Returns:

  • int: the struct size in bytes (160)

type GPULightHeader

type GPULightHeader struct {
	AmbientColor [3]float32 // offset 0: scene ambient RGB
	LightCount   uint32     // offset 12: number of active lights following the header
}

GPULightHeader is the header prepended to the light storage buffer. Contains the ambient color and the active light count. Matches the WGSL LightHeader struct layout exactly (see GPULightHeaderSource). Size: 16 bytes (vec3 + u32, std430 aligned).

func (*GPULightHeader) Marshal

func (h *GPULightHeader) Marshal() []byte

Marshal serializes the GPULightHeader struct into a byte buffer suitable for GPU upload.

Returns:

  • []byte: 16-byte buffer ready for GPU upload

func (*GPULightHeader) Size

func (h *GPULightHeader) Size() int

Size returns the size of the GPULightHeader struct in bytes.

Returns:

  • int: the struct size in bytes (16)

type GPUProbeBakeCamera added in v0.2.0

type GPUProbeBakeCamera struct {
	ViewProj       [16]float32 // offset  0: cubemap face view-projection matrix (column-major)
	CameraPosition [3]float32  // offset 64: probe world-space position
	// contains filtered or unexported fields
}

GPUProbeBakeCamera is the GPU-aligned representation of the camera uniform used during probe cubemap baking. It contains a combined view-projection matrix and the probe's world-space position (used as the camera origin for specular calculations in the bake shader). Matches the WGSL ProbeBakeCamera struct layout exactly (see GPUProbeBakeCameraSource). Size: 80 bytes (mat4x4 + vec3 + pad).

Layout:

mat4x4<f32> view_proj        (64 bytes, offset  0)
vec3<f32>   camera_position  (12 bytes, offset 64)
f32         _pad             ( 4 bytes, offset 76)

func (*GPUProbeBakeCamera) Marshal added in v0.2.0

func (c *GPUProbeBakeCamera) Marshal() []byte

Marshal serializes the GPUProbeBakeCamera struct into a byte buffer suitable for GPU uniform upload.

Returns:

  • []byte: 80-byte buffer ready for GPU upload

func (*GPUProbeBakeCamera) Size added in v0.2.0

func (c *GPUProbeBakeCamera) Size() int

Size returns the size of the GPUProbeBakeCamera struct in bytes.

Returns:

  • int: the struct size in bytes (80)

type GPUProbeGridParams added in v0.2.0

type GPUProbeGridParams struct {
	GridMin     [3]float32 // offset  0: world-space minimum corner of the probe grid
	ProbeCountX uint32     // offset 12: number of probes along the X axis
	GridMax     [3]float32 // offset 16: world-space maximum corner of the probe grid
	ProbeCountY uint32     // offset 28: number of probes along the Y axis
	Spacing     [3]float32 // offset 32: world-space distance between adjacent probes per axis
	ProbeCountZ uint32     // offset 44: number of probes along the Z axis
	TotalProbes uint32     // offset 48: total number of probes (X × Y × Z)
	// contains filtered or unexported fields
}

GPUProbeGridParams is the GPU-aligned uniform data describing the layout of the irradiance probe grid. The lit fragment shader uses these parameters to compute which probes surround a given world-space fragment position and to perform trilinear interpolation of SH data. Matches the WGSL ProbeGridParams struct layout exactly (see GPUProbeGridParamsSource). Size: 80 bytes (WGSL-aligned). In WGSL, vec3<u32> has alignment 16, so after total_probes at offset 52, the _pad field is aligned to offset 64. The struct's overall alignment is 16 so total size rounds to 80.

Layout (WGSL byte offsets):

vec3<f32> grid_min       (12 bytes, offset  0)
u32       probe_count_x  ( 4 bytes, offset 12)
vec3<f32> grid_max       (12 bytes, offset 16)
u32       probe_count_y  ( 4 bytes, offset 28)
vec3<f32> spacing        (12 bytes, offset 32)
u32       probe_count_z  ( 4 bytes, offset 44)
u32       total_probes   ( 4 bytes, offset 48)
           implicit pad  (12 bytes, offset 52) — align _pad to 16
vec3<u32> _pad           (12 bytes, offset 64)
           trailing pad  ( 4 bytes, offset 76) — align struct to 16

func (*GPUProbeGridParams) Marshal added in v0.2.0

func (p *GPUProbeGridParams) Marshal() []byte

Marshal serializes the GPUProbeGridParams struct into a byte buffer suitable for GPU uniform upload.

Returns:

  • []byte: 80-byte buffer ready for GPU upload

func (*GPUProbeGridParams) Size added in v0.2.0

func (p *GPUProbeGridParams) Size() int

Size returns the size of the GPUProbeGridParams struct in bytes.

Returns:

  • int: the struct size in bytes (80)

type GPUSATParams added in v0.2.0

type GPUSATParams struct {
	Direction [2]int32 // (1,0) for horizontal, (0,1) for vertical
	Offset    int32    // 2^k step offset for recursive doubling; 0 = precision distribution pass
	// contains filtered or unexported fields
}

GPUSATParams is the GPU-aligned representation of the SAT (Summed-Area Table) compute shader uniform. Controls the prefix-sum direction and step offset. When Offset is 0, the shader performs precision distribution from the RG32Float moments texture into RGBA32Float; when Offset > 0, it performs a standard recursive-doubling prefix-sum step. Matches the WGSL SATParams struct layout exactly (see GPUSATParamsSource). Size: 16 bytes (vec2<i32> + i32 + i32 padding).

Layout:

vec2<i32> direction  (8 bytes, offset  0)
i32       offset     (4 bytes, offset  8)
i32       _pad       (4 bytes, offset 12)

func (*GPUSATParams) Marshal added in v0.2.0

func (p *GPUSATParams) Marshal() []byte

Marshal serializes the GPUSATParams struct into a byte buffer suitable for GPU upload.

Returns:

  • []byte: 16-byte buffer ready for GPU upload

func (*GPUSATParams) Size added in v0.2.0

func (p *GPUSATParams) Size() int

Size returns the size of the GPUSATParams struct in bytes.

Returns:

  • int: the struct size in bytes (16)

type GPUSHProjectParams added in v0.2.0

type GPUSHProjectParams struct {
	ProbeIndex uint32
	FaceIndex  uint32
	Resolution uint32
	// contains filtered or unexported fields
}

GPUSHProjectParams is the GPU-aligned representation of the SH projection compute shader uniform parameters. It identifies the target probe, the cubemap face being projected, and the bake resolution. Matches the WGSL SHProjectParams struct layout exactly (see GPUSHProjectParamsSource). Size: 16 bytes.

Layout:

u32 probe_index  (4 bytes, offset  0)
u32 face_index   (4 bytes, offset  4)
u32 resolution   (4 bytes, offset  8)
u32 _pad         (4 bytes, offset 12)

func (*GPUSHProjectParams) Marshal added in v0.2.0

func (p *GPUSHProjectParams) Marshal() []byte

Marshal serializes the GPUSHProjectParams struct into a byte buffer suitable for GPU uniform buffer upload.

Returns:

  • []byte: the marshaled buffer ready for GPU upload

func (*GPUSHProjectParams) Size added in v0.2.0

func (p *GPUSHProjectParams) Size() int

Size returns the size of the GPUSHProjectParams struct in bytes.

Returns:

  • int: the size in bytes (16)

type GPUSSAOParams added in v0.2.0

type GPUSSAOParams struct {
	Projection   [16]float32 // offset   0: view-projection matrix (column-major)
	InvViewProj  [16]float32 // offset  64: inverse view-projection matrix (column-major)
	Radius       float32     // offset 128: hemisphere sample radius in world units
	Bias         float32     // offset 132: depth comparison bias to prevent self-occlusion
	Power        float32     // offset 136: exponent applied to the final AO value
	SampleCount  uint32      // offset 140: number of hemisphere samples (max 32)
	ScreenWidth  float32     // offset 144: screen width in pixels (SSAO output resolution)
	ScreenHeight float32     // offset 148: screen height in pixels (SSAO output resolution)
	GBufferScale float32     // offset 152: coordinate multiplier for G-Buffer texture lookups (1.0 = full-res, 2.0 = half-res)

	CameraPosition [3]float32 // offset 160: world-space camera position for linear depth computation
	// contains filtered or unexported fields
}

GPUSSAOParams is the GPU-aligned uniform data for the SSAO compute shader. Contains the view-projection and inverse view-projection matrices needed to project world-space samples and reconstruct world positions from depth, plus SSAO quality parameters, screen dimensions, and camera position. Matches the WGSL SSAOParams struct layout exactly (see GPUSSAOParamsSource). Size: 176 bytes (std430 / WGSL aligned).

Layout:

mat4x4<f32> projection        (64 bytes, offset   0)
mat4x4<f32> inv_view_proj     (64 bytes, offset  64)
f32         radius            ( 4 bytes, offset 128)
f32         bias              ( 4 bytes, offset 132)
f32         power             ( 4 bytes, offset 136)
u32         sample_count      ( 4 bytes, offset 140)
f32         screen_width      ( 4 bytes, offset 144)
f32         screen_height     ( 4 bytes, offset 148)
f32         gbuffer_scale     ( 4 bytes, offset 152)
f32         _pad              ( 4 bytes, offset 156)
vec3<f32>   camera_position   (12 bytes, offset 160)
f32         _pad2             ( 4 bytes, offset 172)

func (*GPUSSAOParams) Marshal added in v0.2.0

func (p *GPUSSAOParams) Marshal() []byte

Marshal serializes the GPUSSAOParams struct into a byte buffer suitable for GPU upload.

Returns:

  • []byte: 176-byte buffer ready for GPU upload

func (*GPUSSAOParams) Size added in v0.2.0

func (p *GPUSSAOParams) Size() int

Size returns the size of the GPUSSAOParams struct in bytes.

Returns:

  • int: the struct size in bytes (176)

type GPUSSRParams added in v0.2.0

type GPUSSRParams struct {
	Projection      [16]float32 // offset   0: projection matrix (column-major)
	InvProjection   [16]float32 // offset  64: inverse projection matrix (column-major)
	View            [16]float32 // offset 128: view matrix (column-major)
	MaxDistance     float32     // offset 192: maximum ray march distance in view space
	Thickness       float32     // offset 196: depth thickness tolerance for hit detection
	Stride          float32     // offset 200: step stride multiplier for ray march (unused in Hi-Z mode)
	MaxSteps        uint32      // offset 204: maximum number of ray march steps
	ScreenWidth     float32     // offset 208: screen width in pixels
	ScreenHeight    float32     // offset 212: screen height in pixels
	RoughnessCutoff float32     // offset 216: roughness above which SSR is skipped
	HiZMipCount     uint32      // offset 220: number of Hi-Z mip levels in the depth pyramid
}

GPUSSRParams is the GPU-aligned uniform data for the screen-space reflections compute shader. Contains the projection, inverse projection, and view matrices along with ray march configuration parameters. Matches the WGSL SSRParams struct layout exactly (see GPUSSRParamsSource). Size: 224 bytes.

Layout:

mat4x4<f32> projection      (64 bytes, offset   0)
mat4x4<f32> inv_projection  (64 bytes, offset  64)
mat4x4<f32> view            (64 bytes, offset 128)
f32         max_distance    ( 4 bytes, offset 192)
f32         thickness       ( 4 bytes, offset 196)
f32         stride          ( 4 bytes, offset 200)
u32         max_steps       ( 4 bytes, offset 204)
f32         screen_width    ( 4 bytes, offset 208)
f32         screen_height   ( 4 bytes, offset 212)
f32         roughness_cutoff( 4 bytes, offset 216)
u32         hiz_mip_count   ( 4 bytes, offset 220)

func (*GPUSSRParams) Marshal added in v0.2.0

func (p *GPUSSRParams) Marshal() []byte

Marshal serializes the GPUSSRParams struct into a byte buffer suitable for GPU upload.

Returns:

  • []byte: 224-byte buffer ready for GPU upload

func (*GPUSSRParams) Size added in v0.2.0

func (p *GPUSSRParams) Size() int

Size returns the size of the GPUSSRParams struct in bytes.

Returns:

  • int: the size in bytes (224)

type GPUShadowData

type GPUShadowData struct {
	LightVP             [16]float32 // orthographic view-projection from light's perspective
	LightView           [16]float32 // view-only matrix (no projection) for linear depth
	TexelSize           [2]float32  // 1.0 / shadow_map_resolution for VSM texel calculations
	Bias                float32     // depth comparison bias to reduce shadow acne
	NormalBias          float32     // world-space normal-offset distance for shadow lookup
	ShadowNear          float32     // near plane for linear depth normalization
	ShadowFar           float32     // far plane for linear depth normalization
	MinVariance         float32     // minimum variance clamp for Chebyshev's inequality (VSM)
	LightBleedReduction float32     // exponent to reduce light-bleeding artifacts (VSM)
	LightSize           float32     // world-space light size for PCSS penumbra estimation
	ShadowHalfExtent    float32     // orthographic frustum half-size for PCSS world-to-texel conversion
	// contains filtered or unexported fields
}

GPUShadowData is the GPU-aligned representation of directional shadow data. Matches the WGSL ShadowData struct layout exactly (see GPUShadowDataSource). Size: 176 bytes (std430 / WGSL aligned).

Layout:

mat4x4<f32> light_vp              (64 bytes, offset   0)
mat4x4<f32> light_view            (64 bytes, offset  64)
vec2<f32>   texel_size            ( 8 bytes, offset 128)
f32         bias                  ( 4 bytes, offset 136)
f32         normal_bias           ( 4 bytes, offset 140)
f32         shadow_near           ( 4 bytes, offset 144)
f32         shadow_far            ( 4 bytes, offset 148)
f32         min_variance          ( 4 bytes, offset 152)
f32         light_bleed_reduction ( 4 bytes, offset 156)
f32         light_size            ( 4 bytes, offset 160)
f32         shadow_half_extent    ( 4 bytes, offset 164)
vec2<f32>   _pad                  ( 8 bytes, offset 168)

func (*GPUShadowData) ComputeDirectionalLightVP

func (s *GPUShadowData) ComputeDirectionalLightVP(lightDir [3]float32, centerX, centerY, centerZ, halfExtent, near, far float32)

ComputeDirectionalLightVP builds an orthographic view-projection matrix for a directional light's shadow pass and stores it in the receiver's LightVP field. Also stores the view-only matrix in LightView and the near/far planes in ShadowNear/ShadowFar for VSM linear depth normalization. The frustum is centered on the provided center position (typically the camera position) and aligned to look along the light's direction.

Parameters:

  • lightDir: normalized direction the light points (from light toward scene)
  • centerX, centerY, centerZ: world-space center of the shadow frustum
  • halfExtent: half-size of the orthographic frustum in world units
  • near: near plane distance
  • far: far plane distance

func (*GPUShadowData) ComputeNormalBias

func (s *GPUShadowData) ComputeNormalBias(halfExtent, scale float32, resolution int)

ComputeNormalBias derives the world-space normal-offset bias from the shadow map parameters and stores it in the receiver's NormalBias field. The result is the distance (in world units) that fragment positions are shifted along their surface normal before projecting into light clip space. This prevents self-shadowing on concave geometry.

Parameters:

  • halfExtent: orthographic frustum half-size in world units
  • scale: multiplier on the per-texel world size (typically 2.0–4.0)
  • resolution: shadow map resolution in texels (width and height)

func (*GPUShadowData) Marshal

func (s *GPUShadowData) Marshal() []byte

Marshal serializes the GPUShadowData struct into a byte buffer suitable for GPU uniform upload.

Returns:

  • []byte: 176-byte buffer ready for GPU upload

func (*GPUShadowData) Size

func (s *GPUShadowData) Size() int

Size returns the size of the GPUShadowData struct in bytes.

Returns:

  • int: the struct size in bytes (176)

type GPUShadowUniform

type GPUShadowUniform struct {
	LightVP    [16]float32 // orthographic view-projection from light's perspective
	LightView  [16]float32 // view-only matrix (no projection) for linear depth in VSM
	ShadowNear float32     // near plane for linear depth normalization
	ShadowFar  float32     // far plane for linear depth normalization
}

GPUShadowUniform is the GPU-aligned representation of the shadow vertex shader uniform containing the light view-projection matrix, the view-only matrix, and near/far planes for linear depth normalization in VSM mode. Matches the WGSL ShadowUniform struct layout exactly (see GPUShadowUniformSource). Size: 136 bytes (mat4x4 + mat4x4 + f32 + f32).

Layout:

mat4x4<f32> light_vp    (64 bytes, offset  0)
mat4x4<f32> light_view  (64 bytes, offset 64)
f32         shadow_near ( 4 bytes, offset 128)
f32         shadow_far  ( 4 bytes, offset 132)

func (*GPUShadowUniform) Marshal

func (u *GPUShadowUniform) Marshal() []byte

Marshal serializes the GPUShadowUniform struct into a byte buffer suitable for GPU uniform upload.

Returns:

  • []byte: 136-byte buffer ready for GPU upload

func (*GPUShadowUniform) Size

func (u *GPUShadowUniform) Size() int

Size returns the size of the GPUShadowUniform struct in bytes.

Returns:

  • int: the struct size in bytes (136)

type GPUTileUniforms

type GPUTileUniforms struct {
	TileCountX       uint32
	MaxLightsPerTile uint32
}

GPUTileUniforms is the GPU-aligned uniform data read by the lit fragment shader to compute which tile a fragment belongs to and index into the per-tile light list buffer. Matches the WGSL TileUniforms struct layout exactly (see GPUTileUniformsSource). Size: 8 bytes.

Layout:

u32 tile_count_x       (4 bytes, offset 0)
u32 max_lights_per_tile (4 bytes, offset 4)

func (*GPUTileUniforms) Marshal

func (u *GPUTileUniforms) Marshal() []byte

Marshal serializes GPUTileUniforms into an 8-byte little-endian buffer suitable for GPU upload.

Returns:

  • []byte: 8-byte buffer ready for GPU upload

func (*GPUTileUniforms) Size

func (u *GPUTileUniforms) Size() int

Size returns the size of the GPUTileUniforms struct in bytes.

Returns:

  • int: the struct size in bytes (8)

type IrradianceProbeGrid added in v0.2.0

type IrradianceProbeGrid interface {
	// Enabled returns whether the probe grid subsystem has been GPU-initialized
	// and is ready for rendering.
	//
	// Returns:
	//   - bool: true if probe grid GPU resources have been initialized
	Enabled() bool

	// SetEnabled sets whether the probe grid subsystem is GPU-initialized.
	//
	// Parameters:
	//   - enabled: true to mark as initialized
	SetEnabled(enabled bool)

	// CountX returns the number of probes along the X axis.
	//
	// Returns:
	//   - int: the probe count along X
	CountX() int

	// CountY returns the number of probes along the Y axis.
	//
	// Returns:
	//   - int: the probe count along Y
	CountY() int

	// CountZ returns the number of probes along the Z axis.
	//
	// Returns:
	//   - int: the probe count along Z
	CountZ() int

	// TotalProbes returns the total number of probes in the grid (X × Y × Z).
	//
	// Returns:
	//   - int: the total probe count
	TotalProbes() int

	// GridMin returns the world-space minimum corner of the probe grid.
	//
	// Returns:
	//   - [3]float32: the minimum corner (x, y, z)
	GridMin() [3]float32

	// GridMax returns the world-space maximum corner of the probe grid.
	//
	// Returns:
	//   - [3]float32: the maximum corner (x, y, z)
	GridMax() [3]float32

	// Spacing returns the world-space distance between adjacent probes per axis.
	//
	// Returns:
	//   - [3]float32: the spacing (x, y, z)
	Spacing() [3]float32

	// BakeResolution returns the cubemap face resolution in pixels per edge.
	//
	// Returns:
	//   - int: the cubemap face resolution
	BakeResolution() int

	// ProbeIndex computes the flat array index for the probe at grid position
	// (x, y, z). The layout is: index = x + y*countX + z*countX*countY.
	//
	// Parameters:
	//   - x: the X grid coordinate
	//   - y: the Y grid coordinate
	//   - z: the Z grid coordinate
	//
	// Returns:
	//   - int: the flat array index
	ProbeIndex(x, y, z int) int

	// Probe returns a copy of the probe at the given flat index.
	//
	// Parameters:
	//   - index: the flat probe index
	//
	// Returns:
	//   - GPUIrradianceProbe: the probe data
	Probe(index int) GPUIrradianceProbe

	// Probes returns a reference to the full slice of CPU-side probe data.
	//
	// Returns:
	//   - []GPUIrradianceProbe: all probes in the grid
	Probes() []GPUIrradianceProbe

	// SetProbe writes the given probe data at the specified flat index and
	// marks the probe as dirty for re-baking.
	//
	// Parameters:
	//   - index: the flat probe index
	//   - p: the probe data to set
	SetProbe(index int, p GPUIrradianceProbe)

	// SetProbes replaces the entire CPU-side probe slice.
	//
	// Parameters:
	//   - probes: the new probe data
	SetProbes(probes []GPUIrradianceProbe)

	// DirtyProbes returns the indices of probes that need re-baking.
	//
	// Returns:
	//   - []int: dirty probe indices
	DirtyProbes() []int

	// SetDirtyProbes replaces the dirty probe index list.
	//
	// Parameters:
	//   - indices: the new list of dirty probe indices
	SetDirtyProbes(indices []int)

	// MarkAllDirty adds every probe index to the dirty list.
	MarkAllDirty()

	// ClearDirtyProbes empties the dirty probe list.
	ClearDirtyProbes()

	// ProbeBuffer returns the GPU storage buffer holding the serialized probe array.
	//
	// Returns:
	//   - *wgpu.Buffer: the probe storage buffer, or nil if not initialized
	ProbeBuffer() *wgpu.Buffer

	// SetProbeBuffer sets the GPU storage buffer for probes.
	//
	// Parameters:
	//   - buf: the probe storage buffer
	SetProbeBuffer(buf *wgpu.Buffer)

	// GridParamsBuffer returns the GPU uniform buffer holding the serialized
	// GPUProbeGridParams data.
	//
	// Returns:
	//   - *wgpu.Buffer: the grid params uniform buffer, or nil if not initialized
	GridParamsBuffer() *wgpu.Buffer

	// SetGridParamsBuffer sets the GPU uniform buffer for grid parameters.
	//
	// Parameters:
	//   - buf: the grid params uniform buffer
	SetGridParamsBuffer(buf *wgpu.Buffer)

	// PipelineKey retrieves the pipeline key associated with the given name.
	// Returns an empty string if the name does not exist.
	//
	// Parameters:
	//   - name: the pipeline name
	//
	// Returns:
	//   - string: the pipeline key, or empty if not found
	PipelineKey(name string) string

	// PipelineKeys returns the full map of pipeline keys.
	//
	// Returns:
	//   - map[string]string: all registered pipeline name-to-key mappings
	PipelineKeys() map[string]string

	// SetPipelineKey stores a pipeline key under the given name.
	//
	// Parameters:
	//   - name: the pipeline name
	//   - key: the pipeline key
	SetPipelineKey(name, key string)

	// Bgp retrieves the bind group provider associated with the given key.
	// Returns nil if the key does not exist.
	//
	// Valid keys:
	//   - "probe_grid": lit shader bind group (probe buffer + grid params)
	//   - "probe_sh_project": SH projection compute shader bind group
	//   - "probe_bake_camera": bake pass camera uniform bind group
	//
	// Parameters:
	//   - key: the bind group provider name
	//
	// Returns:
	//   - bind_group_provider.BindGroupProvider: the provider, or nil if not found
	Bgp(key string) bind_group_provider.BindGroupProvider

	// Bgps returns the full map of bind group providers.
	//
	// Returns:
	//   - map[string]bind_group_provider.BindGroupProvider: all registered providers
	Bgps() map[string]bind_group_provider.BindGroupProvider

	// SetBgp stores a bind group provider under the given key.
	//
	// Parameters:
	//   - key: the bind group provider name
	//   - bgp: the bind group provider
	SetBgp(key string, bgp bind_group_provider.BindGroupProvider)

	// BakeColorTexture returns the RGBA8Unorm texture used as the color
	// attachment during cubemap face baking.
	//
	// Returns:
	//   - *wgpu.Texture: the bake color texture, or nil if not initialized
	BakeColorTexture() *wgpu.Texture

	// SetBakeColorTexture sets the cubemap bake color texture.
	//
	// Parameters:
	//   - t: the bake color texture
	SetBakeColorTexture(t *wgpu.Texture)

	// BakeColorTextureView returns the texture view for the bake color texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the bake color texture view, or nil if not initialized
	BakeColorTextureView() *wgpu.TextureView

	// SetBakeColorTextureView sets the texture view for the bake color texture.
	//
	// Parameters:
	//   - tv: the bake color texture view
	SetBakeColorTextureView(tv *wgpu.TextureView)

	// BakeDepthTexture returns the depth texture used during cubemap face baking.
	//
	// Returns:
	//   - *wgpu.Texture: the bake depth texture, or nil if not initialized
	BakeDepthTexture() *wgpu.Texture

	// SetBakeDepthTexture sets the cubemap bake depth texture.
	//
	// Parameters:
	//   - t: the bake depth texture
	SetBakeDepthTexture(t *wgpu.Texture)

	// BakeDepthTextureView returns the texture view for the bake depth texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the bake depth texture view, or nil if not initialized
	BakeDepthTextureView() *wgpu.TextureView

	// SetBakeDepthTextureView sets the texture view for the bake depth texture.
	//
	// Parameters:
	//   - tv: the bake depth texture view
	SetBakeDepthTextureView(tv *wgpu.TextureView)

	// BuildGPUGridParams computes and returns the GPUProbeGridParams uniform
	// data matching the current grid configuration.
	//
	// Returns:
	//   - GPUProbeGridParams: the serializable grid parameter block
	BuildGPUGridParams() GPUProbeGridParams
}

IrradianceProbeGrid defines the interface for the scene's irradiance probe grid subsystem.

The probe grid stores a regular 3-D grid of irradiance probes, each containing L2 spherical harmonic coefficients that encode low-frequency indirect illumination sampled from the surrounding scene. During probe baking, the scene is rendered from each probe position into a tiny cubemap (6 faces at the configured resolution), then the cubemap is projected into SH coefficients via a compute shader. The resulting SH data is uploaded to a GPU storage buffer and sampled in the lit fragment shader for per-pixel diffuse indirect lighting via trilinear probe interpolation.

Thread safety is provided by the owning scene's mutex — the handler itself does not perform internal locking.

func NewIrradianceProbeGrid added in v0.2.0

func NewIrradianceProbeGrid(opts ...IrradianceProbeGridOption) IrradianceProbeGrid

NewIrradianceProbeGrid creates a new IrradianceProbeGrid with sensible defaults and any provided options applied. After options are applied the per-axis spacing is derived from the grid bounds and counts, and the CPU-side probe array is pre-allocated with world-space positions set to each grid cell centre. GPU resources are not allocated until the owning scene calls the appropriate initialization methods.

Defaults:

  • Grid counts: 8 × 4 × 8
  • Bounds: (-10, -2, -10) to (10, 6, 10)
  • Bake resolution: 32 pixels per cubemap face edge

Parameters:

  • opts: variadic list of IrradianceProbeGridOption functions to configure the handler

Returns:

  • IrradianceProbeGrid: a new handler instance ready to be attached to a scene

type IrradianceProbeGridOption added in v0.2.0

type IrradianceProbeGridOption func(*irradianceProbeGridImpl)

IrradianceProbeGridOption is a functional option for configuring an IrradianceProbeGrid during construction via NewIrradianceProbeGrid.

func WithProbeBakeResolution added in v0.2.0

func WithProbeBakeResolution(resolution int) IrradianceProbeGridOption

WithProbeBakeResolution sets the cubemap face resolution used during probe baking. Each face is rendered at resolution × resolution pixels.

Parameters:

  • resolution: the cubemap face edge length in pixels (e.g. 32)

Returns:

  • IrradianceProbeGridOption: a function that applies the resolution option to an irradianceProbeGridImpl

func WithProbeGridBounds added in v0.2.0

func WithProbeGridBounds(min, max [3]float32) IrradianceProbeGridOption

WithProbeGridBounds sets the world-space axis-aligned bounding box of the probe grid. Probes are placed uniformly between min and max on each axis.

Parameters:

  • min: the minimum corner (x, y, z)
  • max: the maximum corner (x, y, z)

Returns:

  • IrradianceProbeGridOption: a function that applies the bounds option to an irradianceProbeGridImpl

func WithProbeGridCounts added in v0.2.0

func WithProbeGridCounts(x, y, z int) IrradianceProbeGridOption

WithProbeGridCounts sets the number of probes in each axis.

Parameters:

  • x: the number of probes along the X axis
  • y: the number of probes along the Y axis
  • z: the number of probes along the Z axis

Returns:

  • IrradianceProbeGridOption: a function that applies the count option to an irradianceProbeGridImpl

type Light

type Light interface {
	common.Delegate[Light]

	// Type returns the kind of light source.
	//
	// Returns:
	//   - LightType: the light type (directional, point, or spot)
	Type() LightType

	// Position returns the world-space position of the light.
	// Meaningless for directional lights.
	//
	// Returns:
	//   - [3]float32: position as (x, y, z)
	Position() [3]float32

	// Direction returns the normalized direction of the light.
	// For directional lights this is the light direction. For spot lights this
	// is the cone axis. Meaningless for point lights.
	//
	// Returns:
	//   - [3]float32: normalized direction as (x, y, z)
	Direction() [3]float32

	// Color returns the RGB color of the light.
	//
	// Returns:
	//   - [3]float32: color as (r, g, b)
	Color() [3]float32

	// Intensity returns the scalar intensity multiplier for the light.
	//
	// Returns:
	//   - float32: the intensity value
	Intensity() float32

	// Range returns the maximum attenuation distance for point and spot lights.
	// Beyond this distance the light contributes zero energy. Meaningless for
	// directional lights.
	//
	// Returns:
	//   - float32: the range value
	Range() float32

	// InnerCone returns the cosine of the inner cone half-angle for spot lights.
	// Fragments within this angle receive full intensity. Meaningless for
	// directional and point lights.
	//
	// Returns:
	//   - float32: cos(inner half-angle)
	InnerCone() float32

	// OuterCone returns the cosine of the outer cone half-angle for spot lights.
	// Fragments outside this angle receive zero intensity from the spot cone
	// falloff. Meaningless for directional and point lights.
	//
	// Returns:
	//   - float32: cos(outer half-angle)
	OuterCone() float32

	// Enabled returns whether this light is active for rendering.
	// Disabled lights are skipped during GPU buffer marshaling.
	//
	// Returns:
	//   - bool: true if the light is enabled
	Enabled() bool

	// Ephemeral returns whether this light is a short-lived particle-emitted light.
	// Ephemeral lights are not persisted in the scene's light registry and are
	// managed by their owning particle system.
	//
	// Returns:
	//   - bool: true if ephemeral
	Ephemeral() bool

	// CastsShadows returns whether this light is eligible for shadow map generation.
	// Shadow-casting lights have their depth pass rendered each frame, which is
	// expensive. Most ephemeral and distant lights should have this disabled.
	//
	// Returns:
	//   - bool: true if the light casts shadows
	CastsShadows() bool

	// SetPosition sets the world-space position of the light.
	//
	// Parameters:
	//   - x, y, z: position components
	SetPosition(x, y, z float32)

	// SetDirection sets the direction of the light and normalizes it.
	//
	// Parameters:
	//   - x, y, z: direction components (will be normalized)
	SetDirection(x, y, z float32)

	// SetColor sets the RGB color of the light.
	//
	// Parameters:
	//   - r, g, b: color components
	SetColor(r, g, b float32)

	// SetIntensity sets the scalar intensity multiplier.
	//
	// Parameters:
	//   - intensity: the intensity value
	SetIntensity(intensity float32)

	// SetRange sets the maximum attenuation distance.
	//
	// Parameters:
	//   - lightRange: the range value
	SetRange(lightRange float32)

	// SetSpotCone sets the inner and outer cone half-angles for spot lights.
	// Angles are specified in degrees and stored internally as cosines.
	//
	// Parameters:
	//   - innerDeg: inner cone half-angle in degrees
	//   - outerDeg: outer cone half-angle in degrees
	SetSpotCone(innerDeg, outerDeg float32)

	// SetEnabled enables or disables the light for rendering.
	//
	// Parameters:
	//   - enabled: true to enable
	SetEnabled(enabled bool)

	// SetEphemeral marks the light as ephemeral (particle-emitted).
	//
	// Parameters:
	//   - ephemeral: true if ephemeral
	SetEphemeral(ephemeral bool)

	// SetCastsShadows sets whether the light is eligible for shadow mapping.
	//
	// Parameters:
	//   - castsShadows: true to enable shadow casting
	SetCastsShadows(castsShadows bool)
}

Light defines the interface for a light source in the scene.

Lights are scene-level entities that contribute to the final pixel color during the lit forward rendering pass. All light types (directional, point, spot) share this interface; type-specific properties (e.g. cone angles for spot lights) return zero values when not applicable.

Lights are managed by the scene and marshaled into a GPU storage buffer each frame via the gpu_types helpers.

func NewLight

func NewLight(lightType LightType, opts ...LightBuilderOption) Light

NewLight creates a new Light of the specified type with sensible defaults and any provided options applied.

Parameters:

  • lightType: the kind of light to create (directional, point, or spot)
  • opts: variadic list of LightBuilderOption functions to configure the light

Returns:

  • Light: a new Light instance

type LightBuilderOption

type LightBuilderOption func(*lightImpl)

LightBuilderOption is a function that configures a Light instance during construction.

func WithCastsShadows

func WithCastsShadows(castsShadows bool) LightBuilderOption

WithCastsShadows is an option builder that sets whether the light is eligible for shadow map generation.

Parameters:

  • castsShadows: true to enable shadow casting

Returns:

  • LightBuilderOption: a function that applies the shadow casting option to a lightImpl

func WithColor

func WithColor(r, g, b float32) LightBuilderOption

WithColor is an option builder that sets the RGB color of the light.

Parameters:

  • r: the red color component
  • g: the green color component
  • b: the blue color component

Returns:

  • LightBuilderOption: a function that applies the color option to a lightImpl

func WithDirection

func WithDirection(x, y, z float32) LightBuilderOption

WithDirection is an option builder that sets the direction of the light. The direction is normalized before storing.

Parameters:

  • x: the x direction component
  • y: the y direction component
  • z: the z direction component

Returns:

  • LightBuilderOption: a function that applies the direction option to a lightImpl

func WithEnabled

func WithEnabled(enabled bool) LightBuilderOption

WithEnabled is an option builder that sets whether the light is active for rendering.

Parameters:

  • enabled: true to enable the light

Returns:

  • LightBuilderOption: a function that applies the enabled option to a lightImpl

func WithEphemeral

func WithEphemeral(ephemeral bool) LightBuilderOption

WithEphemeral is an option builder that marks the light as ephemeral, meaning it is a short-lived particle-emitted light that is not persisted in the scene registry.

Parameters:

  • ephemeral: true if the light is ephemeral

Returns:

  • LightBuilderOption: a function that applies the ephemeral option to a lightImpl

func WithIntensity

func WithIntensity(intensity float32) LightBuilderOption

WithIntensity is an option builder that sets the scalar intensity multiplier.

Parameters:

  • intensity: the intensity value

Returns:

  • LightBuilderOption: a function that applies the intensity option to a lightImpl

func WithPosition

func WithPosition(x, y, z float32) LightBuilderOption

WithPosition is an option builder that sets the world-space position of the light.

Parameters:

  • x: the x position component
  • y: the y position component
  • z: the z position component

Returns:

  • LightBuilderOption: a function that applies the position option to a lightImpl

func WithRange

func WithRange(lightRange float32) LightBuilderOption

WithRange is an option builder that sets the maximum attenuation distance for point and spot lights.

Parameters:

  • lightRange: the range value

Returns:

  • LightBuilderOption: a function that applies the range option to a lightImpl

func WithSpotCone

func WithSpotCone(innerDeg, outerDeg float32) LightBuilderOption

WithSpotCone is an option builder that sets the inner and outer cone half-angles for spot lights. Angles are specified in degrees and converted to cosines internally, which is the format required by the GPU shader.

Parameters:

  • innerDeg: inner cone half-angle in degrees
  • outerDeg: outer cone half-angle in degrees

Returns:

  • LightBuilderOption: a function that applies the spot cone option to a lightImpl

type LightType

type LightType int

LightType identifies the kind of light source.

const (
	// LightTypeDirectional represents a light with no position, only direction.
	// Used for large distant sources like the sun or moon. Affects all fragments
	// uniformly with no distance attenuation.
	LightTypeDirectional LightType = iota

	// LightTypePoint represents a light that emits in all directions from a position.
	// Used for bare bulbs, lanterns, candle flames, and particle-emitted lights.
	// Attenuates with distance up to a configurable range.
	LightTypePoint

	// LightTypeSpot represents a light that emits in a cone from a position along a direction.
	// Used for flashlights, desk lamps, and wall sconces. Attenuates with both
	// distance and angle from the cone axis, controlled by inner and outer cone angles.
	LightTypeSpot
)

type LightingHandler added in v0.1.0

type LightingHandler interface {
	// Enabled returns whether the lighting subsystem has been GPU-initialized and
	// is ready for rendering.
	//
	// Returns:
	//   - bool: true if lighting GPU resources have been initialized
	Enabled() bool

	// SetEnabled sets whether the lighting subsystem is GPU-initialized.
	//
	// Parameters:
	//   - enabled: true to mark as initialized
	SetEnabled(enabled bool)

	// Lights returns a copy of the current light list.
	//
	// Returns:
	//   - []Light: a copy of the lights registered with the handler
	Lights() []Light

	// AddLight appends a light to the handler's light list.
	//
	// Parameters:
	//   - l: the Light to add
	AddLight(l Light)

	// RemoveLight removes a light from the handler's list by reference equality.
	//
	// Parameters:
	//   - l: the Light to remove
	RemoveLight(l Light)

	// AmbientColor returns the scene's ambient light color.
	//
	// Returns:
	//   - [3]float32: the ambient RGB color
	AmbientColor() [3]float32

	// SetAmbientColor sets the scene's ambient light color.
	//
	// Parameters:
	//   - color: the ambient RGB color
	SetAmbientColor(color [3]float32)

	// Bgp retrieves the BindGroupProvider associated with the given key.
	// Returns nil if the key does not exist.
	//
	// Known keys:
	//   - "lights": light storage buffer BGP
	//   - "shadow_data": shadow depth pass BGP (light VP uniform)
	//   - "shadow_lit": lit pass shadow sampling BGP (texture + sampler + uniform)
	//   - "light_cull": compute shader cull BGP
	//   - "tile_lit": fragment shader tile data BGP
	//   - "ssao_lit": lit pass SSAO occlusion texture + sampler BGP (real or fallback white)
	//
	// Parameters:
	//   - key: the bind group provider identifier
	//
	// Returns:
	//   - bind_group_provider.BindGroupProvider: the provider, or nil if not found
	Bgp(key string) bind_group_provider.BindGroupProvider

	// Bgps returns the full map of bind group providers.
	//
	// Returns:
	//   - map[string]bind_group_provider.BindGroupProvider: all registered providers
	Bgps() map[string]bind_group_provider.BindGroupProvider

	// PipelineKey retrieves the pipeline key associated with the given name.
	// Returns an empty string if the name does not exist.
	//
	// Parameters:
	//   - name: the pipeline name
	//
	// Returns:
	//   - string: the pipeline key, or empty if not found
	PipelineKey(name string) string

	// PipelineKeys returns the full map of pipeline keys.
	//
	// Returns:
	//   - map[string]string: all registered pipeline name-to-key mappings
	PipelineKeys() map[string]string

	// SetPipelineKey stores a pipeline key under the given name.
	//
	// Parameters:
	//   - name: the pipeline name
	//   - key: the pipeline key
	SetPipelineKey(name, key string)

	// ShadowHalfExtent returns the orthographic half-extent of the directional shadow frustum
	// in world units.
	//
	// Returns:
	//   - float32: the shadow frustum half-extent
	ShadowHalfExtent() float32

	// ShadowNear returns the near plane distance for the directional shadow projection.
	//
	// Returns:
	//   - float32: the shadow near plane
	ShadowNear() float32

	// ShadowFar returns the far plane distance for the directional shadow projection.
	//
	// Returns:
	//   - float32: the shadow far plane
	ShadowFar() float32

	// ShadowBias returns the constant depth bias applied to shadow comparisons.
	//
	// Returns:
	//   - float32: the shadow bias
	ShadowBias() float32

	// ShadowNormalBiasScale returns the multiplier applied to the shadow map texel
	// world-size to derive the normal-offset bias.
	//
	// Returns:
	//   - float32: the normal bias scale
	ShadowNormalBiasScale() float32

	// ShadowMapResolution returns the width and height in texels of the shadow depth texture.
	//
	// Returns:
	//   - int: the shadow map resolution
	ShadowMapResolution() int

	// VSMTexture returns the RG32Float variance shadow map texture.
	//
	// Returns:
	//   - *wgpu.Texture: the VSM texture, or nil if not initialized
	VSMTexture() *wgpu.Texture

	// SetVSMTexture sets the RG32Float variance shadow map texture.
	//
	// Parameters:
	//   - t: the VSM texture
	SetVSMTexture(t *wgpu.Texture)

	// VSMTextureView returns the texture view for the VSM texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the VSM texture view, or nil if not initialized
	VSMTextureView() *wgpu.TextureView

	// SetVSMTextureView sets the texture view for the VSM texture.
	//
	// Parameters:
	//   - tv: the VSM texture view
	SetVSMTextureView(tv *wgpu.TextureView)

	// VSMScratchTexture returns the scratch RG32Float texture used as intermediate
	// storage during the separable blur pass.
	//
	// Returns:
	//   - *wgpu.Texture: the scratch texture, or nil if not initialized
	VSMScratchTexture() *wgpu.Texture

	// SetVSMScratchTexture sets the scratch texture used during the separable blur pass.
	//
	// Parameters:
	//   - t: the scratch texture
	SetVSMScratchTexture(t *wgpu.Texture)

	// VSMScratchTextureView returns the texture view for the scratch texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the scratch texture view, or nil if not initialized
	VSMScratchTextureView() *wgpu.TextureView

	// SetVSMScratchTextureView sets the texture view for the scratch texture.
	//
	// Parameters:
	//   - tv: the scratch texture view
	SetVSMScratchTextureView(tv *wgpu.TextureView)

	// VSMAuxDepthTexture returns the auxiliary Depth32Float texture used for hardware
	// z-testing during the VSM shadow render pass.
	//
	// Returns:
	//   - *wgpu.Texture: the auxiliary depth texture, or nil if not initialized
	VSMAuxDepthTexture() *wgpu.Texture

	// SetVSMAuxDepthTexture sets the auxiliary depth texture for the VSM shadow pass.
	//
	// Parameters:
	//   - t: the auxiliary depth texture
	SetVSMAuxDepthTexture(t *wgpu.Texture)

	// VSMAuxDepthTextureView returns the texture view for the auxiliary depth texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the auxiliary depth texture view, or nil if not initialized
	VSMAuxDepthTextureView() *wgpu.TextureView

	// SetVSMAuxDepthTextureView sets the texture view for the auxiliary depth texture.
	//
	// Parameters:
	//   - tv: the auxiliary depth texture view
	SetVSMAuxDepthTextureView(tv *wgpu.TextureView)

	// VSMLinearSampler returns the linear sampler used for VSM texture lookups in
	// the lit fragment shader (replaces the comparison sampler used by PCF).
	//
	// Returns:
	//   - *wgpu.Sampler: the linear sampler, or nil if not initialized
	VSMLinearSampler() *wgpu.Sampler

	// SetVSMLinearSampler sets the linear sampler used for VSM texture lookups.
	//
	// Parameters:
	//   - s: the linear sampler
	SetVSMLinearSampler(s *wgpu.Sampler)

	// VSMBlurRadius returns the half-width (in texels) of the separable blur
	// applied to the variance shadow map.
	//
	// Returns:
	//   - int: the blur radius
	VSMBlurRadius() int

	// VSMMinVariance returns the minimum variance clamp for Chebyshev's inequality.
	//
	// Returns:
	//   - float32: the minimum variance
	VSMMinVariance() float32

	// VSMLightBleedReduction returns the exponent applied to the raw Chebyshev shadow
	// probability to reduce light-bleeding artifacts.
	//
	// Returns:
	//   - float32: the light bleed reduction exponent
	VSMLightBleedReduction() float32

	// VSMLightSize returns the world-space area light size used for PCSS penumbra estimation.
	//
	// Returns:
	//   - float32: the light size
	VSMLightSize() float32

	// PCSSEnabled returns whether PCSS contact-hardening soft shadows are enabled.
	// PCSS requires VSM to also be enabled.
	//
	// Returns:
	//   - bool: true if PCSS is enabled
	PCSSEnabled() bool

	// SetPCSSEnabled sets whether PCSS contact-hardening soft shadows are enabled.
	//
	// Parameters:
	//   - enabled: true to enable PCSS
	SetPCSSEnabled(enabled bool)

	// SATTextureA returns the first RGBA32Float SAT ping-pong texture.
	//
	// Returns:
	//   - *wgpu.Texture: SAT texture A, or nil if not initialized
	SATTextureA() *wgpu.Texture

	// SetSATTextureA sets the first SAT ping-pong texture.
	//
	// Parameters:
	//   - t: SAT texture A
	SetSATTextureA(t *wgpu.Texture)

	// SATTextureAView returns the texture view for SAT texture A.
	//
	// Returns:
	//   - *wgpu.TextureView: SAT texture A view, or nil if not initialized
	SATTextureAView() *wgpu.TextureView

	// SetSATTextureAView sets the texture view for SAT texture A.
	//
	// Parameters:
	//   - tv: SAT texture A view
	SetSATTextureAView(tv *wgpu.TextureView)

	// SATTextureB returns the second RGBA32Float SAT ping-pong texture.
	//
	// Returns:
	//   - *wgpu.Texture: SAT texture B, or nil if not initialized
	SATTextureB() *wgpu.Texture

	// SetSATTextureB sets the second SAT ping-pong texture.
	//
	// Parameters:
	//   - t: SAT texture B
	SetSATTextureB(t *wgpu.Texture)

	// SATTextureBView returns the texture view for SAT texture B.
	//
	// Returns:
	//   - *wgpu.TextureView: SAT texture B view, or nil if not initialized
	SATTextureBView() *wgpu.TextureView

	// SetSATTextureBView sets the texture view for SAT texture B.
	//
	// Parameters:
	//   - tv: SAT texture B view
	SetSATTextureBView(tv *wgpu.TextureView)

	// ScreenWidth returns the current screen width in pixels used for tile calculations.
	//
	// Returns:
	//   - int: the screen width
	ScreenWidth() int

	// ScreenHeight returns the current screen height in pixels used for tile calculations.
	//
	// Returns:
	//   - int: the screen height
	ScreenHeight() int

	// TileCountX returns the number of Forward+ tile columns for the current screen width.
	//
	// Returns:
	//   - uint32: the tile column count
	TileCountX() uint32

	// TileCountY returns the number of Forward+ tile rows for the current screen height.
	//
	// Returns:
	//   - uint32: the tile row count
	TileCountY() uint32

	// Resize updates the screen dimensions and recalculates tile counts for Forward+
	// light culling. This should be called when the window is resized.
	//
	// Parameters:
	//   - width: the new screen width in pixels
	//   - height: the new screen height in pixels
	Resize(width, height int)

	// GBufferHandler returns the GBufferHandler attached to this lighting
	// subsystem, or nil if no G-Buffer pre-pass is configured.
	//
	// Returns:
	//   - GBufferHandler: the G-Buffer handler, or nil
	GBufferHandler() GBufferHandler

	// SSAOHandler returns the SSAOHandler attached to this lighting
	// subsystem, or nil if SSAO is not configured.
	//
	// Returns:
	//   - SSAOHandler: the SSAO handler, or nil
	SSAOHandler() SSAOHandler

	// ProbeGrid returns the IrradianceProbeGrid attached to this lighting
	// subsystem, or nil if probe-based GI is not configured.
	//
	// Returns:
	//   - IrradianceProbeGrid: the probe grid handler, or nil
	ProbeGrid() IrradianceProbeGrid

	// CompositionHandler returns the CompositionHandler attached to this lighting
	// subsystem, or nil if composition/tone mapping is not configured.
	//
	// Returns:
	//   - CompositionHandler: the composition handler, or nil
	CompositionHandler() CompositionHandler

	// SSRHandler returns the SSRHandler attached to this lighting
	// subsystem, or nil if screen-space reflections are not configured.
	//
	// Returns:
	//   - SSRHandler: the SSR handler, or nil
	SSRHandler() SSRHandler
}

LightingHandler defines the interface for the scene's lighting subsystem.

The LightingHandler manages the light list, ambient color, shadow mapping configuration, Forward+ tile culling state, and all associated GPU resources (bind group providers, pipeline keys, shadow textures). It is created via NewLightingHandler with builder options and attached to a scene via WithLighting. GPU resources are initialized lazily by the scene when the first light is added.

Thread safety is provided by the owning scene's mutex — the handler itself does not perform internal locking.

func NewLightingHandler added in v0.1.0

func NewLightingHandler(opts ...LightingHandlerOption) LightingHandler

NewLightingHandler creates a new LightingHandler with sensible defaults and any provided options applied. Pre-creates named BindGroupProviders for each lighting subsystem stage. GPU resources are not allocated until the owning scene calls the appropriate initialization methods.

Parameters:

  • opts: variadic list of LightingHandlerOption functions to configure the handler

Returns:

  • LightingHandler: a new handler instance ready to be attached to a scene

type LightingHandlerOption added in v0.1.0

type LightingHandlerOption func(*lightingHandlerImpl)

LightingHandlerOption is a functional option for configuring a LightingHandler during construction via NewLightingHandler.

func WithAmbientColor added in v0.1.0

func WithAmbientColor(color [3]float32) LightingHandlerOption

WithAmbientColor sets the initial ambient light color for the scene. Default is black (no ambient contribution).

Parameters:

  • color: the ambient RGB color

Returns:

  • LightingHandlerOption: a function that applies the ambient color option to a lightingHandlerImpl

func WithCompositionHandler added in v0.2.0

func WithCompositionHandler(handler CompositionHandler) LightingHandlerOption

WithCompositionHandler attaches a pre-configured CompositionHandler to the lighting subsystem, overriding the default that is auto-created by NewLightingHandler. The composition handler manages the offscreen HDR render target and the full-screen tone mapping pass. GPU resources are initialized lazily during the first lighting initialization.

Parameters:

  • handler: the pre-configured CompositionHandler

Returns:

  • LightingHandlerOption: a function that applies the composition handler option to a lightingHandlerImpl

func WithGBufferHandler added in v0.2.0

func WithGBufferHandler(handler GBufferHandler) LightingHandlerOption

WithGBufferHandler attaches a pre-configured GBufferHandler to the lighting subsystem, overriding the default that is auto-created by NewLightingHandler. GPU resources are initialized lazily during the first lighting initialization.

Parameters:

  • handler: the pre-configured GBufferHandler

Returns:

  • LightingHandlerOption: a function that applies the G-Buffer handler option to a lightingHandlerImpl

func WithPCSSEnabled added in v0.2.0

func WithPCSSEnabled(enabled bool) LightingHandlerOption

WithPCSSEnabled enables or disables Percentage-Closer Soft Shadows. PCSS uses a Summed-Area Table built from the VSM moments texture to provide per-pixel variable-width shadow filtering, producing contact-hardening soft shadows. Requires VSM to be enabled. Default is false.

Parameters:

  • enabled: true to enable PCSS, false to use constant-width VSM blur

Returns:

  • LightingHandlerOption: a function that applies the PCSS enabled option to a lightingHandlerImpl

func WithProbeGrid added in v0.2.0

func WithProbeGrid(handler IrradianceProbeGrid) LightingHandlerOption

WithProbeGrid attaches a pre-configured IrradianceProbeGrid to the lighting subsystem. The probe grid stores L2 spherical harmonic coefficients sampled by baking the scene from each probe position. GPU resources are initialized lazily during the first lighting initialization. If not set, no probe-based diffuse indirect lighting is applied.

Parameters:

  • handler: the pre-configured IrradianceProbeGrid

Returns:

  • LightingHandlerOption: a function that applies the probe grid handler option to a lightingHandlerImpl

func WithSSAOHandler added in v0.2.0

func WithSSAOHandler(handler SSAOHandler) LightingHandlerOption

WithSSAOHandler attaches a pre-configured SSAOHandler to the lighting subsystem, overriding the default that is auto-created by NewLightingHandler. GPU resources are initialized lazily during the first lighting initialization.

Parameters:

  • handler: the pre-configured SSAOHandler

Returns:

  • LightingHandlerOption: a function that applies the SSAO handler option to a lightingHandlerImpl

func WithSSRHandler added in v0.2.0

func WithSSRHandler(handler SSRHandler) LightingHandlerOption

WithSSRHandler attaches a pre-configured SSRHandler to the lighting subsystem, overriding the default that is auto-created by NewLightingHandler. The SSR handler reads the G-Buffer and writes to a texture sampled by the composition pass. GPU resources are initialized lazily during the first lighting initialization.

Parameters:

  • handler: the pre-configured SSRHandler

Returns:

  • LightingHandlerOption: a function that applies the SSR handler option to a lightingHandlerImpl

func WithShadowBias added in v0.1.0

func WithShadowBias(bias float32) LightingHandlerOption

WithShadowBias sets the depth comparison bias used during shadow sampling to reduce shadow acne. Default is DefaultShadowBias (0.001).

Parameters:

  • bias: the depth bias value

Returns:

  • LightingHandlerOption: a function that applies the bias option to a lightingHandlerImpl

func WithShadowHalfExtent added in v0.1.0

func WithShadowHalfExtent(halfExtent float32) LightingHandlerOption

WithShadowHalfExtent sets the orthographic half-extent of the directional shadow frustum in world units. Larger values capture more of the scene but reduce shadow resolution. Default is DefaultShadowHalfExtent (40.0).

Parameters:

  • halfExtent: half-size of the shadow frustum in world units

Returns:

  • LightingHandlerOption: a function that applies the half-extent option to a lightingHandlerImpl

func WithShadowMapResolution added in v0.1.0

func WithShadowMapResolution(resolution int) LightingHandlerOption

WithShadowMapResolution sets the width and height in texels of the shadow depth texture. Higher values produce sharper shadows at the cost of more GPU memory and fill-rate. Must be set before GPU initialization. Default is ShadowMapResolution (2048).

Parameters:

  • resolution: shadow map width and height in texels (e.g. 1024, 2048, 4096)

Returns:

  • LightingHandlerOption: a function that applies the resolution option to a lightingHandlerImpl

func WithShadowNearFar added in v0.1.0

func WithShadowNearFar(near, far float32) LightingHandlerOption

WithShadowNearFar sets the near and far planes for the directional shadow projection. Default is DefaultShadowNear (0.1) and DefaultShadowFar (200.0).

Parameters:

  • near: near plane distance
  • far: far plane distance

Returns:

  • LightingHandlerOption: a function that applies the near/far option to a lightingHandlerImpl

func WithShadowNormalBiasScale added in v0.1.0

func WithShadowNormalBiasScale(scale float32) LightingHandlerOption

WithShadowNormalBiasScale sets the multiplier applied to the shadow-map texel world-size to derive the normal-offset bias. The normal offset shifts the shadow lookup position along the surface normal, preventing self-shadowing on concave geometry. Default is DefaultShadowNormalBiasScale (3.0).

Parameters:

  • scale: multiplier on per-texel world size (typically 2.0–4.0)

Returns:

  • LightingHandlerOption: a function that applies the normal bias scale option to a lightingHandlerImpl

func WithVSMBlurRadius added in v0.2.0

func WithVSMBlurRadius(radius int) LightingHandlerOption

WithVSMBlurRadius sets the half-width (in texels) of the separable blur applied to the variance shadow map. The full kernel width is 2*radius+1. The paper notes a minimum filter width of at least 4 is required to eliminate aliasing. Default is DefaultVSMBlurRadius (4).

Parameters:

  • radius: the blur half-width in texels

Returns:

  • LightingHandlerOption: a function that applies the blur radius option to a lightingHandlerImpl

func WithVSMLightBleedReduction added in v0.2.0

func WithVSMLightBleedReduction(reduction float32) LightingHandlerOption

WithVSMLightBleedReduction sets the exponent applied to the raw Chebyshev shadow probability to reduce light-bleeding artifacts. Higher values reduce light bleeding at the cost of darker shadow interiors. Typical range: 0.1–0.6. Default is DefaultVSMLightBleedReduction (0.3).

Parameters:

  • reduction: the light bleed reduction exponent

Returns:

  • LightingHandlerOption: a function that applies the light bleed reduction option to a lightingHandlerImpl

func WithVSMLightSize added in v0.2.0

func WithVSMLightSize(size float32) LightingHandlerOption

WithVSMLightSize sets the world-space size of the area light used for PCSS penumbra estimation. Larger values produce wider soft-shadow penumbrae. Only relevant when PCSS is enabled. Default is DefaultVSMLightSize (1.0).

Parameters:

  • size: the world-space light size

Returns:

  • LightingHandlerOption: a function that applies the light size option to a lightingHandlerImpl

func WithVSMMinVariance added in v0.2.0

func WithVSMMinVariance(minVariance float32) LightingHandlerOption

WithVSMMinVariance sets the minimum variance clamped during Chebyshev's inequality evaluation. Prevents division by near-zero variance from producing hard shadow edges on perfectly planar geometry. Default is DefaultVSMMinVariance (0.00001).

Parameters:

  • minVariance: the minimum variance clamp value

Returns:

  • LightingHandlerOption: a function that applies the min variance option to a lightingHandlerImpl

type SSAOHandler added in v0.2.0

type SSAOHandler interface {
	// Enabled returns whether the SSAO subsystem has been GPU-initialized
	// and is ready for rendering.
	//
	// Returns:
	//   - bool: true if SSAO GPU resources have been initialized
	Enabled() bool

	// SetEnabled sets whether the SSAO subsystem is GPU-initialized.
	//
	// Parameters:
	//   - enabled: true to mark as initialized
	SetEnabled(enabled bool)

	// ScreenWidth returns the current screen width in pixels used for texture sizing.
	//
	// Returns:
	//   - int: the screen width
	ScreenWidth() int

	// ScreenHeight returns the current screen height in pixels used for texture sizing.
	//
	// Returns:
	//   - int: the screen height
	ScreenHeight() int

	// SampleCount returns the number of hemisphere samples per pixel.
	//
	// Returns:
	//   - int: the sample count (1–32)
	SampleCount() int

	// Radius returns the hemisphere sampling radius in world-space units.
	//
	// Returns:
	//   - float32: the sampling radius
	Radius() float32

	// Bias returns the depth comparison bias used to prevent self-occlusion.
	//
	// Returns:
	//   - float32: the depth bias
	Bias() float32

	// Power returns the exponent applied to the final AO value.
	//
	// Returns:
	//   - float32: the power exponent
	Power() float32

	// BlurRadius returns the half-width of the bilateral blur kernel in texels.
	//
	// Returns:
	//   - int: the blur kernel half-width
	BlurRadius() int

	// PipelineKey retrieves the pipeline key associated with the given name.
	// Returns an empty string if the name does not exist.
	//
	// Parameters:
	//   - name: the pipeline name
	//
	// Returns:
	//   - string: the pipeline key, or empty if not found
	PipelineKey(name string) string

	// PipelineKeys returns the full map of pipeline keys.
	//
	// Returns:
	//   - map[string]string: all registered pipeline name-to-key mappings
	PipelineKeys() map[string]string

	// SetPipelineKey stores a pipeline key under the given name.
	//
	// Parameters:
	//   - name: the pipeline name
	//   - key: the pipeline key
	SetPipelineKey(name, key string)

	// Bgp retrieves the bind group provider associated with the given key.
	// Returns nil if the key does not exist.
	//
	// Parameters:
	//   - key: the bind group provider name
	//
	// Returns:
	//   - bind_group_provider.BindGroupProvider: the provider, or nil if not found
	Bgp(key string) bind_group_provider.BindGroupProvider

	// Bgps returns the full map of bind group providers.
	//
	// Returns:
	//   - map[string]bind_group_provider.BindGroupProvider: all registered providers
	Bgps() map[string]bind_group_provider.BindGroupProvider

	// SetBgp stores a bind group provider under the given key.
	//
	// Parameters:
	//   - key: the bind group provider name
	//   - bgp: the bind group provider
	SetBgp(key string, bgp bind_group_provider.BindGroupProvider)

	// RawTexture returns the R8Unorm texture storing the raw (pre-blur) SSAO
	// occlusion values.
	//
	// Returns:
	//   - *wgpu.Texture: the raw SSAO texture, or nil if not initialized
	RawTexture() *wgpu.Texture

	// SetRawTexture sets the raw SSAO texture.
	//
	// Parameters:
	//   - t: the raw SSAO texture
	SetRawTexture(t *wgpu.Texture)

	// RawTextureView returns the texture view for the raw SSAO texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the raw SSAO texture view, or nil if not initialized
	RawTextureView() *wgpu.TextureView

	// SetRawTextureView sets the texture view for the raw SSAO texture.
	//
	// Parameters:
	//   - tv: the raw SSAO texture view
	SetRawTextureView(tv *wgpu.TextureView)

	// BlurredTexture returns the R8Unorm texture storing the blurred (final)
	// SSAO occlusion values bound to the lit shader.
	//
	// Returns:
	//   - *wgpu.Texture: the blurred SSAO texture, or nil if not initialized
	BlurredTexture() *wgpu.Texture

	// SetBlurredTexture sets the blurred SSAO texture.
	//
	// Parameters:
	//   - t: the blurred SSAO texture
	SetBlurredTexture(t *wgpu.Texture)

	// BlurredTextureView returns the texture view for the blurred SSAO texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the blurred SSAO texture view, or nil if not initialized
	BlurredTextureView() *wgpu.TextureView

	// SetBlurredTextureView sets the texture view for the blurred SSAO texture.
	//
	// Parameters:
	//   - tv: the blurred SSAO texture view
	SetBlurredTextureView(tv *wgpu.TextureView)

	// ScratchTexture returns the R8Unorm scratch texture used as an intermediate
	// target between the horizontal and vertical blur passes.
	//
	// Returns:
	//   - *wgpu.Texture: the scratch texture, or nil if not initialized
	ScratchTexture() *wgpu.Texture

	// SetScratchTexture sets the scratch texture for the blur passes.
	//
	// Parameters:
	//   - t: the scratch texture
	SetScratchTexture(t *wgpu.Texture)

	// ScratchTextureView returns the texture view for the scratch texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the scratch texture view, or nil if not initialized
	ScratchTextureView() *wgpu.TextureView

	// SetScratchTextureView sets the texture view for the scratch texture.
	//
	// Parameters:
	//   - tv: the scratch texture view
	SetScratchTextureView(tv *wgpu.TextureView)

	// NoiseTexture returns the 4×4 RGBA16Float texture storing random rotation
	// vectors for the SSAO sample kernel.
	//
	// Returns:
	//   - *wgpu.Texture: the noise texture, or nil if not initialized
	NoiseTexture() *wgpu.Texture

	// SetNoiseTexture sets the SSAO noise texture.
	//
	// Parameters:
	//   - t: the noise texture
	SetNoiseTexture(t *wgpu.Texture)

	// NoiseTextureView returns the texture view for the noise texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the noise texture view, or nil if not initialized
	NoiseTextureView() *wgpu.TextureView

	// SetNoiseTextureView sets the texture view for the noise texture.
	//
	// Parameters:
	//   - tv: the noise texture view
	SetNoiseTextureView(tv *wgpu.TextureView)

	// LinearSampler returns the linear sampler used when binding the SSAO
	// blurred texture to the lit fragment shader.
	//
	// Returns:
	//   - *wgpu.Sampler: the linear sampler, or nil if not initialized
	LinearSampler() *wgpu.Sampler

	// SetLinearSampler sets the linear sampler for SSAO texture sampling.
	//
	// Parameters:
	//   - s: the linear sampler
	SetLinearSampler(s *wgpu.Sampler)

	// Resize updates the screen dimensions for texture sizing. Existing
	// textures are not automatically recreated — call the appropriate texture
	// creation method if the dimensions change while the handler is enabled.
	//
	// Parameters:
	//   - width: the new screen width in pixels
	//   - height: the new screen height in pixels
	Resize(width, height int)

	// HalfResolution returns whether SSAO textures are allocated at half the
	// screen resolution for improved performance.
	//
	// Returns:
	//   - bool: true if half-resolution mode is enabled
	HalfResolution() bool

	// SetHalfResolution sets whether SSAO textures should be allocated at half
	// the screen resolution.
	//
	// Parameters:
	//   - enabled: true to enable half-resolution mode
	SetHalfResolution(enabled bool)
}

SSAOHandler defines the interface for the scene's SSAO subsystem.

The SSAOHandler manages the hemisphere sample kernel, noise texture, raw and blurred occlusion textures, compute pipeline keys, and bind group providers needed by the SSAO compute and bilateral blur shaders. It is created via NewSSAOHandler with builder options and attached to a scene via the GI configuration. GPU resources are initialized lazily by the owning scene when SSAO is first enabled.

Thread safety is provided by the owning scene's mutex — the handler itself does not perform internal locking.

func NewSSAOHandler added in v0.2.0

func NewSSAOHandler(opts ...SSAOHandlerOption) SSAOHandler

NewSSAOHandler creates a new SSAOHandler with sensible defaults and any provided options applied. GPU resources are not allocated until the owning scene calls the appropriate initialization methods.

Default values:

  • SampleCount: 16
  • Radius: 0.5
  • Bias: 0.025
  • Power: 2.0
  • BlurRadius: 4

Parameters:

  • opts: variadic list of SSAOHandlerOption functions to configure the handler

Returns:

  • SSAOHandler: a new handler instance ready to be attached to a scene

type SSAOHandlerOption added in v0.2.0

type SSAOHandlerOption func(*ssaoHandlerImpl)

SSAOHandlerOption is a functional option for configuring an SSAOHandler during construction via NewSSAOHandler.

func WithSSAOBias added in v0.2.0

func WithSSAOBias(bias float32) SSAOHandlerOption

WithSSAOBias sets the depth comparison bias used to prevent self-occlusion artifacts on flat surfaces.

Parameters:

  • bias: the depth bias (recommended: 0.025)

Returns:

  • SSAOHandlerOption: a function that applies the bias option to an ssaoHandlerImpl

func WithSSAOBlurRadius added in v0.2.0

func WithSSAOBlurRadius(radius int) SSAOHandlerOption

WithSSAOBlurRadius sets the half-width of the bilateral blur kernel in texels. A radius of 4 produces a 9-texel kernel (2×4+1).

Parameters:

  • radius: the blur kernel half-width in texels (recommended: 4)

Returns:

  • SSAOHandlerOption: a function that applies the blur radius option to an ssaoHandlerImpl

func WithSSAOHalfResolution added in v0.2.0

func WithSSAOHalfResolution(enabled bool) SSAOHandlerOption

WithSSAOHalfResolution enables or disables half-resolution SSAO. When enabled, SSAO textures are allocated at half the screen resolution in each dimension (quarter pixel count), significantly reducing compute cost at the expense of slightly softer ambient occlusion. The bilateral blur and lit shader linear sampler provide adequate upsampling quality.

Parameters:

  • enabled: true to enable half-resolution SSAO

Returns:

  • SSAOHandlerOption: a function that applies the half-resolution option to an ssaoHandlerImpl

func WithSSAOPower added in v0.2.0

func WithSSAOPower(power float32) SSAOHandlerOption

WithSSAOPower sets the exponent applied to the final AO value. Higher values produce darker, more contrasty occlusion.

Parameters:

  • power: the power exponent (recommended: 2.0)

Returns:

  • SSAOHandlerOption: a function that applies the power option to an ssaoHandlerImpl

func WithSSAORadius added in v0.2.0

func WithSSAORadius(radius float32) SSAOHandlerOption

WithSSAORadius sets the hemisphere sampling radius in world-space units. Larger radii detect occlusion over longer distances but may introduce halo artifacts.

Parameters:

  • radius: the sampling radius in world units (recommended: 0.5)

Returns:

  • SSAOHandlerOption: a function that applies the radius option to an ssaoHandlerImpl

func WithSSAOSampleCount added in v0.2.0

func WithSSAOSampleCount(count int) SSAOHandlerOption

WithSSAOSampleCount sets the number of hemisphere samples per pixel. Higher values produce smoother AO at the cost of more texture fetches. Clamped to [1, 32] during compute dispatch.

Parameters:

  • count: the number of samples (recommended: 16)

Returns:

  • SSAOHandlerOption: a function that applies the sample count option to an ssaoHandlerImpl

func WithSSAOScreenSize added in v0.2.0

func WithSSAOScreenSize(width, height int) SSAOHandlerOption

WithSSAOScreenSize sets the initial screen dimensions used for SSAO texture allocation. These should match the surface dimensions at the time of initialization.

Parameters:

  • width: the screen width in pixels
  • height: the screen height in pixels

Returns:

  • SSAOHandlerOption: a function that applies the screen size option to an ssaoHandlerImpl

type SSRHandler added in v0.2.0

type SSRHandler interface {
	// Enabled returns whether the SSR subsystem has been GPU-initialized
	// and is ready for rendering.
	//
	// Returns:
	//   - bool: true if SSR GPU resources have been initialized
	Enabled() bool

	// SetEnabled sets whether the SSR subsystem is GPU-initialized.
	//
	// Parameters:
	//   - enabled: true to mark as initialized
	SetEnabled(enabled bool)

	// ScreenWidth returns the current screen width in pixels used for texture sizing.
	//
	// Returns:
	//   - int: the screen width
	ScreenWidth() int

	// ScreenHeight returns the current screen height in pixels used for texture sizing.
	//
	// Returns:
	//   - int: the screen height
	ScreenHeight() int

	// MaxSteps returns the maximum number of ray march steps per pixel.
	//
	// Returns:
	//   - int: the max step count
	MaxSteps() int

	// MaxDistance returns the maximum ray march distance in view-space units.
	//
	// Returns:
	//   - float32: the max distance
	MaxDistance() float32

	// Thickness returns the depth thickness tolerance for hit detection.
	//
	// Returns:
	//   - float32: the thickness value
	Thickness() float32

	// Stride returns the step stride multiplier for the ray march.
	//
	// Returns:
	//   - float32: the stride multiplier
	Stride() float32

	// RoughnessCutoff returns the roughness value above which SSR is skipped.
	//
	// Returns:
	//   - float32: the roughness cutoff
	RoughnessCutoff() float32

	// PipelineKey retrieves the pipeline key associated with the given name.
	// Returns an empty string if the name does not exist.
	//
	// Parameters:
	//   - name: the pipeline name
	//
	// Returns:
	//   - string: the pipeline key, or empty if not found
	PipelineKey(name string) string

	// PipelineKeys returns the full map of pipeline keys.
	//
	// Returns:
	//   - map[string]string: all registered pipeline name-to-key mappings
	PipelineKeys() map[string]string

	// SetPipelineKey stores a pipeline key under the given name.
	//
	// Parameters:
	//   - name: the pipeline name
	//   - key: the pipeline key
	SetPipelineKey(name, key string)

	// Bgp retrieves the bind group provider associated with the given key.
	// Returns nil if the key does not exist.
	//
	// Parameters:
	//   - key: the bind group provider name
	//
	// Returns:
	//   - bind_group_provider.BindGroupProvider: the provider, or nil if not found
	Bgp(key string) bind_group_provider.BindGroupProvider

	// Bgps returns the full map of bind group providers.
	//
	// Returns:
	//   - map[string]bind_group_provider.BindGroupProvider: all registered providers
	Bgps() map[string]bind_group_provider.BindGroupProvider

	// SetBgp stores a bind group provider under the given key.
	//
	// Parameters:
	//   - key: the bind group provider name
	//   - bgp: the bind group provider
	SetBgp(key string, bgp bind_group_provider.BindGroupProvider)

	// SSRTexture returns the RGBA16Float texture storing the SSR ray march result
	// at half resolution. RGB = reflected color, A = confidence.
	//
	// Returns:
	//   - *wgpu.Texture: the SSR result texture, or nil if not initialized
	SSRTexture() *wgpu.Texture

	// SetSSRTexture sets the SSR result texture.
	//
	// Parameters:
	//   - t: the SSR result texture
	SetSSRTexture(t *wgpu.Texture)

	// SSRTextureView returns the texture view for the SSR result texture.
	//
	// Returns:
	//   - *wgpu.TextureView: the SSR texture view, or nil if not initialized
	SSRTextureView() *wgpu.TextureView

	// SetSSRTextureView sets the texture view for the SSR result texture.
	//
	// Parameters:
	//   - tv: the SSR texture view
	SetSSRTextureView(tv *wgpu.TextureView)

	// LinearSampler returns the linear sampler used when the composition shader
	// samples the SSR result texture.
	//
	// Returns:
	//   - *wgpu.Sampler: the linear sampler, or nil if not initialized
	LinearSampler() *wgpu.Sampler

	// SetLinearSampler sets the linear sampler for SSR texture sampling.
	//
	// Parameters:
	//   - s: the linear sampler
	SetLinearSampler(s *wgpu.Sampler)

	// Resize updates the screen dimensions for texture sizing. Existing
	// textures are not automatically recreated — call the appropriate texture
	// creation method if the dimensions change while the handler is enabled.
	//
	// Parameters:
	//   - width: the new screen width in pixels
	//   - height: the new screen height in pixels
	Resize(width, height int)

	// HiZTexture returns the R32Float Hi-Z depth pyramid texture.
	//
	// Returns:
	//   - *wgpu.Texture: the Hi-Z texture, or nil if not initialized
	HiZTexture() *wgpu.Texture

	// SetHiZTexture sets the Hi-Z depth pyramid texture.
	//
	// Parameters:
	//   - t: the Hi-Z texture
	SetHiZTexture(t *wgpu.Texture)

	// HiZTextureView returns the full mip chain texture view for the Hi-Z pyramid,
	// used by the SSR compute shader to sample at arbitrary mip levels.
	//
	// Returns:
	//   - *wgpu.TextureView: the full mip chain view, or nil if not initialized
	HiZTextureView() *wgpu.TextureView

	// SetHiZTextureView sets the full mip chain texture view for the Hi-Z pyramid.
	//
	// Parameters:
	//   - tv: the full mip chain texture view
	SetHiZTextureView(tv *wgpu.TextureView)

	// HiZMipCount returns the number of mip levels in the Hi-Z depth pyramid.
	//
	// Returns:
	//   - int: the mip level count
	HiZMipCount() int

	// SetHiZMipCount sets the number of mip levels in the Hi-Z depth pyramid.
	//
	// Parameters:
	//   - count: the mip level count
	SetHiZMipCount(count int)

	// HiZMipReadViews returns the per-mip-level texture read views used as
	// input for Hi-Z downsample passes.
	//
	// Returns:
	//   - []*wgpu.TextureView: per-mip read views
	HiZMipReadViews() []*wgpu.TextureView

	// SetHiZMipReadViews sets the per-mip-level texture read views.
	//
	// Parameters:
	//   - views: per-mip read views
	SetHiZMipReadViews(views []*wgpu.TextureView)

	// HiZStorageViews returns the per-mip-level storage texture views used as
	// output for Hi-Z downsample passes.
	//
	// Returns:
	//   - []*wgpu.TextureView: per-mip storage write views
	HiZStorageViews() []*wgpu.TextureView

	// SetHiZStorageViews sets the per-mip-level storage texture views.
	//
	// Parameters:
	//   - views: per-mip storage write views
	SetHiZStorageViews(views []*wgpu.TextureView)
}

SSRHandler defines the interface for the scene's screen-space reflections subsystem.

The SSRHandler manages the ray march configuration, the SSR result texture, compute pipeline keys, and bind group providers needed by the SSR compute shader. It is created via NewSSRHandler with builder options and attached to a scene's lighting handler. GPU resources are initialized lazily by the owning scene when SSR is first enabled.

Thread safety is provided by the owning scene's mutex — the handler itself does not perform internal locking.

func NewSSRHandler added in v0.2.0

func NewSSRHandler(opts ...SSRHandlerOption) SSRHandler

NewSSRHandler creates a new SSRHandler with sensible defaults and any provided options applied. GPU resources are not allocated until the owning scene calls the appropriate initialization methods.

Default values:

  • MaxSteps: 64
  • MaxDistance: 50.0
  • Thickness: 0.1
  • Stride: 1.0
  • RoughnessCutoff: 0.5

Parameters:

  • opts: variadic list of SSRHandlerOption functions to configure the handler

Returns:

  • SSRHandler: a new handler instance ready to be attached to a scene

type SSRHandlerOption added in v0.2.0

type SSRHandlerOption func(*ssrHandlerImpl)

SSRHandlerOption is a functional option for configuring an SSRHandler during construction via NewSSRHandler.

func WithSSRMaxDistance added in v0.2.0

func WithSSRMaxDistance(distance float32) SSRHandlerOption

WithSSRMaxDistance sets the maximum ray march distance in view-space units. Reflections beyond this distance are discarded.

Parameters:

  • distance: the maximum distance (recommended: 50.0)

Returns:

  • SSRHandlerOption: a function that applies the max distance option to an ssrHandlerImpl

func WithSSRMaxSteps added in v0.2.0

func WithSSRMaxSteps(steps int) SSRHandlerOption

WithSSRMaxSteps sets the maximum number of ray march steps per pixel. Higher values find more reflections but cost more compute.

Parameters:

  • steps: the maximum step count (recommended: 64)

Returns:

  • SSRHandlerOption: a function that applies the max steps option to an ssrHandlerImpl

func WithSSRRoughnessCutoff added in v0.2.0

func WithSSRRoughnessCutoff(cutoff float32) SSRHandlerOption

WithSSRRoughnessCutoff sets the roughness value above which SSR is skipped. Surfaces rougher than this threshold receive no screen-space reflections.

Parameters:

  • cutoff: the roughness cutoff (recommended: 0.5)

Returns:

  • SSRHandlerOption: a function that applies the roughness cutoff option to an ssrHandlerImpl

func WithSSRScreenSize added in v0.2.0

func WithSSRScreenSize(width, height int) SSRHandlerOption

WithSSRScreenSize sets the initial screen dimensions used for SSR texture allocation. These should match the surface dimensions at the time of initialization.

Parameters:

  • width: the screen width in pixels
  • height: the screen height in pixels

Returns:

  • SSRHandlerOption: a function that applies the screen size option to an ssrHandlerImpl

func WithSSRStride added in v0.2.0

func WithSSRStride(stride float32) SSRHandlerOption

WithSSRStride sets the step stride multiplier for the ray march. A stride of 1.0 uses uniform stepping; larger strides trade accuracy for speed.

Parameters:

  • stride: the stride multiplier (recommended: 1.0)

Returns:

  • SSRHandlerOption: a function that applies the stride option to an ssrHandlerImpl

func WithSSRThickness added in v0.2.0

func WithSSRThickness(thickness float32) SSRHandlerOption

WithSSRThickness sets the depth thickness tolerance used for hit detection. Thinner values are more precise but may miss thin geometry.

Parameters:

  • thickness: the depth tolerance (recommended: 0.1)

Returns:

  • SSRHandlerOption: a function that applies the thickness option to an ssrHandlerImpl

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL