1/**************************************************************************/
2/* bokeh_dof.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef BOKEH_DOF_RD_H
32#define BOKEH_DOF_RD_H
33
34#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
35#include "servers/rendering/renderer_rd/shaders/effects/bokeh_dof.glsl.gen.h"
36#include "servers/rendering/renderer_rd/shaders/effects/bokeh_dof_raster.glsl.gen.h"
37#include "servers/rendering/renderer_scene_render.h"
38
39#include "servers/rendering_server.h"
40
41namespace RendererRD {
42
43class BokehDOF {
44private:
45 bool prefer_raster_effects;
46
47 struct BokehPushConstant {
48 uint32_t size[2];
49 float z_far;
50 float z_near;
51
52 uint32_t orthogonal;
53 float blur_size;
54 float blur_scale;
55 uint32_t steps;
56
57 uint32_t blur_near_active;
58 float blur_near_begin;
59 float blur_near_end;
60 uint32_t blur_far_active;
61
62 float blur_far_begin;
63 float blur_far_end;
64 uint32_t second_pass;
65 uint32_t half_size;
66
67 uint32_t use_jitter;
68 float jitter_seed;
69 uint32_t use_physical_near;
70 uint32_t use_physical_far;
71
72 float blur_size_near;
73 float blur_size_far;
74 uint32_t pad[2];
75 };
76
77 enum BokehMode {
78 BOKEH_GEN_BLUR_SIZE,
79 BOKEH_GEN_BOKEH_BOX,
80 BOKEH_GEN_BOKEH_BOX_NOWEIGHT,
81 BOKEH_GEN_BOKEH_HEXAGONAL,
82 BOKEH_GEN_BOKEH_HEXAGONAL_NOWEIGHT,
83 BOKEH_GEN_BOKEH_CIRCULAR,
84 BOKEH_COMPOSITE,
85 BOKEH_MAX
86 };
87
88 struct Bokeh {
89 BokehPushConstant push_constant;
90 BokehDofShaderRD compute_shader;
91 BokehDofRasterShaderRD raster_shader;
92 RID shader_version;
93 RID compute_pipelines[BOKEH_MAX];
94 PipelineCacheRD raster_pipelines[BOKEH_MAX];
95 } bokeh;
96
97public:
98 struct BokehBuffers {
99 // bokeh buffers
100
101 // textures
102 Size2i base_texture_size;
103 RID base_texture;
104 RID depth_texture;
105 RID secondary_texture;
106 RID half_texture[2];
107
108 // raster only
109 RID base_fb;
110 RID secondary_fb; // with weights
111 RID half_fb[2]; // with weights
112 RID base_weight_fb;
113 RID weight_texture[4];
114 };
115
116 BokehDOF(bool p_prefer_raster_effects);
117 ~BokehDOF();
118
119 void bokeh_dof_compute(const BokehBuffers &p_buffers, RID p_camera_attributes, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
120 void bokeh_dof_raster(const BokehBuffers &p_buffers, RID p_camera_attributes, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
121};
122
123} // namespace RendererRD
124
125#endif // BOKEH_DOF_RD_H
126