VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
renderPassCoC.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4//
5#include "renderPassCoC.h"
6
7#include <algorithm>
8
9#include "scene/camera.h"
11
12namespace visutwin::canvas
13{
14 RenderPassCoC::RenderPassCoC(const std::shared_ptr<GraphicsDevice>& device, CameraComponent* cameraComponent,
15 const bool nearBlur)
16 : RenderPassShaderQuad(device), _cameraComponent(cameraComponent), _nearBlur(nearBlur)
17 {
18 }
19
21 {
22 _params[0] = focusDistance + 0.001f;
23 _params[1] = std::max(focusRange, 0.001f);
24 _params[2] = 1.0f / _params[1];
25
26 const auto* camera = _cameraComponent ? _cameraComponent->camera() : nullptr;
27 if (!camera) return;
28
29 const auto gd = device();
30 if (!gd) return;
31
32 // Get depth texture from the graphics device (same mechanism as SSAO)
33 Texture* depthTexture = gd->sceneDepthMap();
34 if (!depthTexture) {
35 // Fall back to shader quad path if no depth texture available
36 if (camera) {
37 _cameraParams[0] = camera->nearClip();
38 _cameraParams[1] = camera->farClip();
39 _cameraParams[2] = camera->projection() == ProjectionType::Perspective ? 1.0f : 0.0f;
40 _cameraParams[3] = _nearBlur ? 1.0f : 0.0f;
41 }
43 return;
44 }
45
46 CoCPassParams params;
47 params.depthTexture = depthTexture;
49 params.focusRange = std::max(focusRange, 0.001f);
50 params.cameraNear = camera->nearClip();
51 params.cameraFar = camera->farClip();
52 params.nearBlur = _nearBlur;
53 gd->executeCoCPass(params);
54 }
55}
56
RenderPassCoC(const std::shared_ptr< GraphicsDevice > &device, CameraComponent *cameraComponent, bool nearBlur)
std::shared_ptr< GraphicsDevice > device() const
Definition renderPass.h:124
RenderPassShaderQuad(const std::shared_ptr< GraphicsDevice > &device)
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
Definition texture.h:57