1 | /**************************************************************************/ |
2 | /* scene_shader_forward_mobile.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 SCENE_SHADER_FORWARD_MOBILE_H |
32 | #define SCENE_SHADER_FORWARD_MOBILE_H |
33 | |
34 | #include "servers/rendering/renderer_rd/renderer_scene_render_rd.h" |
35 | #include "servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl.gen.h" |
36 | |
37 | namespace RendererSceneRenderImplementation { |
38 | |
39 | class SceneShaderForwardMobile { |
40 | private: |
41 | static SceneShaderForwardMobile *singleton; |
42 | |
43 | public: |
44 | enum ShaderVersion { |
45 | SHADER_VERSION_COLOR_PASS, |
46 | SHADER_VERSION_LIGHTMAP_COLOR_PASS, |
47 | SHADER_VERSION_SHADOW_PASS, |
48 | SHADER_VERSION_SHADOW_PASS_DP, |
49 | SHADER_VERSION_DEPTH_PASS_WITH_MATERIAL, |
50 | |
51 | SHADER_VERSION_COLOR_PASS_MULTIVIEW, |
52 | SHADER_VERSION_LIGHTMAP_COLOR_PASS_MULTIVIEW, |
53 | SHADER_VERSION_SHADOW_PASS_MULTIVIEW, |
54 | |
55 | SHADER_VERSION_MAX |
56 | }; |
57 | |
58 | struct ShaderData : public RendererRD::MaterialStorage::ShaderData { |
59 | enum BlendMode { //used internally |
60 | BLEND_MODE_MIX, |
61 | BLEND_MODE_ADD, |
62 | BLEND_MODE_SUB, |
63 | BLEND_MODE_MUL, |
64 | BLEND_MODE_ALPHA_TO_COVERAGE |
65 | }; |
66 | |
67 | enum DepthDraw { |
68 | DEPTH_DRAW_DISABLED, |
69 | DEPTH_DRAW_OPAQUE, |
70 | DEPTH_DRAW_ALWAYS |
71 | }; |
72 | |
73 | enum DepthTest { |
74 | DEPTH_TEST_DISABLED, |
75 | DEPTH_TEST_ENABLED |
76 | }; |
77 | |
78 | enum Cull { |
79 | CULL_DISABLED, |
80 | CULL_FRONT, |
81 | CULL_BACK |
82 | }; |
83 | |
84 | enum CullVariant { |
85 | CULL_VARIANT_NORMAL, |
86 | CULL_VARIANT_REVERSED, |
87 | CULL_VARIANT_DOUBLE_SIDED, |
88 | CULL_VARIANT_MAX |
89 | |
90 | }; |
91 | |
92 | enum AlphaAntiAliasing { |
93 | ALPHA_ANTIALIASING_OFF, |
94 | ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE, |
95 | ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE_AND_TO_ONE |
96 | }; |
97 | |
98 | bool valid = false; |
99 | RID version; |
100 | uint32_t vertex_input_mask = 0; |
101 | PipelineCacheRD pipelines[CULL_VARIANT_MAX][RS::PRIMITIVE_MAX][SHADER_VERSION_MAX]; |
102 | |
103 | Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms; |
104 | |
105 | Vector<uint32_t> ubo_offsets; |
106 | uint32_t ubo_size = 0; |
107 | |
108 | String code; |
109 | |
110 | DepthDraw depth_draw; |
111 | DepthTest depth_test; |
112 | |
113 | bool uses_point_size = false; |
114 | bool uses_alpha = false; |
115 | bool uses_blend_alpha = false; |
116 | bool uses_alpha_clip = false; |
117 | bool uses_alpha_antialiasing = false; |
118 | bool uses_depth_prepass_alpha = false; |
119 | bool uses_discard = false; |
120 | bool uses_roughness = false; |
121 | bool uses_normal = false; |
122 | bool uses_particle_trails = false; |
123 | |
124 | bool unshaded = false; |
125 | bool uses_vertex = false; |
126 | bool uses_sss = false; |
127 | bool uses_transmittance = false; |
128 | bool uses_screen_texture = false; |
129 | bool uses_depth_texture = false; |
130 | bool uses_normal_texture = false; |
131 | bool uses_screen_texture_mipmaps = false; |
132 | bool uses_time = false; |
133 | bool uses_vertex_time = false; |
134 | bool uses_fragment_time = false; |
135 | bool writes_modelview_or_projection = false; |
136 | bool uses_world_coordinates = false; |
137 | |
138 | uint64_t last_pass = 0; |
139 | uint32_t index = 0; |
140 | |
141 | virtual void set_code(const String &p_Code); |
142 | virtual bool is_animated() const; |
143 | virtual bool casts_shadows() const; |
144 | virtual RS::ShaderNativeSourceCode get_native_source_code() const; |
145 | |
146 | SelfList<ShaderData> shader_list_element; |
147 | |
148 | ShaderData(); |
149 | virtual ~ShaderData(); |
150 | }; |
151 | |
152 | RendererRD::MaterialStorage::ShaderData *_create_shader_func(); |
153 | static RendererRD::MaterialStorage::ShaderData *_create_shader_funcs() { |
154 | return static_cast<SceneShaderForwardMobile *>(singleton)->_create_shader_func(); |
155 | } |
156 | |
157 | struct MaterialData : public RendererRD::MaterialStorage::MaterialData { |
158 | ShaderData *shader_data = nullptr; |
159 | RID uniform_set; |
160 | uint64_t last_pass = 0; |
161 | uint32_t index = 0; |
162 | RID next_pass; |
163 | uint8_t priority; |
164 | virtual void set_render_priority(int p_priority); |
165 | virtual void set_next_pass(RID p_pass); |
166 | virtual bool update_parameters(const HashMap<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); |
167 | virtual ~MaterialData(); |
168 | }; |
169 | |
170 | SelfList<ShaderData>::List shader_list; |
171 | |
172 | RendererRD::MaterialStorage::MaterialData *_create_material_func(ShaderData *p_shader); |
173 | static RendererRD::MaterialStorage::MaterialData *_create_material_funcs(RendererRD::MaterialStorage::ShaderData *p_shader) { |
174 | return static_cast<SceneShaderForwardMobile *>(singleton)->_create_material_func(static_cast<ShaderData *>(p_shader)); |
175 | } |
176 | |
177 | SceneForwardMobileShaderRD shader; |
178 | ShaderCompiler compiler; |
179 | |
180 | RID default_shader; |
181 | RID default_material; |
182 | RID overdraw_material_shader; |
183 | RID overdraw_material; |
184 | RID debug_shadow_splits_material_shader; |
185 | RID debug_shadow_splits_material; |
186 | RID default_shader_rd; |
187 | |
188 | RID default_vec4_xform_buffer; |
189 | RID default_vec4_xform_uniform_set; |
190 | |
191 | RID shadow_sampler; |
192 | |
193 | RID default_material_uniform_set; |
194 | ShaderData *default_material_shader_ptr = nullptr; |
195 | |
196 | RID overdraw_material_uniform_set; |
197 | ShaderData *overdraw_material_shader_ptr = nullptr; |
198 | |
199 | RID debug_shadow_splits_material_uniform_set; |
200 | ShaderData *debug_shadow_splits_material_shader_ptr = nullptr; |
201 | |
202 | SceneShaderForwardMobile(); |
203 | ~SceneShaderForwardMobile(); |
204 | |
205 | Vector<RD::PipelineSpecializationConstant> default_specialization_constants; |
206 | |
207 | void init(const String p_defines); |
208 | void set_default_specialization_constants(const Vector<RD::PipelineSpecializationConstant> &p_constants); |
209 | }; |
210 | |
211 | } // namespace RendererSceneRenderImplementation |
212 | |
213 | #endif // SCENE_SHADER_FORWARD_MOBILE_H |
214 | |