Nameless Engine
Loading...
Searching...
No Matches
ne::Material Class Reference

#include <Material.h>

Inheritance diagram for ne::Material:
ne::Serializable

Classes

struct  GpuResources
 
struct  InternalResources
 
struct  MaterialShaderConstants
 

Public Member Functions

 Material ()
 
 Material (const Material &)=delete
 
Materialoperator= (const Material &)=delete
 
void setEnableTransparency (bool bEnable)
 
void setDiffuseColor (const glm::vec3 &diffuseColor)
 
void setDiffuseTexture (const std::string &sTextureResourcePathRelativeRes)
 
void setSpecularColor (const glm::vec3 &specularColor)
 
void setRoughness (float roughness)
 
void setOpacity (float opacity=1.0F)
 
bool isTransparencyEnabled ()
 
glm::vec3 getDiffuseColor () const
 
glm::vec3 getSpecularColor () const
 
std::string getPathToDiffuseTextureResource ()
 
float getRoughness () const
 
float getOpacity () const
 
std::pair< std::mutex, MeshNodesThatUseThisMaterial > * getSpawnedMeshNodesThatUseThisMaterial ()
 
std::string getMaterialName () const
 
bool isUsingTransparency () const
 
PipelinegetColorPipeline () const
 
PipelinegetDepthOnlyPipeline () const
 
PipelinegetShadowMappingDirectionalSpotPipeline () const
 
PipelinegetShadowMappingPointPipeline () const
 
std::pair< std::recursive_mutex, GpuResources > * getMaterialGpuResources ()
 
std::string getVertexShaderName () const
 
std::string getPixelShaderName () const
 
- Public Member Functions inherited from ne::Serializable
std::optional< Errorserialize (std::filesystem::path pathToFile, bool bEnableBackup, const std::unordered_map< std::string, std::string > &customAttributes={})
 
std::variant< std::string, Errorserialize (toml::value &tomlData, const std::string &sEntityId="", const std::unordered_map< std::string, std::string > &customAttributes={}, const std::optional< std::filesystem::path > &optionalPathToFile={}, bool bEnableBackup=false)
 
std::variant< std::string, Errorserialize (toml::value &tomlData, Serializable *pOriginalObject, std::string sEntityId="", const std::unordered_map< std::string, std::string > &customAttributes={}, const std::optional< std::filesystem::path > &optionalPathToFile={}, bool bEnableBackup=false)
 
std::optional< std::pair< std::string, std::string > > getPathDeserializedFromRelativeToRes () const
 

Static Public Member Functions

static size_t getCurrentAliveMaterialCount ()
 
static std::variant< std::unique_ptr< Material >, Errorcreate (const std::string &sVertexShaderName, const std::string &sPixelShaderName, bool bUseTransparency, const std::string &sMaterialName="Material")
 
- Static Public Member Functions inherited from ne::Serializable
static std::variant< std::pair< std::set< std::string >, toml::value >, ErrorgetIdsFromFile (std::filesystem::path pathToFile)
 
static std::optional< ErrorserializeMultiple (std::filesystem::path pathToFile, std::vector< SerializableObjectInformation > vObjects, bool bEnableBackup)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (const std::filesystem::path &pathToFile)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (const std::filesystem::path &pathToFile, std::unordered_map< std::string, std::string > &customAttributes)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (std::filesystem::path pathToFile, std::unordered_map< std::string, std::string > &customAttributes, const std::string &sEntityId)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (const std::filesystem::path &pathToFile, const std::string &sEntityId)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::same_as<SmartPointer, sgc::GcPtr<Serializable>> || std::same_as<SmartPointer, std::unique_ptr<Serializable>>
static std::variant< std::vector< DeserializedObjectInformation< SmartPointer > >, ErrordeserializeMultiple (std::filesystem::path pathToFile)
 
template<typename SmartPointer , typename InnerType = typename SmartPointer::element_type>
requires std::derived_from<InnerType, Serializable> && (std::same_as<SmartPointer, sgc::GcPtr<InnerType>> || std::same_as<SmartPointer, std::unique_ptr<InnerType>>)
static std::variant< SmartPointer, Errordeserialize (const toml::value &tomlData, std::unordered_map< std::string, std::string > &customAttributes, std::string sEntityId="", const std::optional< std::filesystem::path > &optionalPathToFile={})
 

Protected Member Functions

virtual void onAfterDeserialized () override
 
virtual void onAfterDeserialized ()
 

Private Member Functions

 Material (const std::string &sVertexShaderName, const std::string &sPixelShaderName, bool bUseTransparency, PipelineManager *pPipelineManager, const std::string &sMaterialName="Material")
 
void onMeshNodeSpawning (MeshNode *pMeshNode, const std::pair< GpuResource *, unsigned int > &indexBufferToDisplay)
 
void onSpawnedMeshNodeStartedUsingMaterial (MeshNode *pMeshNode, const std::pair< GpuResource *, unsigned int > &indexBufferToDisplay)
 
void onSpawnedMeshNodeRecreatedIndexBuffer (MeshNode *pMeshNode, const std::pair< GpuResource *, unsigned int > &deletedIndexBuffer, const std::pair< GpuResource *, unsigned int > &newIndexBuffer)
 
void onSpawnedMeshNodeChangedVisibility (MeshNode *pMeshNode, bool bOldVisibility)
 
void onSpawnedMeshNodeStoppedUsingMaterial (MeshNode *pMeshNode, const std::pair< GpuResource *, unsigned int > &indexBufferDisplayed)
 
void onMeshNodeDespawning (MeshNode *pMeshNode, const std::pair< GpuResource *, unsigned int > &indexBufferDisplayed)
 
std::optional< ErrorinitializePipelines ()
 
void resetPipelines ()
 
void allocateShaderResources ()
 
void deallocateShaderResources ()
 
void setShaderCpuWriteResourceBinding (const std::string &sShaderResourceName, size_t iResourceSizeInBytes, const std::function< void *()> &onStartedUpdatingResource, const std::function< void()> &onFinishedUpdatingResource)
 
void setShaderTextureResourceBinding (const std::string &sShaderResourceName, const std::string &sPathToTextureResourceRelativeRes)
 
void markShaderCpuWriteResourceAsNeedsUpdate (const std::string &sShaderResourceName)
 
void updateToNewPipeline ()
 
void * onStartUpdatingShaderMeshConstants ()
 
void onFinishedUpdatingShaderMeshConstants ()
 
std::set< ShaderMacro > getVertexShaderMacrosForCurrentState ()
 
std::set< ShaderMacro > getPixelShaderMacrosForCurrentState ()
 

Static Private Member Functions

static std::variant< PipelineManager *, ErrorgetPipelineManagerForNewMaterial (const std::string &sVertexShaderName, const std::string &sPixelShaderName)
 

Private Attributes

std::pair< std::mutex, MeshNodesThatUseThisMaterialmtxSpawnedMeshNodesThatUseThisMaterial
 
std::pair< std::recursive_mutex, InternalResourcesmtxInternalResources
 
std::pair< std::recursive_mutex, GpuResourcesmtxGpuResources
 
std::pair< std::recursive_mutex, MaterialShaderConstantsmtxShaderMaterialDataConstants
 
PipelineManagerpPipelineManager = nullptr
 
std::string sVertexShaderName
 
std::string sPixelShaderName
 
std::string sMaterialName
 
std::string sDiffuseTexturePathRelativeRes
 
glm::vec3 diffuseColor = glm::vec3(1.0F, 1.0F, 1.0F)
 
glm::vec3 specularColor = glm::vec3(1.0F, 1.0F, 1.0F)
 
float roughness = 0.7F
 
float opacity = 0.6F
 
bool bUseTransparency = false
 
bool bIsShaderResourcesAllocated = false
 

Static Private Attributes

static const auto sMaterialShaderBufferName = "materialData"
 
static const auto sMaterialShaderDiffuseTextureName = "diffuseTextures"
 

Friends

class MeshNode
 

Detailed Description

Defines visual aspects of a mesh.

Constructor & Destructor Documentation

◆ Material() [1/2]

ne::Material::Material ( )

Creates uninitialized material, only used for deserialization, instead use create.

◆ Material() [2/2]

ne::Material::Material ( const std::string &  sVertexShaderName,
const std::string &  sPixelShaderName,
bool  bUseTransparency,
PipelineManager pPipelineManager,
const std::string &  sMaterialName = "Material" 
)
private

Creates a new material with the specified name.

Remarks
This constructor should only be used internally (only by this class), use create instead.
Parameters
sVertexShaderNameName of the vertex shader that this material is using.
sPixelShaderNameName of the pixel shader that this material is using.
bUseTransparencyWhether this material will use transparency or not.
pPipelineManagerPipeline manager that the renderer owns.
sMaterialNameName of this material.

Member Function Documentation

◆ allocateShaderResources()

void ne::Material::allocateShaderResources ( )
private

Creates shader resources such as material's constant buffer.

Remarks
Should be called after pipeline was initialized.

◆ create()

std::variant< std::unique_ptr< Material >, Error > ne::Material::create ( const std::string &  sVertexShaderName,
const std::string &  sPixelShaderName,
bool  bUseTransparency,
const std::string &  sMaterialName = "Material" 
)
static

Creates a new material that uses the specified shaders.

Parameters
sVertexShaderNameName of the compiled vertex shader (see ShaderManager::compileShaders) to use.
sPixelShaderNameName of the compiled pixel shader (see ShaderManager::compileShaders) to use.
bUseTransparencyWhether this material should enable transparency after being created or not (see setEnableTransparency).
sMaterialNameName of this material.
Returns
Error if something went wrong, otherwise created material.

◆ deallocateShaderResources()

void ne::Material::deallocateShaderResources ( )
private

Deallocates shader resources after allocateShaderResources was called.

Remarks
Should be called before pipeline is cleared.

◆ getColorPipeline()

Pipeline * ne::Material::getColorPipeline ( ) const

Returns pipeline with pixel/fragment shader enabled (this pipeline is considered to be the main pipeline while others might be optional).

Warning
Do not delete returned pointer.
Returns
nullptr if pipeline was not initialized yet, otherwise used pipeline.

◆ getCurrentAliveMaterialCount()

size_t ne::Material::getCurrentAliveMaterialCount ( )
static

Returns total amount of currently alive material objects.

Returns
Total amount of alive materials.

◆ getDepthOnlyPipeline()

Pipeline * ne::Material::getDepthOnlyPipeline ( ) const

Returns pipeline that only has vertex shader (used for depth only passes).

Warning
Do not delete returned pointer.
Returns
nullptr if pipeline was not initialized yet or if isUsingTransparency is enabled, otherwise used pipeline.

◆ getDiffuseColor()

glm::vec3 ne::Material::getDiffuseColor ( ) const

Returns fill color of this material.

Returns
Color in the RGB format.

◆ getMaterialGpuResources()

std::pair< std::recursive_mutex, GpuResources > * ne::Material::getMaterialGpuResources ( )
inline

Returns GPU resources that this material uses.

Returns
GPU resources.

◆ getMaterialName()

std::string ne::Material::getMaterialName ( ) const

Returns material name.

Returns
Material name.

◆ getOpacity()

float ne::Material::getOpacity ( ) const

Returns opacity of this material.

Returns
Value in range [0.0F; 1.0F].

◆ getPathToDiffuseTextureResource()

std::string ne::Material::getPathToDiffuseTextureResource ( )

Returns path to a file/directory that stores currently used diffuse texture of this material.

Returns
Empty if no diffuse texture is set, otherwise path to a file/directory relative to the res directory.

◆ getPipelineManagerForNewMaterial()

std::variant< PipelineManager *, Error > ne::Material::getPipelineManagerForNewMaterial ( const std::string &  sVertexShaderName,
const std::string &  sPixelShaderName 
)
staticprivate

Returns pipeline manager.

Remarks
Generally called before creating a new material to get pipeline manager and also check that selected shader names indeed exist.
Parameters
sVertexShaderNameName of the vertex shader that the material is using.
sPixelShaderNameName of the pixel shader that the material is using.
Returns
Error if something went wrong, otherwise pipeline manager.

◆ getPixelShaderMacrosForCurrentState()

std::set< ShaderMacro > ne::Material::getPixelShaderMacrosForCurrentState ( )
private

Analyzes mtxInternalResources and returns pixel/fragment shader macros that should be enabled to support the material's features.

Returns
Macros.

◆ getPixelShaderName()

std::string ne::Material::getPixelShaderName ( ) const

Returns name of the pixel shader that this material uses.

Returns
Pixel shader name.

◆ getRoughness()

float ne::Material::getRoughness ( ) const

Returns roughness of this material.

Returns
Value in range [0.0F; 1.0F].

◆ getShadowMappingDirectionalSpotPipeline()

Pipeline * ne::Material::getShadowMappingDirectionalSpotPipeline ( ) const

Returns pipeline that only has vertex shader and depth bias enabled, used for shadow passes of directional and spot lights.

Warning
Do not delete returned pointer.
Returns
nullptr if pipeline was not initialized yet or if isUsingTransparency is enabled, otherwise used pipeline.

◆ getShadowMappingPointPipeline()

Pipeline * ne::Material::getShadowMappingPointPipeline ( ) const

Returns pipeline that only has vertex shader and depth bias enabled, used for shadow passes of point lights.

Warning
Do not delete returned pointer.
Returns
nullptr if pipeline was not initialized yet or if isUsingTransparency is enabled, otherwise used pipeline.

◆ getSpawnedMeshNodesThatUseThisMaterial()

std::pair< std::mutex, MeshNodesThatUseThisMaterial > * ne::Material::getSpawnedMeshNodesThatUseThisMaterial ( )

Returns array of mesh nodes that currently use this material. Must be used with mutex.

Returns
Array of mesh nodes.

◆ getSpecularColor()

glm::vec3 ne::Material::getSpecularColor ( ) const

Returns reflected color of this material.

Returns
Color in the RGB format.

◆ getVertexShaderMacrosForCurrentState()

std::set< ShaderMacro > ne::Material::getVertexShaderMacrosForCurrentState ( )
private

Analyzes mtxInternalResources and returns vertex shader macros that should be enabled to support the material's features.

Returns
Macros.

◆ getVertexShaderName()

std::string ne::Material::getVertexShaderName ( ) const

Returns name of the vertex shader that this material uses.

Returns
Vertex shader name.

◆ initializePipelines()

std::optional< Error > ne::Material::initializePipelines ( )
private

Initializes pipelines that the material needs.

Remarks
Expects that pipelines are not initialized.
Returns
Error if something went wrong.

◆ isTransparencyEnabled()

bool ne::Material::isTransparencyEnabled ( )

Tells whether transparency on this material is enabled or not.

Returns
true if enabled, false otherwise.

◆ isUsingTransparency()

bool ne::Material::isUsingTransparency ( ) const

Tells whether this material uses transparency or not.

Returns
Whether this material uses transparency or not.

◆ markShaderCpuWriteResourceAsNeedsUpdate()

void ne::Material::markShaderCpuWriteResourceAsNeedsUpdate ( const std::string &  sShaderResourceName)
private

Looks for binding created using setShaderCpuWriteResourceBinding and notifies the engine that there is new (updated) data for shader CPU write resource to copy to the GPU to be used by shaders.

Remarks
You don't need to check if the pipeline is initialized or not before calling this function, if the binding does not exist or some other condition is not met this call will be silently ignored without any errors.
Note that the callbacks that you have specified in setShaderCpuWriteResourceBinding will not be called inside of this function, moreover they are most likely to be called in the next frame(s) (most likely multiple times) when the engine is ready to copy the data to the GPU, so if the resource's data is used by multiple threads in your code, make sure to use mutex or other synchronization primitive in your callbacks.
Parameters
sShaderResourceNameName of the shader CPU write resource (should be exactly the same as the resource name written in the shader file we are referencing).

◆ onAfterDeserialized()

void ne::Material::onAfterDeserialized ( )
overrideprotectedvirtual

Called after the object was successfully deserialized. Used to execute post-deserialization logic.

Warning
If overriding you must call the parent's version of this function first (before executing your login) to execute parent's logic.

Reimplemented from ne::Serializable.

◆ onFinishedUpdatingShaderMeshConstants()

void ne::Material::onFinishedUpdatingShaderMeshConstants ( )
private

Called after finished copying data from mtxShaderMaterialDataConstants.

◆ onMeshNodeDespawning()

void ne::Material::onMeshNodeDespawning ( MeshNode pMeshNode,
const std::pair< GpuResource *, unsigned int > &  indexBufferDisplayed 
)
private

Called from MeshNode when a spawned mesh node that uses this material is being despawned.

Warning
Expects that the mesh will not change its visibility while calling this function.
Parameters
pMeshNodeSpawned mesh node that is being despawned.
indexBufferDisplayedIndex buffer that this material was displaying.

◆ onMeshNodeSpawning()

void ne::Material::onMeshNodeSpawning ( MeshNode pMeshNode,
const std::pair< GpuResource *, unsigned int > &  indexBufferToDisplay 
)
private

Called from MeshNode when a mesh node that uses this material is being spawned.

Warning
Expects that the mesh will not change its visibility while calling this function.
Parameters
pMeshNodeMesh node that is currently being spawned.
indexBufferToDisplayIndex buffer that this material should display.

◆ onSpawnedMeshNodeChangedVisibility()

void ne::Material::onSpawnedMeshNodeChangedVisibility ( MeshNode pMeshNode,
bool  bOldVisibility 
)
private

Called from MeshNode when a spawned mesh node changed its visibility.

Warning
Expects that the mesh will not change its visibility while calling this function.
Parameters
pMeshNodeSpawned mesh node that is using this material.
bOldVisibilityOld visibility of the mesh.

◆ onSpawnedMeshNodeRecreatedIndexBuffer()

void ne::Material::onSpawnedMeshNodeRecreatedIndexBuffer ( MeshNode pMeshNode,
const std::pair< GpuResource *, unsigned int > &  deletedIndexBuffer,
const std::pair< GpuResource *, unsigned int > &  newIndexBuffer 
)
private

Called from MeshNode when a spawned mesh node re-created some index buffer and now wants to notify the material about it.

Warning
Expects that the mesh will not change its visibility while calling this function.
Parameters
pMeshNodeSpawned mesh node that is using this material.
deletedIndexBufferIndex buffer that was deleted.
newIndexBufferIndex buffer that this material should display now.

◆ onSpawnedMeshNodeStartedUsingMaterial()

void ne::Material::onSpawnedMeshNodeStartedUsingMaterial ( MeshNode pMeshNode,
const std::pair< GpuResource *, unsigned int > &  indexBufferToDisplay 
)
private

Called from MeshNode when a spawned mesh node changed its material and started using this material now.

Warning
Expects that the mesh will not change its visibility while calling this function.
Parameters
pMeshNodeSpawned mesh node that is using this material.
indexBufferToDisplayIndex buffer that this material should display.

◆ onSpawnedMeshNodeStoppedUsingMaterial()

void ne::Material::onSpawnedMeshNodeStoppedUsingMaterial ( MeshNode pMeshNode,
const std::pair< GpuResource *, unsigned int > &  indexBufferDisplayed 
)
private

Called from MeshNode when a spawned mesh node changed its material and now no longer using this material.

Warning
Expects that the mesh will not change its visibility while calling this function.
Parameters
pMeshNodeSpawned mesh node that stopped using this material.
indexBufferDisplayedIndex buffer that this material was displaying.

◆ onStartUpdatingShaderMeshConstants()

void * ne::Material::onStartUpdatingShaderMeshConstants ( )
private

Called to copy data from mtxShaderMaterialDataConstants.

Returns
Pointer to data in mtxShaderMaterialDataConstants.

◆ resetPipelines()

void ne::Material::resetPipelines ( )
private

Clears (sets to nullptr) all used pipelines.

◆ setDiffuseColor()

void ne::Material::setDiffuseColor ( const glm::vec3 &  diffuseColor)

Sets material's fill color.

Parameters
diffuseColorColor in the RGB format.

◆ setDiffuseTexture()

void ne::Material::setDiffuseTexture ( const std::string &  sTextureResourcePathRelativeRes)

Sets material's diffuse texture.

Example:

// Specify path to a directory that stores DDS and KTX files with player's diffuse texture.
pMaterial->setDiffuseTexture("game/player/textures/diffuse");
Parameters
sTextureResourcePathRelativeResPath to a texture resource (file/directory) relative to res directory that this material should now use. Specify empty string to clear the current diffuse texture (if any is set) and don't use diffuse texture at all.

◆ setEnableTransparency()

void ne::Material::setEnableTransparency ( bool  bEnable)

Enables/disables transparency.

Parameters
bEnableWhether to enable transparency or not.

◆ setOpacity()

void ne::Material::setOpacity ( float  opacity = 1.0F)

Sets material's opacity.

Remarks
Only works if the material has transparency enabled (see create or setEnableTransparency).
Parameters
opacityValue in range [0.0F; 1.0F], will be clamped if outside of this range.

◆ setRoughness()

void ne::Material::setRoughness ( float  roughness)

Sets factor that defines how much specular light will be reflected (i.e. how rough or smooth the surface is).

Parameters
roughnessValue in range [0.0F; 1.0F], will be clamped if outside of this range.

◆ setShaderCpuWriteResourceBinding()

void ne::Material::setShaderCpuWriteResourceBinding ( const std::string &  sShaderResourceName,
size_t  iResourceSizeInBytes,
const std::function< void *()> &  onStartedUpdatingResource,
const std::function< void()> &  onFinishedUpdatingResource 
)
private

Setups callbacks for a shader resource (buffer or a texture from the shader code) with CPU write access to copy the data from the CPU to the GPU to be used by the shaders.

Remarks
Call this function in allocateShaderResources to bind to shader resources, all bindings will be automatically removed in deallocateShaderResources.
When data of a resource that you registered was updated on the CPU side you need to call markShaderCpuWriteResourceAsNeedsUpdate so that update callbacks will be called and updated data will be copied to the GPU to be used by shaders. Note that you don't need to call markShaderCpuWriteResourceAsNeedsUpdate for resources you have not registered yourself. Also note that all registered resources are marked as "need update" by default so you don't have to call markShaderCpuWriteResourceAsNeedsUpdate right after calling this function.
Parameters
sShaderResourceNameName of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing).
iResourceSizeInBytesSize of the data that this resource will contain. Note that the specified size will most likely be padded (changed) to be a multiple of 256 because of the hardware requirement for shader constant buffers.
onStartedUpdatingResourceFunction that will be called when the engine has started copying data to the GPU. Function returns pointer to new (updated) data of the specified resource that will be copied to the GPU.
onFinishedUpdatingResourceFunction that will be called when the engine has finished copying resource data to the GPU (usually used for unlocking mutexes).

◆ setShaderTextureResourceBinding()

void ne::Material::setShaderTextureResourceBinding ( const std::string &  sShaderResourceName,
const std::string &  sPathToTextureResourceRelativeRes 
)
private

Setups a shader resource binding that references a texture that will be used in shaders when this material is rendered.

Remarks
Call this function in allocateShaderResources to bind to shader resources, all bindings will be automatically removed in deallocateShaderResources.
Parameters
sShaderResourceNameName of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing).
sPathToTextureResourceRelativeResPath to the directory with texture resource to use.

◆ setSpecularColor()

void ne::Material::setSpecularColor ( const glm::vec3 &  specularColor)

Sets material's reflected color.

Parameters
specularColorColor in the RGB format.

◆ updateToNewPipeline()

void ne::Material::updateToNewPipeline ( )
private

Releases all shader resources, requests a new pipeline according to currently defined shader macros, allocates all shader resources and notifies all mesh nodes that use this material.

Member Data Documentation

◆ bIsShaderResourcesAllocated

bool ne::Material::bIsShaderResourcesAllocated = false
private

Whether allocateShaderResources was called or not.

◆ bUseTransparency

bool ne::Material::bUseTransparency = false
private

Whether this material will use transparency or not.

◆ diffuseColor

glm::vec3 ne::Material::diffuseColor = glm::vec3(1.0F, 1.0F, 1.0F)
private

Fill color.

◆ mtxGpuResources

std::pair<std::recursive_mutex, GpuResources> ne::Material::mtxGpuResources
private

Stores GPU resources used by this material.

◆ mtxInternalResources

std::pair<std::recursive_mutex, InternalResources> ne::Material::mtxInternalResources
private

Internal data.

◆ mtxShaderMaterialDataConstants

std::pair<std::recursive_mutex, MaterialShaderConstants> ne::Material::mtxShaderMaterialDataConstants
private

Stores data for constant buffer used by shaders.

◆ mtxSpawnedMeshNodesThatUseThisMaterial

std::pair<std::mutex, MeshNodesThatUseThisMaterial> ne::Material::mtxSpawnedMeshNodesThatUseThisMaterial
private

Array of spawned mesh nodes that use this material. Must be used with mutex.

◆ opacity

float ne::Material::opacity = 0.6F
private

Opacity in range [0.0; 1.0].

Remarks
Only used when bUseTransparency is enabled.

◆ pPipelineManager

PipelineManager* ne::Material::pPipelineManager = nullptr
private

Do not delete (free) this pointer. Pipeline manager that the renderer owns.

◆ roughness

float ne::Material::roughness = 0.7F
private

Defines how much specular light will be reflected. Value in range [0.0F; 1.0F].

◆ sDiffuseTexturePathRelativeRes

std::string ne::Material::sDiffuseTexturePathRelativeRes
private

Empty if diffuse texture is not used, otherwise path to used diffuse texture relative to res directory.

◆ sMaterialName

std::string ne::Material::sMaterialName
private

Name of this material.

◆ sMaterialShaderBufferName

const auto ne::Material::sMaterialShaderBufferName = "materialData"
inlinestaticprivate

Name of the buffer used to store material data in shaders.

◆ sMaterialShaderDiffuseTextureName

const auto ne::Material::sMaterialShaderDiffuseTextureName = "diffuseTextures"
inlinestaticprivate

Name of the resource used to store diffuse textures in shaders.

◆ specularColor

glm::vec3 ne::Material::specularColor = glm::vec3(1.0F, 1.0F, 1.0F)
private

Reflected color.

◆ sPixelShaderName

std::string ne::Material::sPixelShaderName
private

Name of the pixel shader that this material is using.

◆ sVertexShaderName

std::string ne::Material::sVertexShaderName
private

Name of the vertex shader that this material is using.


The documentation for this class was generated from the following files: