1#include "EngineBindGroups.h"
5#include "RenderTarget.h"
7#include "Rendering/IContext.h"
8#include "Systems/Core/LightSystem.h"
9#include "Systems/Core/EnvironmentSystem.h"
10#include "Tasks/RenderTask.h"
12#include "RenderResources.h"
13#include "RenderTexture.h"
15#include "Resources/TextureManager.h"
16#include "Resources/ShaderBuilderHelpersWebGPU.h"
18#include "Rendering/IBindGroups.h"
20void Cogs::Core::initializeEngineBindGroups(IBindGroups * bindGroups, EngineBindGroups & engineBindGroups)
22 if (!bindGroups)
return;
24 const BindGroupSetDescription & desc = getEngineBindGroupDescription();
25 const BindGroupDescription & lightTextures = desc.groups[
static_cast<size_t>(BindGroup::LightTextures)];
26 if (lightTextures.numEntries == 0)
return;
28 engineBindGroups.lightTextures = bindGroups->createBindGroup(&lightTextures);
31 BindGroupHandle handle = engineBindGroups.lightTextures;
32 engineBindGroups.skyBinding = bindGroups->getTextureBinding(handle,
"environmentSky");
33 engineBindGroups.radianceBinding = bindGroups->getTextureBinding(handle,
"environmentRadiance");
34 engineBindGroups.irradianceBinding = bindGroups->getTextureBinding(handle,
"environmentIrradiance");
35 engineBindGroups.ambientIrradianceBinding = bindGroups->getTextureBinding(handle,
"ambientIrradiance");
36 engineBindGroups.brdfLUTBinding = bindGroups->getTextureBinding(handle,
"brdfLUT");
37 engineBindGroups.shadowArrayBinding = bindGroups->getTextureBinding(handle,
"cascadedShadowMap");
38 engineBindGroups.shadowCubeArrayBinding = bindGroups->getTextureBinding(handle,
"cubeShadowMap");
40 engineBindGroups.linearSamplerBinding = bindGroups->getSamplerBinding(handle,
"linearSampler");
41 engineBindGroups.linearClampSampler = bindGroups->getSamplerBinding(handle,
"linearClampSampler");
42 engineBindGroups.pointSampler = bindGroups->getSamplerBinding(handle,
"pointSampler");
43 engineBindGroups.pointClampSampler = bindGroups->getSamplerBinding(handle,
"pointClampSampler");
44 engineBindGroups.shadowSamplerBinding = bindGroups->getSamplerBinding(handle,
"shadowSampler");
47void Cogs::Core::updateLightTexturesBindGroup(RenderTaskContext* taskContext)
49 IGraphicsDevice* device = taskContext->renderer->getDevice();
50 IBindGroups* bindGroups = device->getBindGroups();
51 IContext* deviceContext = device->getImmediateContext();
52 if (!bindGroups)
return;
54 EngineBindGroups& engineBindGroups = taskContext->renderer->getEngineBindGroups();
57 BindGroupHandle handle = engineBindGroups.lightTextures;
58 RenderResources& renderResources = taskContext->renderer->getRenderResources();
59 TextureManager* textureManager = taskContext->context->textureManager;
70 const EnvironmentComponent* environmentComponent = taskContext->context->environmentSystem->getGlobalEnvironment();
71 if (environmentComponent) {
72 if (environmentComponent->isSubmerged(taskContext->cameraData)) {
73 if (environmentComponent->subseaRadiance) {
74 RenderTexture* subseaRadianceTexture = renderResources.getRenderTexture(environmentComponent->subseaRadiance);
75 if (subseaRadianceTexture && subseaRadianceTexture->description.target == ResourceDimensions::TextureCube) {
76 skyTexture = subseaRadianceTexture->textureHandle;
77 radianceTexture = subseaRadianceTexture->textureHandle;
78 irradianceTexture = subseaRadianceTexture->textureHandle;
79 ambientIrradianceTexture = subseaRadianceTexture->textureHandle;
83 if (environmentComponent->skyDome) {
84 RenderTexture* tex = renderResources.getRenderTexture(environmentComponent->skyDome);
85 if (tex && tex->description.target == ResourceDimensions::TextureCube) skyTexture = tex->textureHandle;
87 if (environmentComponent->radiance) {
88 RenderTexture* tex = renderResources.getRenderTexture(environmentComponent->radiance);
89 if (tex && tex->description.target == ResourceDimensions::TextureCube) radianceTexture = tex->textureHandle;
91 if (environmentComponent->irradiance) {
92 RenderTexture* tex = renderResources.getRenderTexture(environmentComponent->irradiance);
93 if (tex && tex->description.target == ResourceDimensions::TextureCube) irradianceTexture = tex->textureHandle;
95 if (environmentComponent->ambientIrradiance) {
96 RenderTexture* tex = renderResources.getRenderTexture(environmentComponent->ambientIrradiance);
97 if (tex && tex->description.target == ResourceDimensions::TextureCube) ambientIrradianceTexture = tex->textureHandle;
99 if (environmentComponent->brdfLUT) {
100 RenderTexture* tex = renderResources.getRenderTexture(environmentComponent->brdfLUT);
101 if (tex && tex->description.target == ResourceDimensions::Texture2D) brdfLUTTexture = tex->textureHandle;
107 if (RenderTexture* tex = renderResources.getRenderTexture(textureManager->whiteCube)) skyTexture = tex->textureHandle;
110 if (RenderTexture* tex = renderResources.getRenderTexture(textureManager->whiteCube)) radianceTexture = tex->textureHandle;
113 if (RenderTexture* tex = renderResources.getRenderTexture(textureManager->whiteCube)) irradianceTexture = tex->textureHandle;
116 if (RenderTexture* tex = renderResources.getRenderTexture(textureManager->whiteCube)) ambientIrradianceTexture = tex->textureHandle;
119 if (RenderTexture* tex = renderResources.getRenderTexture(textureManager->white)) brdfLUTTexture = tex->textureHandle;
123 if (RenderTexture* tex = renderResources.getRenderTexture(taskContext->context->lightSystem->cascadeArray)) shadowArrayTexture = tex->textureHandle;
125 if (RenderTexture* tex = renderResources.getRenderTexture(textureManager->whiteDepthArray)) shadowArrayTexture = tex->textureHandle;
129 if (RenderTexture* tex = renderResources.getRenderTexture(taskContext->context->lightSystem->cubeArray)) shadowCubeArrayTexture = tex->textureHandle;
131 if (RenderTexture* tex = renderResources.getRenderTexture(textureManager->whiteDepthCube)) shadowCubeArrayTexture = tex->textureHandle;
133 bindGroups->setTexture(handle, engineBindGroups.skyBinding, skyTexture);
134 bindGroups->setTexture(handle, engineBindGroups.radianceBinding, radianceTexture);
135 bindGroups->setTexture(handle, engineBindGroups.irradianceBinding, irradianceTexture);
136 bindGroups->setTexture(handle, engineBindGroups.ambientIrradianceBinding, ambientIrradianceTexture);
137 bindGroups->setTexture(handle, engineBindGroups.brdfLUTBinding, brdfLUTTexture);
138 bindGroups->setTexture(handle, engineBindGroups.shadowArrayBinding, shadowArrayTexture);
139 bindGroups->setTexture(handle, engineBindGroups.shadowCubeArrayBinding, shadowCubeArrayTexture);
141 bindGroups->setSamplerState(handle, engineBindGroups.linearSamplerBinding, taskContext->states->defaultSampler);
142 bindGroups->setSamplerState(handle, engineBindGroups.linearClampSampler, taskContext->states->commonSamplerStates[1]);
143 bindGroups->setSamplerState(handle, engineBindGroups.pointSampler, taskContext->states->commonSamplerStates[2]);
144 bindGroups->setSamplerState(handle, engineBindGroups.pointClampSampler, taskContext->states->commonSamplerStates[3]);
145 bindGroups->setSamplerState(handle, engineBindGroups.shadowSamplerBinding, taskContext->states->shadowSampler);
147 deviceContext->setBindGroup(engineBindGroups.lightTextures,
static_cast<uint32_t
>(BindGroup::LightTextures));
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
static const Handle_t NoHandle
Represents a handle to nothing.