All Vec3 and Vec4s in materials are now automatically set to full 1.0 vectors
This commit is contained in:
parent
e733cd2e1c
commit
621dae4c40
|
@ -124,8 +124,7 @@ namespace Sandbox
|
||||||
auto& floorCollider = *SHComponentManager::GetComponent_s<SHColliderComponent>(floor);
|
auto& floorCollider = *SHComponentManager::GetComponent_s<SHColliderComponent>(floor);
|
||||||
|
|
||||||
floorRenderable.SetMesh(CUBE_MESH);
|
floorRenderable.SetMesh(CUBE_MESH);
|
||||||
floorRenderable.SetMaterial(customMat);
|
floorRenderable.SetMaterial(graphicsSystem->GetDefaultMaterialInstance());
|
||||||
floorRenderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
|
||||||
|
|
||||||
floorTransform.SetWorldScale({ 7.5f, 0.5f, 7.5 });
|
floorTransform.SetWorldScale({ 7.5f, 0.5f, 7.5 });
|
||||||
floorTransform.SetWorldPosition({ 0.0f, -3.0f, -5.0f });
|
floorTransform.SetWorldPosition({ 0.0f, -3.0f, -5.0f });
|
||||||
|
|
|
@ -200,7 +200,6 @@ namespace SHADE
|
||||||
auto cubeFS = shaderModuleLibrary.GetBuiltInShaderModule("TestCube_FS");
|
auto cubeFS = shaderModuleLibrary.GetBuiltInShaderModule("TestCube_FS");
|
||||||
|
|
||||||
defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferSubpass);
|
defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferSubpass);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHGraphicsSystem::InitMiddleEnd(void) noexcept
|
void SHGraphicsSystem::InitMiddleEnd(void) noexcept
|
||||||
|
|
|
@ -144,6 +144,7 @@ namespace SHADE
|
||||||
Handle<SHMaterialInstance> AddMaterialInstanceCopy(Handle<SHMaterialInstance> materialInst);
|
Handle<SHMaterialInstance> AddMaterialInstanceCopy(Handle<SHMaterialInstance> materialInst);
|
||||||
void RemoveMaterialInstance(Handle<SHMaterialInstance> materialInstance);
|
void RemoveMaterialInstance(Handle<SHMaterialInstance> materialInstance);
|
||||||
Handle<SHMaterial> GetDefaultMaterial() { return defaultMaterial; }
|
Handle<SHMaterial> GetDefaultMaterial() { return defaultMaterial; }
|
||||||
|
Handle<SHMaterialInstance> GetDefaultMaterialInstance() { return AddOrGetBaseMaterialInstance(defaultMaterial); }
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Mesh Registration Functions */
|
/* Mesh Registration Functions */
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include "Graphics/Pipeline/SHVkPipeline.h"
|
#include "Graphics/Pipeline/SHVkPipeline.h"
|
||||||
#include "SHGraphicsConstants.h"
|
#include "SHGraphicsConstants.h"
|
||||||
#include "Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h"
|
#include "Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h"
|
||||||
|
#include "Math/Vector/SHVec3.h"
|
||||||
|
#include "Math/Vector/SHVec4.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -49,6 +51,22 @@ namespace SHADE
|
||||||
// Reset all the properties to default values
|
// Reset all the properties to default values
|
||||||
if (propMemory)
|
if (propMemory)
|
||||||
memset(propMemory.get(), 0, propMemorySize);
|
memset(propMemory.get(), 0, propMemorySize);
|
||||||
|
|
||||||
|
// Initialize Vectors to all 1.0 by default
|
||||||
|
const Handle<SHShaderBlockInterface> SHADER_INFO = GetShaderBlockInterface();
|
||||||
|
for (int i = 0; i < SHADER_INFO->GetVariableCount(); ++i)
|
||||||
|
{
|
||||||
|
const auto& VAR = SHADER_INFO->GetVariable(i);
|
||||||
|
switch (VAR->type)
|
||||||
|
{
|
||||||
|
case SHShaderBlockInterface::Variable::Type::VECTOR3:
|
||||||
|
setPropertyUnsafe(VAR->offset, SHVec3::One);
|
||||||
|
break;
|
||||||
|
case SHShaderBlockInterface::Variable::Type::VECTOR4:
|
||||||
|
setPropertyUnsafe(VAR->offset, SHVec4::One);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHMaterial::ExportProperties(void* dest) const noexcept
|
void SHMaterial::ExportProperties(void* dest) const noexcept
|
||||||
|
|
|
@ -75,6 +75,12 @@ namespace SHADE
|
||||||
Handle<SHVkPipeline> pipeline;
|
Handle<SHVkPipeline> pipeline;
|
||||||
std::unique_ptr<char> propMemory;
|
std::unique_ptr<char> propMemory;
|
||||||
Byte propMemorySize = 0;
|
Byte propMemorySize = 0;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
template<typename T>
|
||||||
|
inline void setPropertyUnsafe(uint32_t memOffset, const T& value); // SetProperty() but without checks
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get offset and modify the memory directly
|
// Get offset and modify the memory directly
|
||||||
T* dataPtr = propMemory.get() + PROP_INFO->offset;
|
T* dataPtr = reinterpret_cast<T*>(propMemory.get() + PROP_INFO->offset);
|
||||||
*dataPtr = value;
|
*dataPtr = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace SHADE
|
||||||
if (memOffset + sizeof(T) > propMemorySize)
|
if (memOffset + sizeof(T) > propMemorySize)
|
||||||
throw std::invalid_argument("Attempted to set an invalid property!");
|
throw std::invalid_argument("Attempted to set an invalid property!");
|
||||||
// Set
|
// Set
|
||||||
(*reinterpret_cast<T*>(propMemory.get() + memOffset)) = value;
|
setPropertyUnsafe(memOffset, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -81,4 +81,10 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
return const_cast<const T&>(const_cast<SHMaterial*>(this)->GetProperty(memOffset));
|
return const_cast<const T&>(const_cast<SHMaterial*>(this)->GetProperty(memOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void SHMaterial::setPropertyUnsafe(uint32_t memOffset, const T& value)
|
||||||
|
{
|
||||||
|
(*reinterpret_cast<T*>(propMemory.get() + memOffset)) = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue