4#ifndef GREM_GRAPHICS_3D_LIGHT_BAKER_3D_HPP
5#define GREM_GRAPHICS_3D_LIGHT_BAKER_3D_HPP
181 GREM_API(graphics_3d)
205 GREM_API(graphics_3d)
232 GREM_API(graphics_3d)
253 GREM_API(graphics_3d)
279 GREM_API(graphics_3d)
300 GREM_API(graphics_3d)
342 GREM_API(graphics_3d)
362 GREM_API(graphics_3d)
390 .maxAnisotropy = 1.0f,
398 struct CubemapIrradianceFragmentShaderConstants {
399 uint32_t IRRADIANCE_SAMPLE_COUNT;
402 struct CubemapIrradianceFragmentParameters {
403 samplerCube radianceCubemapTexture;
406 using CubemapIrradianceFragmentParameterBuffer = UniformBuffer<CubemapIrradianceFragmentParameters,
"LightBaker3DCubemapIrradianceFragmentParameters">;
408 using CubemapIrradianceFragmentShader = graphics::FragmentShader<
Cubemap3D::Mesh, Cubemap3D::VertexShaderOutputs, CubemapIrradianceFragmentShaderConstants,
413 struct CubemapReflectionFragmentShaderConstants {
414 uint32_t REFLECTION_SAMPLE_COUNT;
417 struct CubemapReflectionFragmentParameters {
418 samplerCube radianceCubemapTexture;
419 samplerCubeShadow depthCubemapTexture;
420 float reflectionResolution;
421 float reflectionRoughness;
424 using CubemapReflectionFragmentParameterBuffer = UniformBuffer<CubemapReflectionFragmentParameters,
"LightBaker3DCubemapReflectionFragmentParameters">;
426 using CubemapReflectionFragmentShader = graphics::FragmentShader<
Cubemap3D::Mesh, Cubemap3D::VertexShaderOutputs, CubemapReflectionFragmentShaderConstants,
431 struct CubemapFromEquirectangularFragmentShaderConstants {};
433 struct CubemapFromEquirectangularFragmentParameters {
434 sampler2D equirectangularTexture;
437 using CubemapFromEquirectangularFragmentParameterBuffer =
438 UniformBuffer<CubemapFromEquirectangularFragmentParameters,
"LightBaker3DCubemapFromEquirectangularFragmentParameters">;
440 using CubemapFromEquirectangularFragmentShader = graphics::FragmentShader<
Cubemap3D::Mesh, Cubemap3D::VertexShaderOutputs, CubemapFromEquirectangularFragmentShaderConstants,
445 struct LightProbeAtlasVertex {
449 using LightProbeAtlasMesh = Mesh<LightProbeAtlasVertex>;
451 struct LightProbeAtlasVertexShaderConstants {};
453 struct LightProbeAtlasVertexShaderOutputs {
454 vec2 fragmentTextureCoordinates;
457 using LightProbeAtlasVertexShader = VertexShader<LightProbeAtlasMesh, LightProbeAtlasVertexShaderConstants, LightProbeAtlasVertexShaderOutputs>;
459 struct LightProbeAtlasIrradianceFragmentShaderConstants {
460 uint32_t IRRADIANCE_SAMPLE_COUNT;
463 struct LightProbeAtlasDistanceFragmentShaderConstants {
464 uint32_t DISTANCE_SAMPLE_COUNT;
467 struct LightProbeAtlasFragmentShaderOutputs {
471 struct LightProbeAtlasIrradianceFragmentParameters {
472 samplerCube radianceCubemapTexture;
473 float irradianceMapPadding;
476 using LightProbeAtlasIrradianceFragmentParameterBuffer = UniformBuffer<LightProbeAtlasIrradianceFragmentParameters,
"LightBaker3DLightProbeAtlasIrradianceFragmentParameters">;
478 using LightProbeAtlasIrradianceFragmentShader = FragmentShader<LightProbeAtlasMesh, LightProbeAtlasVertexShaderOutputs, LightProbeAtlasIrradianceFragmentShaderConstants,
479 LightProbeAtlasFragmentShaderOutputs, LightProbeAtlasIrradianceFragmentParameterBuffer>;
481 struct LightProbeAtlasDistanceFragmentParameters {
482 samplerCube distanceCubemapTexture;
483 float distanceMapPadding;
484 float distanceSharpness;
485 float distanceMaxDistance;
488 using LightProbeAtlasDistanceFragmentParameterBuffer = UniformBuffer<LightProbeAtlasDistanceFragmentParameters,
"LightBaker3DLightProbeAtlasDistanceFragmentParameters">;
490 using LightProbeAtlasDistanceFragmentShader = FragmentShader<LightProbeAtlasMesh, LightProbeAtlasVertexShaderOutputs, LightProbeAtlasDistanceFragmentShaderConstants,
491 LightProbeAtlasFragmentShaderOutputs, LightProbeAtlasDistanceFragmentParameterBuffer>;
493 using LightProbeAtlasShaderPipeline = ShaderPipeline<LightProbeAtlasMesh>;
497 struct CubemapBaker {
506 CubemapFromEquirectangularFragmentParameterBuffer cubemapFromEquirectangularFragmentParameterBuffer;
507 CubemapIrradianceFragmentParameterBuffer cubemapIrradianceFragmentParameterBuffer;
508 CubemapReflectionFragmentParameterBuffer cubemapReflectionFragmentParameterBuffer;
509 DrawCommandBuffer<Cubemap3D::Mesh> cubemapFromEquirectangularDrawCommandBuffer;
510 DrawCommandBuffer<Cubemap3D::Mesh> cubemapIrradianceDrawCommandBuffer;
511 DrawCommandBuffer<Cubemap3D::Mesh> cubemapReflectionDrawCommandBuffer;
514 struct LightProbeBaker {
516 Texture distanceBuffer;
517 Texture depthStencilBuffer;
518 LightProbeAtlasMesh lightProbeAtlasMesh;
519 LightProbeAtlasShaderPipeline lightProbeAtlasIrradianceShaderPipeline;
520 LightProbeAtlasShaderPipeline lightProbeAtlasDistanceShaderPipeline;
521 LightProbeAtlasIrradianceFragmentParameterBuffer lightProbeAtlasIrradianceFragmentParameterBuffer;
522 LightProbeAtlasDistanceFragmentParameterBuffer lightProbeAtlasDistanceFragmentParameterBuffer;
523 DrawCommandBuffer<LightProbeAtlasMesh> lightProbeAtlasIrradianceDrawCommandBuffer;
524 DrawCommandBuffer<LightProbeAtlasMesh> lightProbeAtlasDistanceDrawCommandBuffer;
525 mat4 renderProjectionMatrix;
528 struct ReflectionProbeBaker {
530 Texture depthStencilBuffer;
532 CubemapReflectionFragmentParameterBuffer cubemapReflectionFragmentParameterBuffer;
533 DrawCommandBuffer<Cubemap3D::Mesh> reflectionMapsDrawCommandBuffer;
534 mat4 renderProjectionMatrix;
537 [[nodiscard]] GREM_API(graphics_3d) CubemapBaker& getCubemapBaker();
538 [[nodiscard]] GREM_API(graphics_3d) SkyBaker& getSkyBaker();
539 [[nodiscard]] GREM_API(graphics_3d) LightProbeBaker& getLightProbeBaker();
540 [[nodiscard]] GREM_API(graphics_3d) ReflectionProbeBaker& getReflectionProbeBaker();
543 Renderer3D& renderer3D;
544 LightBaker3DOptions options;
545 Optional<CubemapBaker> cubemapBakerStorage{};
546 Optional<SkyBaker> skyBakerStorage{};
547 Optional<LightProbeBaker> lightProbeBakerStorage{};
548 Optional<ReflectionProbeBaker> reflectionProbeBakerStorage{};
Definition FunctionView.hpp:29
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Combined view-projection matrix, defining a 3D perspective to render from.
Definition Camera3D.hpp:173
graphics::Mesh< Vertex, Index > Mesh
Cubemap mesh primitive type.
Definition Cubemap3D.hpp:33
UniformBuffer< PerspectiveParameters, "Cubemap3DPerspective"> PerspectiveBuffer
Shader buffer for cubemap perspective parameters.
Definition Cubemap3D.hpp:54
graphics::ShaderPipeline< Mesh > ShaderPipeline
Shader pipeline for drawing cubemaps.
Definition Cubemap3D.hpp:60
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
void bakeReflectionProbeReflectionMap(ReflectionProbes3D &reflectionProbes, uint32_t reflectionProbeIndex, FunctionView< void(RenderPass &, const Camera3D &)> drawReflection)
Render the reflection map of a single reflection probe in a set of reflection probes.
Texture generateCubemapFromEquirectangularMap(TextureFormat internalFormat, uint32_t resolution, const Texture &equirectangularMap, Optional< TextureSamplerOptions > samplerOptions=TextureSamplerOptions{ .minificationFilter=TextureFilter::LINEAR,.magnificationFilter=TextureFilter::LINEAR,.mipmapMode=TextureMipmapMode::NONE,.horizontalWrappingMode=TextureWrappingMode::CLAMP_TO_EDGE,.verticalWrappingMode=TextureWrappingMode::CLAMP_TO_EDGE,.maxAnisotropy=1.0f, })
Generate a cubemap from a 2D equirectangular map texture.
void bakeDiffuseLighting(LightProbeVolumes3D &lightProbeVolumes, FunctionView< void(RenderPass &, const Camera3D &)> drawRadiance, FunctionView< void(RenderPass &, const Camera3D &)> drawDistance)
Render the irradiance and distance maps of a set of light probe volumes.
void bakeAllLightProbeIrradianceMaps(LightProbeVolumes3D &lightProbeVolumes, FunctionView< void(RenderPass &, const Camera3D &)> drawRadiance)
Render the irradiance maps of all light probes of all volumes in a set of light probe volumes.
void bakeSkybox(Sky3D &sky, Texture newSkyTexture, const Sky3DOptions &newSkyOptions)
Render a sky map texture onto a sky.
void bakeAllReflectionProbeReflectionMaps(ReflectionProbes3D &reflectionProbes, FunctionView< void(RenderPass &, const Camera3D &)> drawReflection)
Render all reflection maps in a set of reflection probes.
void bakeAllLightProbeDistanceMaps(LightProbeVolumes3D &lightProbeVolumes, FunctionView< void(RenderPass &, const Camera3D &)> drawDistance)
Render the distance maps of all light probes of all volumes in a set of light probe volumes.
LightBaker3D(Device &device, Renderer3D &renderer3D, const LightBaker3DOptions &options={})
Construct a light baker.
void bakeLightProbeIrradianceMap(LightProbeVolumes3D &lightProbeVolumes, uint32_t lightProbeVolumeIndex, u32vec3 lightProbeGridIndices, FunctionView< void(RenderPass &, const Camera3D &)> drawRadiance)
Render the irradiance map of a single light probe of a specific volume in a set of light probe volume...
void bakeLightProbeDistanceMap(LightProbeVolumes3D &lightProbeVolumes, uint32_t lightProbeVolumeIndex, u32vec3 lightProbeGridIndices, FunctionView< void(RenderPass &, const Camera3D &)> drawDistance)
Render the distance map of a single light probe of a specific volume in a set of light probe volumes.
void bakeSpecularReflections(ReflectionProbes3D &reflectionProbes, FunctionView< void(RenderPass &, const Camera3D &)> drawReflection)
Render the reflection maps of a set of reflection probes.
Set of light probe volumes in 3D space.
Definition LightProbeVolumes3D.hpp:89
Set of reflection probes in 3D space.
Definition ReflectionProbes3D.hpp:106
Backend-specific implementation of RenderPass.
Definition RenderPass.hpp:38
Persistent system that provides 3D rendering capabilities.
Definition Renderer3D.hpp:120
Skybox in 3D space.
Definition Sky3D.hpp:81
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configurati...
Definition Texture.hpp:700
Definition buffer_layouts.hpp:20
@ CLAMP_TO_EDGE
Clamp to the edge of the texture when sampling outside the 0-1 range.
Definition Texture.hpp:492
TextureFormat
Description of the internal format of a Texture.
Definition Texture.hpp:267
@ NONE
Always use the most detailed mip level (level 0).
Definition Texture.hpp:482
@ LINEAR
Interpolate between texels for a smoother appearance.
Definition Texture.hpp:475
Array(T, Us...) -> Array< T, 1+sizeof...(Us)>
vec< 4, float > vec4
Definition math.hpp:440
vec< 3, uint32_t > u32vec3
Definition math.hpp:419
vec< 2, float > vec2
Definition math.hpp:438
mat< 4, 4, float > mat4
Definition math.hpp:806
Configuration options for a LightBaker3D.
Definition LightBaker3D.hpp:31
uint32_t lightProbeIrradianceSampleCount
Number of samples to use when baking the irradiance maps of light probes.
Definition LightBaker3D.hpp:78
float lightProbeNearZ
Distance to the near plane of light probes.
Definition LightBaker3D.hpp:59
float reflectionProbeNearZ
Distance to the near plane of reflection probes.
Definition LightBaker3D.hpp:107
uint32_t lightProbeDistanceSampleCount
Number of samples to use when baking the distance maps of light probes.
Definition LightBaker3D.hpp:85
uint32_t reflectionProbeRenderResolution
Width, in texels, of the source cubemaps used to render the reflection maps of reflection probes.
Definition LightBaker3D.hpp:100
uint32_t skyReflectionSampleCount
Number of samples to use when baking the reflection cubemap of skyboxes.
Definition LightBaker3D.hpp:44
uint32_t lightProbeRenderResolution
Width, in texels, of the source cubemaps used to render the irradiance and distance maps of light pro...
Definition LightBaker3D.hpp:52
float reflectionProbeFarZ
Distance to the far plane of reflection probes.
Definition LightBaker3D.hpp:114
uint32_t skyIrradianceSampleCount
Number of samples to use when baking the irradiance cubemap of skyboxes.
Definition LightBaker3D.hpp:37
float lightProbeExposure
Camera exposure to use when baking the irradiance maps of light probes.
Definition LightBaker3D.hpp:71
float lightProbeDistanceSharpness
Exponent of the cosine weight between normal and sample direction to use when baking the distance map...
Definition LightBaker3D.hpp:92
float reflectionProbeExposure
Camera exposure to use when baking the reflection maps of reflection probes.
Definition LightBaker3D.hpp:120
uint32_t reflectionProbeReflectionSampleCount
Number of samples to use when baking the reflection maps of reflection probes.
Definition LightBaker3D.hpp:128
float lightProbeFarZ
Distance to the far plane of light probes.
Definition LightBaker3D.hpp:66
Configuration options for a Sky3D.
Definition Sky3D.hpp:27
Configuration options for a texture image upload.
Definition Texture.hpp:550
bool convertToPremultipliedAlpha
Convert the uploaded image from straight to pre-multiplied alpha.
Definition Texture.hpp:565
Configuration options for the sampler of a Texture.
Definition Texture.hpp:617
TextureFilter minificationFilter
Filtering mode to use when the texture is rendered smaller than its original size.
Definition Texture.hpp:628