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