5#include <unordered_map>
8#include "io/Serializable.h"
9#include "shader/general/ShaderMacro.h"
10#include "math/GLMath.hpp"
11#include "shader/general/resource/binding/cpuwrite/ShaderCpuWriteResourceBindingUniquePtr.h"
12#include "shader/general/resource/binding/texture/ShaderTextureResourceBindingUniquePtr.h"
13#include "shader/VulkanAlignmentConstants.hpp"
14#include "render/general/resource/MeshData.h"
15#include "render/general/pipeline/PipelineSharedPtr.h"
17#include "Material.generated.h"
19namespace ne RNAMESPACE() {
23 class PipelineManager;
77 std::unordered_map<std::string, ShaderCpuWriteResourceBindingUniquePtr>
101 static size_t getCurrentAliveMaterialCount();
116 static std::variant<std::unique_ptr<Material>,
Error> create(
117 const std::string& sVertexShaderName,
118 const std::string& sPixelShaderName,
119 bool bUseTransparency,
120 const std::string& sMaterialName =
"Material");
127 void setEnableTransparency(
bool bEnable);
134 void setDiffuseColor(
const glm::vec3& diffuseColor);
149 void setDiffuseTexture(
const std::string& sTextureResourcePathRelativeRes);
156 void setSpecularColor(
const glm::vec3& specularColor);
164 void setRoughness(
float roughness);
174 void setOpacity(
float opacity = 1.0F);
181 bool isTransparencyEnabled();
188 glm::vec3 getDiffuseColor()
const;
195 glm::vec3 getSpecularColor()
const;
203 std::string getPathToDiffuseTextureResource();
210 float getRoughness()
const;
217 float getOpacity()
const;
225 std::pair<std::mutex, MeshNodesThatUseThisMaterial>* getSpawnedMeshNodesThatUseThisMaterial();
232 std::string getMaterialName()
const;
239 bool isUsingTransparency()
const;
259 Pipeline* getDepthOnlyPipeline()
const;
270 Pipeline* getShadowMappingDirectionalSpotPipeline()
const;
281 Pipeline* getShadowMappingPointPipeline()
const;
289 return &mtxGpuResources;
297 std::string getVertexShaderName()
const;
304 std::string getPixelShaderName()
const;
314 virtual void onAfterDeserialized()
override;
364 alignas(iVkVec4Alignment) glm::vec4 diffuseColor = glm::vec4(1.0F, 1.0F, 1.0F, 1.0F);
367 alignas(iVkVec4Alignment) glm::vec4 specularColor = glm::vec4(1.0F, 1.0F, 1.0F, 1.0F);
370 alignas(iVkScalarAlignment)
float roughness = 0.0F;
387 static std::variant<PipelineManager*, Error> getPipelineManagerForNewMaterial(
388 const std::string& sVertexShaderName,
const std::string& sPixelShaderName);
403 const std::string& sVertexShaderName,
404 const std::string& sPixelShaderName,
405 bool bUseTransparency,
407 const std::string& sMaterialName =
"Material");
417 void onMeshNodeSpawning(
418 MeshNode* pMeshNode,
const std::pair<GpuResource*, unsigned int>& indexBufferToDisplay);
429 void onSpawnedMeshNodeStartedUsingMaterial(
430 MeshNode* pMeshNode,
const std::pair<GpuResource*, unsigned int>& indexBufferToDisplay);
442 void onSpawnedMeshNodeRecreatedIndexBuffer(
444 const std::pair<GpuResource*, unsigned int>& deletedIndexBuffer,
445 const std::pair<GpuResource*, unsigned int>& newIndexBuffer);
455 void onSpawnedMeshNodeChangedVisibility(
MeshNode* pMeshNode,
bool bOldVisibility);
466 void onSpawnedMeshNodeStoppedUsingMaterial(
467 MeshNode* pMeshNode,
const std::pair<GpuResource*, unsigned int>& indexBufferDisplayed);
477 void onMeshNodeDespawning(
478 MeshNode* pMeshNode,
const std::pair<GpuResource*, unsigned int>& indexBufferDisplayed);
487 [[nodiscard]] std::optional<Error> initializePipelines();
490 void resetPipelines();
497 void allocateShaderResources();
504 void deallocateShaderResources();
532 void setShaderCpuWriteResourceBinding(
533 const std::string& sShaderResourceName,
534 size_t iResourceSizeInBytes,
535 const std::function<
void*()>& onStartedUpdatingResource,
536 const std::function<
void()>& onFinishedUpdatingResource);
549 void setShaderTextureResourceBinding(
550 const std::string& sShaderResourceName,
const std::string& sPathToTextureResourceRelativeRes);
571 void markShaderCpuWriteResourceAsNeedsUpdate(
const std::string& sShaderResourceName);
577 void updateToNewPipeline();
584 void* onStartUpdatingShaderMeshConstants();
587 void onFinishedUpdatingShaderMeshConstants();
595 std::set<ShaderMacro> getVertexShaderMacrosForCurrentState();
603 std::set<ShaderMacro> getPixelShaderMacrosForCurrentState();
625 std::
string sVertexShaderName;
629 std::
string sPixelShaderName;
633 std::
string sMaterialName;
640 std::
string sDiffuseTexturePathRelativeRes;
644 glm::vec3 diffuseColor = glm::vec3(1.0F, 1.0F, 1.0F);
648 glm::vec3 specularColor = glm::vec3(1.0F, 1.0F, 1.0F);
652 float roughness = 0.7F;
660 float opacity = 0.6F;
664 bool bUseTransparency = false;
667 bool bIsShaderResourcesAllocated = false;
670 static inline const auto sMaterialShaderBufferName = "materialData";
673 static inline const auto sMaterialShaderDiffuseTextureName = "diffuseTextures";
675 ne_Material_GENERATED
679File_Material_GENERATED
Definition: GuidProperty.h:30
Definition: Material.h:63
std::pair< std::recursive_mutex, GpuResources > mtxGpuResources
Definition: Material.h:615
std::pair< std::recursive_mutex, GpuResources > * getMaterialGpuResources()
Definition: Material.h:288
std::pair< std::recursive_mutex, MaterialShaderConstants > mtxShaderMaterialDataConstants
Definition: Material.h:618
std::pair< std::mutex, MeshNodesThatUseThisMaterial > mtxSpawnedMeshNodesThatUseThisMaterial
Definition: Material.h:609
std::pair< std::recursive_mutex, InternalResources > mtxInternalResources
Definition: Material.h:612
Definition: MeshNode.h:28
Definition: PipelineManager.h:98
Definition: PipelineSharedPtr.h:15
Definition: Pipeline.h:20
Definition: Serializable.h:113
Definition: SerializeProperty.h:42
Definition: Material.h:73
std::unordered_map< std::string, ShaderCpuWriteResourceBindingUniquePtr > shaderCpuWriteResources
Definition: Material.h:78
std::unordered_map< std::string, ShaderTextureResourceBindingUniquePtr > shaderTextureResources
Definition: Material.h:81
Definition: Material.h:69
ShaderResources shaderResources
Definition: Material.h:85
Definition: Material.h:318
PipelineSharedPtr pColorPipeline
Definition: Material.h:327
PipelineSharedPtr pShadowMappingPointPipeline
Definition: Material.h:352
PipelineSharedPtr pShadowMappingDirectionalSpotPipeline
Definition: Material.h:344
PipelineSharedPtr pDepthOnlyPipeline
Definition: Material.h:335
Definition: Material.h:360
Definition: Material.h:26
bool isMeshNodeAdded(MeshNode *pMeshNode)
Definition: Material.h:41
size_t getTotalSize() const
Definition: Material.h:32
std::unordered_map< MeshNode *, std::vector< MeshIndexBufferInfo > > visibleMeshNodes
Definition: Material.h:56
std::unordered_map< MeshNode *, std::vector< MeshIndexBufferInfo > > invisibleMeshNodes
Definition: Material.h:59