1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef API_3D_RENDER_RENDER_DATA_DEFINES_H
17 #define API_3D_RENDER_RENDER_DATA_DEFINES_H
18
19 #include <cfloat>
20 #include <cstdint>
21
22 #include <3d/ecs/components/mesh_component.h>
23 #include <3d/render/default_material_constants.h>
24 #include <base/containers/fixed_string.h>
25 #include <base/containers/string.h>
26 #include <base/math/matrix.h>
27 #include <base/math/quaternion.h>
28 #include <base/math/vector.h>
29 #include <core/namespace.h>
30 #include <render/render_data_structures.h>
31
CORE3D_BEGIN_NAMESPACE()32 CORE3D_BEGIN_NAMESPACE()
33 /** \addtogroup group_render_renderdatadefines
34 * @{
35 */
36 /** Render data constants */
37 namespace RenderSceneDataConstants {
38 /** Max morph target count */
39 static constexpr uint32_t MAX_MORPH_TARGET_COUNT { 64u };
40
41 /** Mesh indices in index */
42 static constexpr uint32_t MESH_INDEX_INDEX { 5u };
43 /** Mesh weights in index */
44 static constexpr uint32_t MESH_WEIGHT_INDEX { 6u };
45
46 /** Max vec3 count for 3 bands */
47 static constexpr uint32_t MAX_SH_VEC3_COUNT { 9u };
48
49 /** Max camera target buffer count */
50 static constexpr uint32_t MAX_CAMERA_COLOR_TARGET_COUNT { 8u };
51
52 /** Max custom push constant data size */
53 static constexpr uint32_t MAX_CUSTOM_PUSH_CONSTANT_DATA_SIZE {
54 RENDER_NS::PipelineLayoutConstants::MAX_PUSH_CONSTANT_BYTE_SIZE
55 };
56
57 /** Max default material env custom resources */
58 static constexpr uint32_t MAX_ENV_CUSTOM_RESOURCE_COUNT { 4u };
59
60 /** Additional custom data size which is bind with render mesh structure to shader
61 * Should match api/shaders/common/3d_dm_structures_common.h DefaultMaterialSingleMeshStruct userData
62 */
63 static constexpr uint32_t MESH_CUSTOM_DATA_VEC4_COUNT { 2u };
64
65 /** Max multi-view layer camera count. Max layers is 8 -> additional cameras 7 */
66 static constexpr uint32_t MAX_MULTI_VIEW_LAYER_CAMERA_COUNT { 7u };
67
68 /** Invalid index with default material indices */
69 static constexpr uint32_t INVALID_INDEX { ~0u };
70
71 /** Invalid 64 bit id */
72 static constexpr uint64_t INVALID_ID { 0xFFFFFFFFffffffff };
73
74 /** Default render sort layer id */
75 static constexpr uint8_t DEFAULT_RENDER_SORT_LAYER_ID { 32u };
76
77 /** Default layer mask */
78 static constexpr uint64_t DEFAULT_LAYER_MASK { 0x1 };
79 } // namespace RenderSceneDataConstants
80
81 /** Render draw command */
82 struct RenderDrawCommand {
83 /** Vertex count */
84 uint32_t vertexCount { 0U };
85 /** Index count */
86 uint32_t indexCount { 0U };
87 /** Instance count */
88 uint32_t instanceCount { 1U };
89 /** Indirect draw count */
90 uint32_t drawCountIndirect { 0U };
91 /** Indirect draw stride */
92 uint32_t strideIndirect { 0U };
93 /** First index in draw */
94 uint32_t firstIndex { 0U };
95 /** First vertex offset in draw */
96 uint32_t vertexOffset { 0U };
97 /** First instance in draw */
98 uint32_t firstInstance { 0U };
99 };
100
101 /** Render vertex buffer */
102 struct RenderVertexBuffer {
103 /** Buffer handle */
104 RENDER_NS::RenderHandleReference bufferHandle {};
105 /** Buffer offset */
106 uint32_t bufferOffset { 0 };
107 /** Byte size */
108 uint32_t byteSize { RENDER_NS::PipelineStateConstants::GPU_BUFFER_WHOLE_SIZE };
109 };
110
111 /** Render index buffer */
112 struct RenderIndexBuffer {
113 /** Buffer handle */
114 RENDER_NS::RenderHandleReference bufferHandle {};
115 /** Buffer offset */
116 uint32_t bufferOffset { 0 };
117 /** Byte size */
118 uint32_t byteSize { 0 };
119 /** Index type */
120 RENDER_NS::IndexType indexType { RENDER_NS::IndexType::CORE_INDEX_TYPE_UINT32 };
121 };
122
123 /** Convert RenderVertexBuffer to Renderer VertexBuffer */
ConvertVertexBuffer(const RenderVertexBuffer & rvb)124 inline RENDER_NS::VertexBuffer ConvertVertexBuffer(const RenderVertexBuffer& rvb)
125 {
126 return RENDER_NS::VertexBuffer { rvb.bufferHandle.GetHandle(), rvb.bufferOffset, rvb.byteSize };
127 }
128
129 /** Convert RenderIndexBuffer to Renderer IndexBuffer */
ConvertIndexBuffer(const RenderIndexBuffer & rib)130 inline RENDER_NS::IndexBuffer ConvertIndexBuffer(const RenderIndexBuffer& rib)
131 {
132 return RENDER_NS::IndexBuffer { rib.bufferHandle.GetHandle(), rib.bufferOffset, rib.byteSize, rib.indexType };
133 }
134
135 /** Render mesh data
136 * In default material pipeline created by:
137 * RenderMeshComponent creates RenderMeshData for every mesh.
138 */
139 struct RenderMeshData {
140 /** Regular world matrix. */
141 BASE_NS::Math::Mat4X4 world;
142 /** Normal world matrix. */
143 BASE_NS::Math::Mat4X4 normalWorld;
144 /** Regular previous frame world matrix. */
145 BASE_NS::Math::Mat4X4 prevWorld;
146
147 /** 64 bit id for render instance. Can be used for rendering time identification. RenderMeshComponent entity. */
148 uint64_t id { RenderSceneDataConstants::INVALID_ID };
149 /** 64 bit id for mesh instance. MeshComponent entity. */
150 uint64_t meshId { RenderSceneDataConstants::INVALID_ID };
151
152 /** layer mask. */
153 uint64_t layerMask { RenderSceneDataConstants::DEFAULT_LAYER_MASK };
154 /** scene ID */
155 uint64_t sceneId { 0U };
156
157 /** Custom data. */
158 BASE_NS::Math::UVec4 customData[RenderSceneDataConstants::MESH_CUSTOM_DATA_VEC4_COUNT] {};
159 };
160
161 /** Render min and max AABB
162 */
163 struct RenderMinAndMax {
164 BASE_NS::Math::Vec3 minAabb { FLT_MAX, FLT_MAX, FLT_MAX };
165 BASE_NS::Math::Vec3 maxAabb { -FLT_MAX, -FLT_MAX, -FLT_MAX };
166 #undef CORE_FMAX
167 };
168
169 /** Render frame material indices
170 */
171 struct RenderFrameMaterialIndices {
172 /** Index to material data
173 * This data is unique and has the material handles and uniform data.
174 */
175 uint32_t index { RenderSceneDataConstants::INVALID_INDEX };
176 /** Offset to frame material data processing
177 * There might be duplicates of material uniform data for e.g. GPU instancing
178 * With this one can get the correct offset to rendering time material uniform data processing
179 */
180 uint32_t frameOffset { RenderSceneDataConstants::INVALID_INDEX };
181 };
182
183 /** The rendering material specialization flag bits
184 */
185 enum RenderMaterialFlagBits : uint32_t {
186 /** Defines whether this material receives shadow */
187 RENDER_MATERIAL_SHADOW_RECEIVER_BIT = (1 << 0),
188 /** Defines whether this material is a shadow caster */
189 RENDER_MATERIAL_SHADOW_CASTER_BIT = (1 << 1),
190 /** Defines whether this material has a normal map enabled */
191 RENDER_MATERIAL_NORMAL_MAP_BIT = (1 << 2),
192 /** Defines whether this material as one or many texture transforms */
193 RENDER_MATERIAL_TEXTURE_TRANSFORM_BIT = (1 << 3),
194 /** Defines whether to use clear-coat parameters to simulate multi-layer material */
195 RENDER_MATERIAL_CLEAR_COAT_BIT = (1 << 4),
196 /** Defines whether to use transmission parameters to simulate optically transparent materials. */
197 RENDER_MATERIAL_TRANSMISSION_BIT = (1 << 5),
198 /** Defines whether to use sheen parameters to simulate e.g. cloth and fabric materials. */
199 RENDER_MATERIAL_SHEEN_BIT = (1 << 6),
200 /** Defines and additional shader discard bit. e.g. alpha mask discard */
201 RENDER_MATERIAL_SHADER_DISCARD_BIT = (1 << 7),
202 /** Defines if object is opaque and alpha is ignored */
203 RENDER_MATERIAL_OPAQUE_BIT = (1 << 8),
204 /** Defines whether to use specular color and strength parameters. */
205 RENDER_MATERIAL_SPECULAR_BIT = (1 << 9),
206 /** Defines whether this material will receive light from punctual lights (points, spots, directional) */
207 RENDER_MATERIAL_PUNCTUAL_LIGHT_RECEIVER_BIT = (1 << 10),
208 /** Defines whether this material will receive indirect light from SH and cubemaps */
209 RENDER_MATERIAL_INDIRECT_LIGHT_RECEIVER_BIT = (1 << 11),
210 /** Defines if this material is "basic" in default material pipeline
211 * NOTE: used in render node graph to discard materials
212 */
213 RENDER_MATERIAL_BASIC_BIT = (1 << 12),
214 /** Defines if this material is "complex" in default material pipeline
215 * NOTE: used in render node graph to discard materials
216 */
217 RENDER_MATERIAL_COMPLEX_BIT = (1 << 13),
218 /** Defines whether this material uses GPU instancing and needs dynamic UBO indices.
219 * Spesializes the shader, and therefore needs to be setup
220 */
221 RENDER_MATERIAL_GPU_INSTANCING_BIT = (1 << 14),
222 /** Defines whether this material uses GPU instancing for material fetches.
223 * Many of the instanced materials share the material UBO data, so this would not be needed.
224 * Spesializes the shader, and therefore needs to be setup
225 */
226 RENDER_MATERIAL_GPU_INSTANCING_MATERIAL_BIT = (1 << 15),
227 };
228 /** Container for material flag bits */
229 using RenderMaterialFlags = uint32_t;
230
231 /** Render material type enumeration */
232 enum class RenderMaterialType : uint8_t {
233 /** Enumeration for Metallic roughness workflow */
234 METALLIC_ROUGHNESS = 0,
235 /** Enumumeration for Specular glossiness workflow */
236 SPECULAR_GLOSSINESS = 1,
237 /** Enumumeration for KHR materials unlit workflow */
238 UNLIT = 2,
239 /** Enumumeration for special unlit shadow receiver */
240 UNLIT_SHADOW_ALPHA = 3,
241 /** Custom material. Could be used with custom material model e.g. with shader graph.
242 * Disables automatic factor based modifications for flags.
243 * Note: that base color is always automatically pre-multiplied in all cases
244 */
245 CUSTOM = 4,
246 /** Custom complex material. Could be used with custom material model e.g. with shader graph.
247 * Disables automatic factor based modifications for flags.
248 * Does not use deferred rendering path in any case due to complex material model.
249 * Note: that base color is always automatically pre-multiplied in all cases
250 */
251 CUSTOM_COMPLEX = 5,
252 };
253
254 /** The rendering submesh specialization flag bits
255 */
256 enum RenderSubmeshFlagBits : uint32_t {
257 /** Defines whether to use tangents with this submesh. */
258 RENDER_SUBMESH_TANGENTS_BIT = (1 << 0),
259 /** Defines whether to use vertex colors with this submesh. */
260 RENDER_SUBMESH_VERTEX_COLORS_BIT = (1 << 1),
261 /** Defines whether to use skinning with this submesh. */
262 RENDER_SUBMESH_SKIN_BIT = (1 << 2),
263 /** Defines whether the submesh has second texcoord set available. */
264 RENDER_SUBMESH_SECOND_TEXCOORD_BIT = (1 << 3),
265 /** Defines whether to use inverse winding with this submesh. */
266 RENDER_SUBMESH_INVERSE_WINDING_BIT = (1 << 4),
267 /** Defines whether to calculate correct velocity in shader. */
268 RENDER_SUBMESH_VELOCITY_BIT = (1 << 5),
269 };
270 /** Container for submesh flag bits */
271 using RenderSubmeshFlags = uint32_t;
272
273 /** Rendering flags (specialized rendering flags) */
274 enum RenderExtraRenderingFlagBits : uint32_t {
275 /** Is an additional flag which can be used to discard some materials from rendering from render node graph */
276 RENDER_EXTRA_RENDERING_DISCARD_BIT = (1 << 0),
277 };
278 /** Container for extra material rendering flag bits */
279 using RenderExtraRenderingFlags = uint32_t;
280
281 /** Additional info for processed render mesh data */
282 struct RenderFrameObjectInfo {
283 /** Render material flags from processing */
284 RenderMaterialFlags renderMaterialFlags { 0U };
285 };
286
287 /** Render mesh batch data
288 */
289 struct RenderMeshBatchData {
290 /** AABB */
291 RenderMinAndMax aabb;
292 /** Additional material flags. */
293 RenderMaterialFlags materialFlags { 0U };
294 };
295
296 /** Render mesh AABB data
297 */
298 struct RenderMeshAabbData {
299 /** AABB */
300 RenderMinAndMax aabb;
301 /** Submesh AABBs */
302 BASE_NS::array_view<const RenderMinAndMax> submeshAabb;
303 };
304
305 /** Render mesh skin data
306 */
307 struct RenderMeshSkinData {
308 /** AABB */
309 RenderMinAndMax aabb;
310 /** Skin joint matrices */
311 BASE_NS::array_view<const BASE_NS::Math::Mat4X4> skinJointMatrices;
312 /** Skin joint previous frame matrices */
313 BASE_NS::array_view<const BASE_NS::Math::Mat4X4> prevSkinJointMatrices;
314 };
315
316 struct RenderSubmeshBuffersWithHandleReference {
317 /** Index buffer */
318 RenderIndexBuffer indexBuffer;
319 /** Vertex buffers */
320 RenderVertexBuffer vertexBuffers[RENDER_NS::PipelineStateConstants::MAX_VERTEX_BUFFER_COUNT];
321 /** Vertex buffer count */
322 uint32_t vertexBufferCount { 0 };
323
324 /* Optional indirect args buffer for indirect draw. */
325 RenderVertexBuffer indirectArgsBuffer;
326
327 /* Optional input assembly which overrides the graphics state one. */
328 RENDER_NS::GraphicsState::InputAssembly inputAssembly { false,
329 RENDER_NS::PrimitiveTopology::CORE_PRIMITIVE_TOPOLOGY_MAX_ENUM };
330 };
331
332 struct RenderSubmeshBuffers {
333 /** Index buffer */
334 RENDER_NS::IndexBuffer indexBuffer;
335 /** Vertex buffers */
336 RENDER_NS::VertexBuffer vertexBuffers[RENDER_NS::PipelineStateConstants::MAX_VERTEX_BUFFER_COUNT];
337 /** Vertex buffer count */
338 uint32_t vertexBufferCount { 0 };
339
340 /* Optional indirect args buffer for indirect draw. */
341 RENDER_NS::VertexBuffer indirectArgsBuffer;
342
343 /* Optional input assembly which overrides the graphics state one. */
344 RENDER_NS::GraphicsState::InputAssembly inputAssembly { false,
345 RENDER_NS::PrimitiveTopology::CORE_PRIMITIVE_TOPOLOGY_MAX_ENUM };
346 };
347
348 struct RenderSubmeshIndices {
349 /** 64 bit id for render instance. Can be used for rendering time identification. RenderMeshComponent entity. */
350 uint64_t id { RenderSceneDataConstants::INVALID_ID };
351 /** 64 bit id for mesh instance. MeshComponent entity. */
352 uint64_t meshId { RenderSceneDataConstants::INVALID_ID };
353 /** Submesh index. */
354 uint32_t subMeshIndex { 0 };
355
356 /** A valid index to mesh (matrix). Get from AddMeshData() */
357 uint32_t meshIndex { RenderSceneDataConstants::INVALID_INDEX };
358 /** A valid index to skin joint matrices if has skin. Get from AddSkinJointMatrices() */
359 uint32_t skinJointIndex { RenderSceneDataConstants::INVALID_INDEX };
360
361 /** Material index to data store material data */
362 uint32_t materialIndex { RenderSceneDataConstants::INVALID_INDEX };
363 /** Material frame offset to processed data (i.e. uniform data offset index) */
364 uint32_t materialFrameOffset { RenderSceneDataConstants::INVALID_INDEX };
365 };
366
367 struct RenderSubmeshBounds {
368 /** World center vector */
369 BASE_NS::Math::Vec3 worldCenter { 0.0f, 0.0f, 0.0f };
370 /** World radius */
371 float worldRadius { 0.0f };
372 };
373
374 struct RenderSubmeshLayers {
375 /** Layer mask. */
376 uint64_t layerMask { RenderSceneDataConstants::DEFAULT_LAYER_MASK };
377
378 /** Scene ID. */
379 uint32_t sceneId { 0U };
380
381 /** Mesh render sort layer id. Valid values are 0 - 63 */
382 uint8_t meshRenderSortLayer { RenderSceneDataConstants::DEFAULT_RENDER_SORT_LAYER_ID };
383 /** Mesh render sort layer id. Valid values are 0 - 255 */
384 uint8_t meshRenderSortLayerOrder { 0 };
385
386 /** Material render sort layer id. Valid values are 0 - 63
387 * Typically filled automatically by the data store based on selected material.
388 */
389 uint8_t materialRenderSortLayer { RenderSceneDataConstants::DEFAULT_RENDER_SORT_LAYER_ID };
390 /** Material render sort layer id. Valid values are 0 - 255 */
391 uint8_t materialRenderSortLayerOrder { 0 };
392 };
393
394 /** Render submesh with handle references */
395 struct RenderSubmeshWithHandleReference {
396 /** Submesh flags */
397 RenderSubmeshFlags submeshFlags { 0U };
398
399 /** Additional rendering flags for this submesh material. Typically zero.
400 * Use case could be adding some specific flags for e.g. pso creation / specialization.
401 */
402 RenderMaterialFlags renderSubmeshMaterialFlags { 0U };
403
404 /** Indices */
405 RenderSubmeshIndices indices;
406
407 /** Sorting */
408 RenderSubmeshLayers layers;
409
410 /** Bounds */
411 RenderSubmeshBounds bounds;
412
413 /** Draw command */
414 RenderDrawCommand drawCommand;
415
416 /** buffers for rendering with handle references */
417 RenderSubmeshBuffersWithHandleReference buffers;
418 };
419
420 /** Render submesh */
421 struct RenderSubmesh {
422 /** Submesh flags */
423 RenderSubmeshFlags submeshFlags { 0 };
424 /** Additional rendering flags for this submesh material. Typically zero.
425 * Use case could be adding some specific flags for e.g. pso creation / specialization.
426 */
427 RenderMaterialFlags renderSubmeshMaterialFlags { 0U };
428
429 /** Indices */
430 RenderSubmeshIndices indices;
431
432 /** Sorting */
433 RenderSubmeshLayers layers;
434
435 /** Bounds */
436 RenderSubmeshBounds bounds;
437
438 /** Draw command */
439 RenderDrawCommand drawCommand;
440
441 /** buffers for rendering */
442 RenderSubmeshBuffers buffers;
443 };
444
445 /** Render submesh with handle references */
446 struct RenderSubmeshDataWithHandleReference {
447 /** Submesh flags */
448 RenderSubmeshFlags submeshFlags { 0U };
449
450 /** Mesh render sort layer id. Valid values are 0 - 63 */
451 uint8_t meshRenderSortLayer { RenderSceneDataConstants::DEFAULT_RENDER_SORT_LAYER_ID };
452 /** Mesh render sort layer id. Valid values are 0 - 255 */
453 uint8_t meshRenderSortLayerOrder { 0 };
454
455 /** AABB min */
456 BASE_NS::Math::Vec3 aabbMin { 0.0f, 0.0f, 0.0f };
457 /** AABB max */
458 BASE_NS::Math::Vec3 aabbMax { 0.0f, 0.0f, 0.0f };
459
460 /** Draw command */
461 RenderDrawCommand drawCommand;
462
463 /** buffers for rendering with handle references */
464 RenderSubmeshBuffersWithHandleReference buffers;
465
466 /** basic material id -> invalid uses the default material */
467 uint64_t materialId { RenderSceneDataConstants::INVALID_ID };
468
469 /** additional materials for multi-pass */
470 BASE_NS::array_view<const uint64_t> additionalMaterials;
471 };
472
473 /** Render mesh data
474 * In default material pipeline created by:
475 * RenderMeshComponent creates RenderMeshData for every mesh.
476 */
477 struct MeshDataWithHandleReference {
478 /** 64 bit id for mesh instance. MeshComponent entity. */
479 uint64_t meshId { RenderSceneDataConstants::INVALID_ID };
480
481 /** AABB min (local) */
482 BASE_NS::Math::Vec3 aabbMin { 0.0f, 0.0f, 0.0f };
483 /** AABB max (local) */
484 BASE_NS::Math::Vec3 aabbMax { 0.0f, 0.0f, 0.0f };
485
486 /** Submeshes */
487 BASE_NS::vector<RenderSubmeshDataWithHandleReference> submeshes;
488 };
489
490 /** Render light */
491 struct RenderLight {
492 /** Light usage flag bits */
493 enum LightUsageFlagBits {
494 /** Directional light bit */
495 LIGHT_USAGE_DIRECTIONAL_LIGHT_BIT = (1 << 0),
496 /** Point light bit */
497 LIGHT_USAGE_POINT_LIGHT_BIT = (1 << 1),
498 /** Spot light bit */
499 LIGHT_USAGE_SPOT_LIGHT_BIT = (1 << 2),
500 /** Shadow light bit */
501 LIGHT_USAGE_SHADOW_LIGHT_BIT = (1 << 3),
502 };
503 /** Light usage flags */
504 using LightUsageFlags = uint32_t;
505
506 /** Unique id. */
507 uint64_t id { RenderSceneDataConstants::INVALID_ID };
508
509 /** Layer mask (light affect mask). All enabled by default */
510 uint64_t layerMask { RenderSceneDataConstants::INVALID_ID };
511
512 /** Position */
513 BASE_NS::Math::Vec4 pos { 0.0f, 0.0f, 0.0f, 0.0f };
514 /** Direction */
515 BASE_NS::Math::Vec4 dir { 0.0f, 0.0f, 0.0f, 0.0f };
516 /** Color, w is intensity */
517 BASE_NS::Math::Vec4 color { 0.0f, 0.0f, 0.0f, 0.0f };
518
519 /* Spot light params. .x = angleScale, .y = angleOffset, .z = innerAngle, .w = outerAngle */
520 BASE_NS::Math::Vec4 spotLightParams { 0.0f, 0.0f, 0.0f, 0.0f };
521 /* Point and spot params. */
522 float range { 0.0f };
523 // .x = shadow factor, .y = depth bias, .z = normal bias, .w = empty (filled later with step size)
524 BASE_NS::Math::Vec4 shadowFactors { 1.0f, 0.005f, 0.02f, 0.0f };
525
526 /** Object ID */
527 uint32_t objectId { ~0u };
528 /** Light usage flags */
529 LightUsageFlags lightUsageFlags { 0u };
530
531 /** Shadow camera index in render lights */
532 uint32_t shadowCameraIndex { ~0u };
533 /** Filled by the data store */
534 uint32_t shadowIndex { ~0u };
535
536 /** Scene ID */
537 uint32_t sceneId { 0U };
538 };
539
540 /** Render camera */
541 struct RenderCamera {
542 enum CameraFlagBits : uint32_t {
543 /** Clear depth. Overrides camera RNG loadOp with clear. */
544 CAMERA_FLAG_CLEAR_DEPTH_BIT = (1 << 0),
545 /** Clear color. Overrides camera RNG loadOp with clear. */
546 CAMERA_FLAG_CLEAR_COLOR_BIT = (1 << 1),
547 /** Shadow camera */
548 CAMERA_FLAG_SHADOW_BIT = (1 << 2),
549 /** MSAA enabled */
550 CAMERA_FLAG_MSAA_BIT = (1 << 3),
551 /** Reflection camera */
552 CAMERA_FLAG_REFLECTION_BIT = (1 << 4),
553 /** Main scene camera. I.e. the final main camera which might try to render to swapchain */
554 CAMERA_FLAG_MAIN_BIT = (1 << 5),
555 /** This is a pre-pass color camera. */
556 CAMERA_FLAG_COLOR_PRE_PASS_BIT = (1 << 6),
557 /** Render only opaque. */
558 CAMERA_FLAG_OPAQUE_BIT = (1 << 7),
559 /** Use and flip history */
560 CAMERA_FLAG_HISTORY_BIT = (1 << 8),
561 /** Jitter camera. */
562 CAMERA_FLAG_JITTER_BIT = (1 << 9),
563 /** Output samplable velocity normal */
564 CAMERA_FLAG_OUTPUT_VELOCITY_NORMAL_BIT = (1 << 10),
565 /** Disable FW velocity */
566 CAMERA_FLAG_INVERSE_WINDING_BIT = (1 << 11),
567 /** Samplable depth target */
568 CAMERA_FLAG_OUTPUT_DEPTH_BIT = (1 << 12),
569 /** Custom targets */
570 CAMERA_FLAG_CUSTOM_TARGETS_BIT = (1 << 13),
571 /** Multi-view camera */
572 CAMERA_FLAG_MULTI_VIEW_ONLY_BIT = (1 << 14),
573 /** Not in use (1 << 15) */
574 /** Allow reflection */
575 CAMERA_FLAG_ALLOW_REFLECTION_BIT = (1 << 16),
576 /** Automatic cubemap target camera */
577 CAMERA_FLAG_CUBEMAP_BIT = (1 << 17),
578 };
579 using Flags = uint32_t;
580
581 enum ShaderFlagBits : uint32_t {
582 /** Fog enabled in the shader. Changed based on render slots and rendering types. */
583 CAMERA_SHADER_FOG_BIT = (1 << 0),
584 };
585 using ShaderFlags = uint32_t;
586
587 enum class RenderPipelineType : uint32_t {
588 /** Forward */
589 LIGHT_FORWARD = 0,
590 /** Forward */
591 FORWARD = 1,
592 /** Deferred */
593 DEFERRED = 2,
594 /** Custom */
595 CUSTOM = 3,
596 };
597
598 enum class CameraCullType : uint8_t {
599 /** None */
600 CAMERA_CULL_NONE = 0,
601 /** Front to back */
602 CAMERA_CULL_VIEW_FRUSTUM = 1,
603 };
604
605 /** Matrices */
606 struct Matrices {
607 /** View matrix */
608 BASE_NS::Math::Mat4X4 view;
609 /** Projection matrix */
610 BASE_NS::Math::Mat4X4 proj;
611
612 /** Previous view matrix */
613 BASE_NS::Math::Mat4X4 viewPrevFrame;
614 /** Previous projection matrix */
615 BASE_NS::Math::Mat4X4 projPrevFrame;
616 };
617
618 /** Environment setup */
619 struct Environment {
620 /** Background type for env node */
621 enum BackgroundType {
622 /** None */
623 BG_TYPE_NONE = 0,
624 /** Image (2d) */
625 BG_TYPE_IMAGE = 1,
626 /** Cubemap */
627 BG_TYPE_CUBEMAP = 2,
628 /** Equirectangular */
629 BG_TYPE_EQUIRECTANGULAR = 3,
630 /** Sky */
631 BG_TYPE_SKY = 4,
632 };
633 /** Environment flags */
634 enum EnvironmentFlagBits : uint32_t {
635 /** Main scene environment. From render configuration component */
636 ENVIRONMENT_FLAG_MAIN_BIT = (1 << 0),
637 /** Camera based weather render node enabled (e.g. clouds) */
638 ENVIRONMENT_FLAG_CAMERA_WEATHER_BIT = (1 << 1),
639 };
640 using EnvironmentFlags = uint32_t;
641
642 /** Unique id. */
643 uint64_t id { RenderSceneDataConstants::INVALID_ID };
644
645 /** Layer mask (camera render mask). All enabled by default */
646 uint64_t layerMask { RenderSceneDataConstants::INVALID_ID };
647
648 /** Unique id. */
649 EnvironmentFlags flags { 0U };
650
651 /** Radiance cubemap resource handle */
652 RENDER_NS::RenderHandleReference radianceCubemap;
653 /** Radiance cubemap mip count. Zero indicates that full mipchain is available */
654 uint32_t radianceCubemapMipCount { 0u };
655
656 /** Environment map resource handle */
657 RENDER_NS::RenderHandleReference envMap;
658 /** Environment map lod level for sampling */
659 float envMapLodLevel { 0.0f };
660
661 /** Spherical harmonic coefficients for indirect diffuse (irradiance)
662 * Prescaled with 1.0 / PI. */
663 BASE_NS::Math::Vec4 shIndirectCoefficients[RenderSceneDataConstants::MAX_SH_VEC3_COUNT];
664
665 /** Indirect diffuse color factor (.rgb = tint, .a = intensity) */
666 BASE_NS::Math::Vec4 indirectDiffuseFactor { 1.0f, 1.0f, 1.0f, 1.0f };
667 /** Indirect specular color factor (.rgb = tint, .a = intensity) */
668 BASE_NS::Math::Vec4 indirectSpecularFactor { 1.0f, 1.0f, 1.0f, 1.0f };
669 /** Env map color factor (.rgb = tint, .a = intensity) */
670 BASE_NS::Math::Vec4 envMapFactor { 1.0f, 1.0f, 1.0f, 1.0f };
671 /** Additional blend factor for multiple cubemaps. .x blends 0-1, .y blends 1-2 ... */
672 BASE_NS::Math::Vec4 blendFactor { 0.0f, 0.0f, 0.0f, 0.0f };
673
674 /** Environment rotation */
675 BASE_NS::Math::Quat rotation { 0.0f, 0.0f, 0.0f, 1.0f };
676
677 /** Background type */
678 BackgroundType backgroundType { BackgroundType::BG_TYPE_NONE };
679
680 /** Custom shader handle */
681 RENDER_NS::RenderHandleReference shader;
682 /** invalid handles if not given */
683 RENDER_NS::RenderHandleReference customResourceHandles[RenderSceneDataConstants::MAX_ENV_CUSTOM_RESOURCE_COUNT];
684
685 /** Blended environment count. */
686 uint32_t multiEnvCount { 0U };
687 /** 64bit environment id of environments. */
688 uint64_t multiEnvIds[DefaultMaterialCameraConstants::MAX_CAMERA_MULTI_ENVIRONMENT_COUNT] {
689 RenderSceneDataConstants::INVALID_ID, RenderSceneDataConstants::INVALID_ID,
690 RenderSceneDataConstants::INVALID_ID, RenderSceneDataConstants::INVALID_ID
691 };
692 };
693
694 /** Fog setup */
695 struct Fog {
696 /** Unique id. */
697 uint64_t id { RenderSceneDataConstants::INVALID_ID };
698
699 /** Layer mask (camera render mask). All enabled by default */
700 uint64_t layerMask { RenderSceneDataConstants::INVALID_ID };
701
702 /** .x = density, .y = heightFalloff, .z = heightFogOffset */
703 BASE_NS::Math::Vec4 firstLayer { 1.0f, 1.0f, 1.0f, 0.0f };
704 /** .x = density, .y = heightFalloff, .z = heightFogOffset */
705 BASE_NS::Math::Vec4 secondLayer { 1.0f, 1.0f, 1.0f, 0.0f };
706
707 /** .x = startDistance, .y = cutoffDistance, .z = maxOpacity */
708 BASE_NS::Math::Vec4 baseFactors { 1.0f, -1.0f, 1.0f, 0.0f };
709
710 /** Primary color for the fog (.rgb = tint, .a = intensity) */
711 BASE_NS::Math::Vec4 inscatteringColor { 1.0f, -1.0f, 1.0f, 0.0f };
712 /** Env map color factor (.rgb = tint, .a = intensity) */
713 BASE_NS::Math::Vec4 envMapFactor { 1.0f, -1.0f, 1.0f, 0.0f };
714
715 /** Additional factor */
716 BASE_NS::Math::Vec4 additionalFactor { 0.0f, 0.0f, 0.0f, 0.0f };
717 };
718
719 /** Unique id. */
720 uint64_t id { RenderSceneDataConstants::INVALID_ID };
721 /** Shadow id. (Can be invalid) */
722 uint64_t shadowId { RenderSceneDataConstants::INVALID_ID };
723
724 /** Layer mask (camera render mask). All enabled by default */
725 uint64_t layerMask { RenderSceneDataConstants::INVALID_ID };
726
727 /** Main camera to this camera id. (e.g. reflection camera has info of the main camera) */
728 uint64_t mainCameraId { RenderSceneDataConstants::INVALID_ID };
729
730 /** Matrices (Contains view, projection, view of previous frame and projection of previous frame) */
731 Matrices matrices;
732
733 /** Viewport (relative to render resolution) */
734 BASE_NS::Math::Vec4 viewport { 0.0f, 0.0f, 1.0f, 1.0f };
735 /** Scissor (relative to render resolution) */
736 BASE_NS::Math::Vec4 scissor { 0.0f, 0.0f, 1.0f, 1.0f };
737 /** Render resolution */
738 BASE_NS::Math::UVec2 renderResolution { 0u, 0u };
739
740 /** Z near value */
741 float zNear { 0.0f };
742 /** Z far value */
743 float zFar { 0.0f };
744
745 /** Custom depth target */
746 RENDER_NS::RenderHandleReference depthTarget {};
747 /** Custom color targets */
748 RENDER_NS::RenderHandleReference colorTargets[RenderSceneDataConstants::MAX_CAMERA_COLOR_TARGET_COUNT];
749
750 /** Custom pre-pass color target. Can be tried to fetch with a name if handle is not given. */
751 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> prePassColorTargetName;
752
753 /** Flags for camera */
754 Flags flags { 0u };
755 /** Shader flags for camera */
756 ShaderFlags shaderFlags { 0u };
757
758 /** Which scene the camera belongs to. */
759 uint32_t sceneId { 0U };
760
761 /** Flags for camera render pipeline */
762 RenderPipelineType renderPipelineType { RenderPipelineType::FORWARD };
763
764 /** Clear depth / stencil values. Clear enabled if flags set. */
765 RENDER_NS::ClearDepthStencilValue clearDepthStencil { 1.0f, 0u };
766 /** Clear color values. Clear enabled if flags set */
767 RENDER_NS::ClearColorValue clearColorValues { 0.0f, 0.0f, 0.0f, 0.0f };
768
769 /** Camera cull type */
770 CameraCullType cullType { CameraCullType::CAMERA_CULL_VIEW_FRUSTUM };
771
772 /** MSAA sample count */
773 RENDER_NS::SampleCountFlags msaaSampleCountFlags { RENDER_NS::SampleCountFlagBits::CORE_SAMPLE_COUNT_4_BIT };
774
775 /** Default environment setup for camera */
776 Environment environment;
777
778 /** Fog setup for camera */
779 Fog fog;
780
781 /** Custom render node graph from camera component (WILL BE DEPRECATED) */
782 RENDER_NS::RenderHandleReference customRenderNodeGraph;
783
784 /** Custom render node graph file from camera component */
785 BASE_NS::string customRenderNodeGraphFile;
786
787 /** Custom render node graph file from post process configuration component */
788 BASE_NS::string customPostProcessRenderNodeGraphFile;
789
790 /** Target customization */
791 struct TargetUsage {
792 /** Target format */
793 BASE_NS::Format format { BASE_NS::Format::BASE_FORMAT_UNDEFINED };
794 /** Usage flags hints for optimizing resource creation */
795 RENDER_NS::ImageUsageFlags usageFlags { 0 };
796 };
797
798 /** Depth target customization */
799 TargetUsage depthTargetCustomization;
800 /** Color target customization */
801 TargetUsage colorTargetCustomization[RenderSceneDataConstants::MAX_CAMERA_COLOR_TARGET_COUNT];
802
803 /** Unique camera name for getting named camera. */
804 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> name;
805
806 /** Camera post process name. Can be empty */
807 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> postProcessName;
808
809 /** Multi-view extra camera count. */
810 uint32_t multiViewCameraCount { 0U };
811 /** 64bit camera id of multi-view layer cameras. */
812 uint64_t multiViewCameraIds[RenderSceneDataConstants::MAX_MULTI_VIEW_LAYER_CAMERA_COUNT] {
813 RenderSceneDataConstants::INVALID_ID,
814 RenderSceneDataConstants::INVALID_ID,
815 RenderSceneDataConstants::INVALID_ID,
816 RenderSceneDataConstants::INVALID_ID,
817 RenderSceneDataConstants::INVALID_ID,
818 };
819 /** Hash of the multi-view camera IDs */
820 uint64_t multiViewCameraHash { 0U };
821 uint64_t multiViewParentCameraId { RenderSceneDataConstants::INVALID_ID };
822 };
823
824 /** Render scene */
825 struct RenderScene {
826 /** Unique id. */
827 uint64_t id { RenderSceneDataConstants::INVALID_ID };
828 /** Unique scene name (If name is empty a default id/name is created with index) */
829 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> name;
830
831 /** Scene render data store name needs to be known */
832
833 /** Camera render data store name */
834 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> dataStoreNameCamera;
835 /** Light render data store name */
836 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> dataStoreNameLight;
837 /** Material data store name */
838 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> dataStoreNameMaterial;
839 /** Morphing data store name */
840 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> dataStoreNameMorph;
841 /** Data store name prefix */
842 BASE_NS::fixed_string<RENDER_NS::RenderDataConstants::MAX_DEFAULT_NAME_LENGTH> dataStoreNamePrefix;
843
844 /** World scene center */
845 BASE_NS::Math::Vec3 worldSceneCenter { 0.0f, 0.0f, 0.0f };
846 /** World scene bounding sphere radius */
847 float worldSceneBoundingSphereRadius { 0.0f };
848
849 /** Index of scene camera in rendering cameras */
850 uint32_t cameraIndex { RenderSceneDataConstants::INVALID_INDEX };
851
852 /** Scene delta time in milliseconds */
853 float sceneDeltaTime { 0 };
854 /** Real total tick time in seconds */
855 float totalTime { 0u };
856 /** Real delta tick time in milliseconds */
857 float deltaTime { 0u };
858 /** Render scene frame index */
859 uint32_t frameIndex { 0u };
860
861 /** Custom render node graph file from scene component */
862 BASE_NS::string customRenderNodeGraphFile;
863 /** Custom post scene render node graph file from scene component */
864 BASE_NS::string customPostSceneRenderNodeGraphFile;
865 };
866
867 struct SlotSubmeshIndex {
868 uint32_t submeshIndex { 0 };
869
870 uint32_t sortLayerKey { 0 };
871 uint64_t sortKey { 0 };
872 uint32_t renderMaterialSortHash { 0 };
873 RENDER_NS::RenderHandle shaderHandle;
874 RENDER_NS::RenderHandle gfxStateHandle;
875 };
876
877 enum RenderSceneFlagBits : uint32_t {
878 RENDER_SCENE_DIRECT_POST_PROCESS_BIT = (1 << 0),
879 RENDER_SCENE_FLIP_WINDING_BIT = (1 << 1),
880 RENDER_SCENE_DISCARD_MATERIAL_BIT = (1 << 2),
881 RENDER_SCENE_ENABLE_FOG_BIT = (1 << 3),
882 RENDER_SCENE_DISABLE_FOG_BIT = (1 << 4),
883 };
884 using RenderSceneFlags = uint32_t;
885 /** @} */
886 CORE3D_END_NAMESPACE()
887
888 #endif // API_3D_RENDER_RENDER_DATA_DEFINES_H
889