20 std::vector<CameraComponent*> CameraComponent::_instances;
24 _instances.push_back(
this);
29 const auto it = std::find(_instances.begin(), _instances.end(),
this);
30 if (it != _instances.end()) {
35 _cameraFrame->destroy();
55 _renderSceneColorMap +=
enabled ? 1 : -1;
56 assert(_renderSceneColorMap >= 0);
57 if (_renderSceneColorMap < 0) {
58 _renderSceneColorMap = 0;
61 if (
const auto* systemPtr =
system()) {
62 if (
const auto* engine = systemPtr->engine()) {
70 _renderSceneDepthMap +=
enabled ? 1 : -1;
71 assert(_renderSceneDepthMap >= 0);
72 if (_renderSceneDepthMap < 0) {
73 _renderSceneDepthMap = 0;
76 if (
const auto* systemPtr =
system()) {
77 if (
const auto* engine = systemPtr->engine()) {
96 _cameraFrame->destroy();
112 _camera->setJitter(_taa.enabled ? std::max(_taa.jitter, 0.0f) : 0.0f);
116 _cameraFrame->destroy();
117 _cameraFrame.reset();
130 if (_ssao.enabled ==
enabled) {
144 _cameraFrame->destroy();
145 _cameraFrame.reset();
156 void CameraComponent::ensureDofRenderTarget()
158 const auto* componentSystem =
system();
159 const auto* app = componentSystem ? componentSystem->engine() :
nullptr;
160 const auto graphicsDevice = app ? app->graphicsDevice() :
nullptr;
161 if (!graphicsDevice) {
165 const auto [width, height] = graphicsDevice->size();
166 const bool needsCreate = !_dofSceneColorTexture || !_dofSceneRenderTarget ||
167 static_cast<int>(_dofSceneColorTexture->width()) != width ||
168 static_cast<int>(_dofSceneColorTexture->height()) != height;
174 TextureOptions textureOptions;
175 textureOptions.name =
"DofSceneColor";
176 textureOptions.width = std::max(width, 1);
177 textureOptions.height = std::max(height, 1);
179 textureOptions.mipmaps =
false;
182 _dofSceneColorTexture = std::make_shared<Texture>(graphicsDevice.get(), textureOptions);
186 RenderTargetOptions targetOptions;
187 targetOptions.graphicsDevice = graphicsDevice.get();
188 targetOptions.colorBuffer = _dofSceneColorTexture.get();
189 targetOptions.depth =
true;
190 targetOptions.stencil =
false;
191 targetOptions.name =
"DofSceneTarget";
192 _dofSceneRenderTarget = graphicsDevice->createRenderTarget(targetOptions);
195 void CameraComponent::updatePostprocessRenderTargetBinding()
const
201 if (requiresPostprocessRenderTarget()) {
202 if (_dofSceneRenderTarget) {
203 _camera->setRenderTarget(_dofSceneRenderTarget);
205 }
else if (_camera->renderTarget() == _dofSceneRenderTarget) {
206 _camera->setRenderTarget(
nullptr);
213 if (!device || !sourceTexture || !_taa.enabled) {
218 _taaPass = std::make_shared<RenderPassTAA>(device, sourceTexture,
this);
220 _taaPass->setSourceTexture(sourceTexture);
222 _taaPass->setHighQuality(_taa.highQuality);
bool renderSceneColorMap() const
void requestSceneDepthMap(bool enabled)
void setTaaEnabled(bool enabled)
CameraComponent(IComponentSystem *system, Entity *entity)
void setSsaoEnabled(bool enabled)
void setDofEnabled(bool enabled)
std::shared_ptr< RenderPassTAA > ensureTaaPass(const std::shared_ptr< GraphicsDevice > &device, Texture *sourceTexture)
bool renderSceneDepthMap() const
void requestSceneColorMap(bool enabled)
void initializeComponentData() override
Perspective or orthographic camera with projection matrix, jitter (TAA), and render target binding.
virtual bool enabled() const
Component(IComponentSystem *system, Entity *entity)
IComponentSystem * system() const
ECS entity — a GraphNode that hosts components defining its behavior.
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.