Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_rd/effects/bokeh_dof.h
10279 views
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
#pragma once
32
33
#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
34
#include "servers/rendering/renderer_rd/shaders/effects/bokeh_dof.glsl.gen.h"
35
#include "servers/rendering/renderer_rd/shaders/effects/bokeh_dof_raster.glsl.gen.h"
36
37
namespace RendererRD {
38
39
class BokehDOF {
40
private:
41
bool prefer_raster_effects;
42
43
struct BokehPushConstant {
44
uint32_t size[2];
45
float z_far;
46
float z_near;
47
48
uint32_t orthogonal;
49
float blur_size;
50
float blur_scale;
51
uint32_t steps;
52
53
uint32_t blur_near_active;
54
float blur_near_begin;
55
float blur_near_end;
56
uint32_t blur_far_active;
57
58
float blur_far_begin;
59
float blur_far_end;
60
uint32_t second_pass;
61
uint32_t half_size;
62
63
uint32_t use_jitter;
64
float jitter_seed;
65
uint32_t use_physical_near;
66
uint32_t use_physical_far;
67
68
float blur_size_near;
69
float blur_size_far;
70
uint32_t pad[2];
71
};
72
73
enum BokehMode {
74
BOKEH_GEN_BLUR_SIZE,
75
BOKEH_GEN_BOKEH_BOX,
76
BOKEH_GEN_BOKEH_BOX_NOWEIGHT,
77
BOKEH_GEN_BOKEH_HEXAGONAL,
78
BOKEH_GEN_BOKEH_HEXAGONAL_NOWEIGHT,
79
BOKEH_GEN_BOKEH_CIRCULAR,
80
BOKEH_COMPOSITE,
81
BOKEH_MAX
82
};
83
84
struct Bokeh {
85
BokehPushConstant push_constant;
86
BokehDofShaderRD compute_shader;
87
BokehDofRasterShaderRD raster_shader;
88
RID shader_version;
89
RID compute_pipelines[BOKEH_MAX];
90
PipelineCacheRD raster_pipelines[BOKEH_MAX];
91
} bokeh;
92
93
public:
94
struct BokehBuffers {
95
// bokeh buffers
96
97
// textures
98
Size2i base_texture_size;
99
RID base_texture;
100
RID depth_texture;
101
RID secondary_texture;
102
RID half_texture[2];
103
104
// raster only
105
RID base_fb;
106
RID secondary_fb; // with weights
107
RID half_fb[2]; // with weights
108
RID base_weight_fb;
109
RID weight_texture[4];
110
};
111
112
BokehDOF(bool p_prefer_raster_effects);
113
~BokehDOF();
114
115
void bokeh_dof_compute(const BokehBuffers &p_buffers, RID p_camera_attributes, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
116
void bokeh_dof_raster(const BokehBuffers &p_buffers, RID p_camera_attributes, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
117
};
118
119
} // namespace RendererRD
120
121