1/**************************************************************************/
2/* camera_attributes.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 CAMERA_ATTRIBUTES_H
32#define CAMERA_ATTRIBUTES_H
33
34#include "core/io/resource.h"
35#include "core/templates/rid.h"
36
37class CameraAttributes : public Resource {
38 GDCLASS(CameraAttributes, Resource);
39
40private:
41 RID camera_attributes;
42
43protected:
44 static void _bind_methods();
45 void _validate_property(PropertyInfo &p_property) const;
46
47 float exposure_multiplier = 1.0;
48 float exposure_sensitivity = 100.0; // In ISO.
49 void _update_exposure();
50
51 bool auto_exposure_enabled = false;
52 float auto_exposure_min = 0.01;
53 float auto_exposure_max = 64.0;
54 float auto_exposure_speed = 0.5;
55 float auto_exposure_scale = 0.4;
56 virtual void _update_auto_exposure(){};
57
58public:
59 virtual RID get_rid() const override;
60 virtual float calculate_exposure_normalization() const { return 1.0; }
61
62 void set_exposure_multiplier(float p_multiplier);
63 float get_exposure_multiplier() const;
64 void set_exposure_sensitivity(float p_sensitivity);
65 float get_exposure_sensitivity() const;
66
67 void set_auto_exposure_enabled(bool p_enabled);
68 bool is_auto_exposure_enabled() const;
69 void set_auto_exposure_speed(float p_auto_exposure_speed);
70 float get_auto_exposure_speed() const;
71 void set_auto_exposure_scale(float p_auto_exposure_scale);
72 float get_auto_exposure_scale() const;
73
74 CameraAttributes();
75 ~CameraAttributes();
76};
77
78class CameraAttributesPractical : public CameraAttributes {
79 GDCLASS(CameraAttributesPractical, CameraAttributes);
80
81private:
82 // DOF blur
83 bool dof_blur_far_enabled = false;
84 float dof_blur_far_distance = 10.0;
85 float dof_blur_far_transition = 5.0;
86
87 bool dof_blur_near_enabled = false;
88 float dof_blur_near_distance = 2.0;
89 float dof_blur_near_transition = 1.0;
90
91 float dof_blur_amount = 0.1;
92 void _update_dof_blur();
93
94 virtual void _update_auto_exposure() override;
95
96protected:
97 static void _bind_methods();
98 void _validate_property(PropertyInfo &p_property) const;
99
100public:
101 // DOF blur
102 void set_dof_blur_far_enabled(bool p_enabled);
103 bool is_dof_blur_far_enabled() const;
104 void set_dof_blur_far_distance(float p_distance);
105 float get_dof_blur_far_distance() const;
106 void set_dof_blur_far_transition(float p_distance);
107 float get_dof_blur_far_transition() const;
108
109 void set_dof_blur_near_enabled(bool p_enabled);
110 bool is_dof_blur_near_enabled() const;
111 void set_dof_blur_near_distance(float p_distance);
112 float get_dof_blur_near_distance() const;
113 void set_dof_blur_near_transition(float p_distance);
114 float get_dof_blur_near_transition() const;
115 void set_dof_blur_amount(float p_amount);
116 float get_dof_blur_amount() const;
117
118 void set_auto_exposure_min_sensitivity(float p_min);
119 float get_auto_exposure_min_sensitivity() const;
120 void set_auto_exposure_max_sensitivity(float p_max);
121 float get_auto_exposure_max_sensitivity() const;
122
123 virtual float calculate_exposure_normalization() const override;
124
125 CameraAttributesPractical();
126 ~CameraAttributesPractical();
127};
128
129class CameraAttributesPhysical : public CameraAttributes {
130 GDCLASS(CameraAttributesPhysical, CameraAttributes);
131
132private:
133 // Exposure
134 float exposure_aperture = 16.0; // In f-stops;
135 float exposure_shutter_speed = 100.0; // In 1 / seconds;
136
137 // Camera properties.
138 float frustum_focal_length = 35.0; // In millimeters.
139 float frustum_focus_distance = 10.0; // In Meters.
140 real_t frustum_near = 0.05;
141 real_t frustum_far = 4000.0;
142 real_t frustum_fov = 75.0;
143 void _update_frustum();
144
145 virtual void _update_auto_exposure() override;
146
147protected:
148 static void _bind_methods();
149 void _validate_property(PropertyInfo &property) const;
150
151public:
152 void set_aperture(float p_aperture);
153 float get_aperture() const;
154
155 void set_shutter_speed(float p_shutter_speed);
156 float get_shutter_speed() const;
157
158 void set_focal_length(float p_focal_length);
159 float get_focal_length() const;
160
161 void set_focus_distance(float p_focus_distance);
162 float get_focus_distance() const;
163
164 void set_near(real_t p_near);
165 real_t get_near() const;
166
167 void set_far(real_t p_far);
168 real_t get_far() const;
169
170 real_t get_fov() const;
171
172 void set_auto_exposure_min_exposure_value(float p_min);
173 float get_auto_exposure_min_exposure_value() const;
174 void set_auto_exposure_max_exposure_value(float p_max);
175 float get_auto_exposure_max_exposure_value() const;
176
177 virtual float calculate_exposure_normalization() const override;
178
179 CameraAttributesPhysical();
180 ~CameraAttributesPhysical();
181};
182
183#endif // CAMERA_ATTRIBUTES_H
184