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