Nebula
Loading...
Searching...
No Matches
material.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
11//------------------------------------------------------------------------------
12#include "ids/id.h"
13#include "ids/idallocator.h"
16#include "coregraphics/buffer.h"
17#include "materialvariant.h"
18
19
21{
22struct Entry;
23enum class BatchGroup;
24};
25
26namespace Materials
27{
28
29struct ShaderConfigBatchTexture;
31ID_32_24_8_NAMED_TYPE(MaterialInstanceId, instance, materialId, materialGeneration, material); // 32 bits instance, 24 bits material, 8 bits type
32
34
35
39void DestroyMaterial(const MaterialId id);
40
42void MaterialSetTexture(const MaterialId mat, const ShaderConfigBatchTexture* bind, const Resources::ResourceId tex);
44void MaterialSetTexture(const MaterialId mat, uint name, const Resources::ResourceId tex);
46void MaterialSetTextureBindless(const MaterialId mat, uint name, const uint handle, const uint offset, const Resources::ResourceId tex);
48void MaterialSetConstants(const MaterialId mat, const void* data, const uint size);
50void MaterialSetConstant(const MaterialId mat, const void* data, const uint size, const uint offset);
51
53void MaterialSetBufferBinding(const MaterialId id, IndexT index);
56
58void MaterialAddLODTexture(const MaterialId mat, const Resources::ResourceId tex);
60void MaterialSetLowestLod(const MaterialId mat, float lod);
61
63void MaterialApply(const MaterialId id, const CoreGraphics::CmdBufferId buf, IndexT index);
64
68const Materials::BatchIndex MaterialGetBatchIndex(const MaterialId mat, const MaterialTemplates::BatchGroup batch);
70uint64_t MaterialGetSortCode(const MaterialId mat);
71
72#ifdef WITH_NEBULA_EDITOR
74ubyte* MaterialGetConstants(const MaterialId mat);
76const Resources::ResourceId MaterialGetTexture(const MaterialId mat, const IndexT i);
78void MaterialInvalidate(const MaterialId mat);
79#endif
80
94
100
101enum
102{
113#ifdef WITH_NEBULA_EDITOR
114 , Material_TextureValues
115#endif
117
118
119typedef Ids::IdAllocator<
120 float,
122 Util::FixedArray<CoreGraphics::ResourceTableId>, // surface level resource table, mapped batch -> table
123 CoreGraphics::BufferId, // Material buffer
124 Util::FixedArray<Util::FixedArray<CoreGraphics::ResourceTableId>>, // instance level resource table, mapped batch -> table
125 Util::FixedArray<Util::Tuple<IndexT, SizeT>>, // instance level instance buffer, mapped batch -> memory + size
128 IndexT, // global material buffer binding (based on ShaderConfig::PrototypeHash)
129 const MaterialTemplates::Entry* // template
130#ifdef WITH_NEBULA_EDITOR
132#endif
135
139void DestroyMaterialInstance(const MaterialInstanceId materialInstance);
140
144void MaterialInstanceApply(const MaterialInstanceId id, const CoreGraphics::CmdBufferId buf, IndexT index, IndexT bufferIndex);
145
146
149
154typedef Ids::IdAllocator<
155 uint
158
159} // namespace Materials
An ID allocator associates an id with a slice in an N number of arrays.
Definition idallocator.h:39
Nebula's dynamic array class.
Definition array.h:60
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
#define ID_32_24_8_NAMED_TYPE(x, id32_name, id24_name, id8_name, combined_name)
Definition id.h:46
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
uint ConstantBufferOffset
Definition config.h:21
Materials represent a set of settings and a correlated shader configuration, which tells the engine w...
Definition material.h:21
Material special version of variant.
Definition material.cc:11
void DestroyMaterial(const MaterialId id)
Destroy material.
Definition material.cc:159
void DestroyMaterialInstance(const MaterialInstanceId materialInstance)
Destroy material instance.
Definition material.cc:385
void MaterialApply(const MaterialId id, const CoreGraphics::CmdBufferId buf, IndexT index)
Apply material.
Definition material.cc:361
MaterialId CreateMaterial(const MaterialTemplates::Entry *entry)
Create material.
Definition material.cc:21
const Materials::BatchIndex MaterialGetBatchIndex(const MaterialId mat, const MaterialTemplates::BatchGroup batch)
Get batch index from code.
Definition material.cc:313
void MaterialSetConstant(const MaterialId mat, const void *data, const uint size, const uint offset)
Set a material constant.
Definition material.cc:243
void MaterialInstanceApply(const MaterialInstanceId id, const CoreGraphics::CmdBufferId buf, IndexT index, IndexT bufferIndex)
Apply material instance.
Definition material.cc:408
Ids::IdAllocator< uint > MaterialInstanceAllocator
Definition material.h:156
MaterialInstanceMembers
Definition material.h:151
@ MaterialInstance_Offsets
Definition material.h:152
IndexT MaterialGetBufferBinding(const MaterialId id)
Get material GPU buffer binding.
Definition material.cc:263
uint64_t MaterialGetSortCode(const MaterialId mat)
Get sort code.
Definition material.cc:322
void MaterialSetTextureBindless(const MaterialId mat, uint name, const uint handle, const uint offset, const Resources::ResourceId tex)
Set bindless texture.
Definition material.cc:214
const MaterialTemplates::Entry * MaterialGetTemplate(const MaterialId mat)
Get material shader config.
Definition material.cc:304
void MaterialAddLODTexture(const MaterialId mat, const Resources::ResourceId tex)
Add texture to LOD update.
Definition material.cc:272
SizeT MaterialInstanceBufferSize(const MaterialInstanceId mat, const BatchIndex batch)
Get material instance buffer size for batch.
Definition material.cc:426
MaterialAllocator materialAllocator
Definition material.cc:13
void MaterialSetBufferBinding(const MaterialId id, IndexT index)
Set material GPU buffer binding.
Definition material.cc:254
MaterialInstanceAllocator materialInstanceAllocator
Definition material.cc:14
void MaterialSetLowestLod(const MaterialId mat, float lod)
Update LOD for material.
Definition material.cc:285
@ Material_InstanceTables
Definition material.h:107
@ Material_Textures
Definition material.h:109
@ Material_MinLOD
Definition material.h:103
@ Material_Buffer
Definition material.h:106
@ Material_BufferOffset
Definition material.h:111
@ Material_Constants
Definition material.h:110
@ Material_LODTextures
Definition material.h:104
@ Material_Template
Definition material.h:112
@ Material_Table
Definition material.h:105
@ Material_InstanceBuffers
Definition material.h:108
IndexT BatchIndex
Definition material.h:33
CoreGraphics::ConstantBufferOffset MaterialInstanceAllocate(const MaterialInstanceId mat, const BatchIndex batch)
Allocate instance constants, call per frame when instance constants are needed.
Definition material.cc:394
Ids::IdAllocator< float, Util::Array< Resources::ResourceId >, Util::FixedArray< CoreGraphics::ResourceTableId >, CoreGraphics::BufferId, Util::FixedArray< Util::FixedArray< CoreGraphics::ResourceTableId > >, Util::FixedArray< Util::Tuple< IndexT, SizeT > >, Util::FixedArray< Util::Array< MaterialTexture > >, Util::FixedArray< Util::Array< MaterialConstant > >, IndexT, const MaterialTemplates::Entry * > MaterialAllocator
Definition material.h:133
void MaterialSetTexture(const MaterialId mat, const ShaderConfigBatchTexture *bind, const Resources::ResourceId tex)
Set texture.
Definition material.cc:168
material
Definition material.h:31
MaterialInstanceId CreateMaterialInstance(const MaterialId material)
Create material instance.
Definition material.cc:370
void MaterialSetConstants(const MaterialId mat, const void *data, const uint size)
Set all material constants.
Definition material.cc:232
#define RESOURCE_ID_TYPE(type)
Definition resourceid.h:41
Definition buffer.h:23
Definition commandbuffer.h:155
texture type
Definition texture.h:25
Definition materialtemplatetypes.h:65
Definition material.h:82
IndexT binding
Definition material.h:86
MaterialVariant defaultValue
Definition material.h:83
CoreGraphics::BufferId buffer
Definition material.h:87
MaterialConstant()
Definition material.h:89
bool instanceConstant
Definition material.h:85
IndexT bufferIndex
Definition material.h:84
Definition material.h:30
Definition material.h:31
Definition material.h:96
CoreGraphics::TextureId defaultValue
Definition material.h:97
IndexT slot
Definition material.h:98
Definition materialvariant.h:15
Definition shaderconfig.h:30
unsigned char ubyte
Definition types.h:34
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48