5#include <unordered_map>
8#include "render/general/pipeline/PipelineManager.h"
9#include "io/Serializable.h"
10#include "shader/general/ShaderMacro.h"
11#include "math/GLMath.hpp"
12#include "shader/general/resources/cpuwrite/ShaderCpuWriteResourceUniquePtr.h"
13#include "shader/general/resources/texture/ShaderTextureResourceUniquePtr.h"
14#include "shader/VulkanAlignmentConstants.hpp"
15#include "material/TextureManager.h"
17#include "Material.generated.h"
19namespace ne RNAMESPACE() {
121 static size_t getCurrentAliveMaterialCount();
136 static std::variant<std::unique_ptr<Material>,
Error> create(
137 const std::string& sVertexShaderName,
138 const std::string& sPixelShaderName,
139 bool bUseTransparency,
140 const std::string& sMaterialName =
"Material");
147 void setEnableTransparency(
bool bEnable);
154 void setDiffuseColor(
const glm::vec3& diffuseColor);
169 void setDiffuseTexture(
const std::string& sTextureResourcePathRelativeRes);
176 void setSpecularColor(
const glm::vec3& specularColor);
184 void setRoughness(
float roughness);
194 void setOpacity(
float opacity = 1.0F);
201 bool isTransparencyEnabled();
208 glm::vec3 getDiffuseColor()
const;
215 glm::vec3 getSpecularColor()
const;
223 std::string getPathToDiffuseTextureResource();
230 float getRoughness()
const;
237 float getOpacity()
const;
245 std::pair<std::mutex, MeshNodesThatUseThisMaterial>* getSpawnedMeshNodesThatUseThisMaterial();
252 std::string getMaterialName()
const;
259 bool isUsingTransparency()
const;
279 Pipeline* getDepthOnlyPipeline()
const;
290 Pipeline* getShadowMappingDirectionalSpotPipeline()
const;
301 Pipeline* getShadowMappingPointPipeline()
const;
309 return &mtxGpuResources;
317 std::string getVertexShaderName()
const;
324 std::string getPixelShaderName()
const;
334 virtual void onAfterDeserialized()
override;
384 alignas(iVkVec4Alignment) glm::vec4 diffuseColor = glm::vec4(1.0F, 1.0F, 1.0F, 1.0F);
387 alignas(iVkVec4Alignment) glm::vec4 specularColor = glm::vec4(1.0F, 1.0F, 1.0F, 1.0F);
390 alignas(iVkScalarAlignment)
float roughness = 0.0F;
404 static std::variant<PipelineManager*, Error> getPipelineManagerForNewMaterial(
405 const std::string& sVertexShaderName,
const std::string& sPixelShaderName);
420 const std::string& sVertexShaderName,
421 const std::string& sPixelShaderName,
422 bool bUseTransparency,
424 const std::string& sMaterialName =
"Material");
434 void onMeshNodeSpawning(
435 MeshNode* pMeshNode,
const std::pair<GpuResource*, unsigned int>& indexBufferToDisplay);
446 void onSpawnedMeshNodeStartedUsingMaterial(
447 MeshNode* pMeshNode,
const std::pair<GpuResource*, unsigned int>& indexBufferToDisplay);
459 void onSpawnedMeshNodeRecreatedIndexBuffer(
461 const std::pair<GpuResource*, unsigned int>& deletedIndexBuffer,
462 const std::pair<GpuResource*, unsigned int>& newIndexBuffer);
472 void onSpawnedMeshNodeChangedVisibility(
MeshNode* pMeshNode,
bool bOldVisibility);
483 void onSpawnedMeshNodeStoppedUsingMaterial(
484 MeshNode* pMeshNode,
const std::pair<GpuResource*, unsigned int>& indexBufferDisplayed);
494 void onMeshNodeDespawning(
495 MeshNode* pMeshNode,
const std::pair<GpuResource*, unsigned int>& indexBufferDisplayed);
504 [[nodiscard]] std::optional<Error> initializePipelines();
507 void resetPipelines();
514 void allocateShaderResources();
521 void deallocateShaderResources();
549 void setShaderCpuWriteResourceBindingData(
550 const std::string& sShaderResourceName,
551 size_t iResourceSizeInBytes,
552 const std::function<
void*()>& onStartedUpdatingResource,
553 const std::function<
void()>& onFinishedUpdatingResource);
566 void setShaderTextureResourceBindingData(
567 const std::string& sShaderResourceName,
const std::string& sPathToTextureResourceRelativeRes);
588 void markShaderCpuWriteResourceAsNeedsUpdate(
const std::string& sShaderResourceName);
594 void updateToNewPipeline();
601 void* onStartUpdatingShaderMeshConstants();
604 void onFinishedUpdatingShaderMeshConstants();
612 std::set<ShaderMacro> getVertexShaderMacrosForCurrentState();
620 std::set<ShaderMacro> getPixelShaderMacrosForCurrentState();
642 std::
string sVertexShaderName;
646 std::
string sPixelShaderName;
650 std::
string sMaterialName;
657 std::
string sDiffuseTexturePathRelativeRes;
661 glm::vec3 diffuseColor = glm::vec3(1.0F, 1.0F, 1.0F);
665 glm::vec3 specularColor = glm::vec3(1.0F, 1.0F, 1.0F);
669 float roughness = 0.7F;
677 float opacity = 0.6F;
681 bool bUseTransparency = false;
684 bool bIsShaderResourcesAllocated = false;
687 static inline const auto sMaterialShaderConstantBufferName = "materialData";
690 static inline const auto sMaterialShaderDiffuseTextureName = "diffuseTexture";
692 ne_Material_GENERATED
696File_Material_GENERATED
Definition: GpuResource.h:14
Definition: GuidProperty.h:30
Definition: Material.h:84
std::pair< std::recursive_mutex, GpuResources > mtxGpuResources
Definition: Material.h:632
std::pair< std::recursive_mutex, GpuResources > * getMaterialGpuResources()
Definition: Material.h:308
std::pair< std::recursive_mutex, MaterialShaderConstants > mtxShaderMaterialDataConstants
Definition: Material.h:635
std::pair< std::mutex, MeshNodesThatUseThisMaterial > mtxSpawnedMeshNodesThatUseThisMaterial
Definition: Material.h:626
std::pair< std::recursive_mutex, InternalResources > mtxInternalResources
Definition: Material.h:629
Definition: MeshNode.h:148
Definition: PipelineManager.h:89
Definition: PipelineSharedPtr.h:15
Definition: Pipeline.h:20
Definition: Serializable.h:113
Definition: SerializeProperty.h:42
Definition: Material.h:94
std::unordered_map< std::string, ShaderCpuWriteResourceUniquePtr > shaderCpuWriteResources
Definition: Material.h:98
std::unordered_map< std::string, ShaderTextureResourceUniquePtr > shaderTextureResources
Definition: Material.h:101
Definition: Material.h:90
ShaderResources shaderResources
Definition: Material.h:105
Definition: Material.h:338
PipelineSharedPtr pColorPipeline
Definition: Material.h:347
PipelineSharedPtr pShadowMappingPointPipeline
Definition: Material.h:372
PipelineSharedPtr pShadowMappingDirectionalSpotPipeline
Definition: Material.h:364
PipelineSharedPtr pDepthOnlyPipeline
Definition: Material.h:355
Definition: Material.h:380
Definition: Material.h:24
MeshIndexBufferInfo()=default
MeshIndexBufferInfo(GpuResource *pIndexBuffer, unsigned int iIndexCount)
Definition: Material.h:34
GpuResource * pIndexBuffer
Definition: Material.h:40
unsigned int iIndexCount
Definition: Material.h:43
Definition: Material.h:47
bool isMeshNodeAdded(MeshNode *pMeshNode)
Definition: Material.h:62
size_t getTotalSize() const
Definition: Material.h:53
std::unordered_map< MeshNode *, std::vector< MeshIndexBufferInfo > > visibleMeshNodes
Definition: Material.h:77
std::unordered_map< MeshNode *, std::vector< MeshIndexBufferInfo > > invisibleMeshNodes
Definition: Material.h:80