mirror of
https://github.com/lubosz/overte.git
synced 2025-08-28 03:56:36 +02:00
bringing the tex corrd transform in the Material struct and shaving one ubo
This commit is contained in:
parent
b3112f898a
commit
4210ce46aa
6 changed files with 63 additions and 31 deletions
|
@ -20,15 +20,15 @@ using namespace gpu;
|
|||
Material::Material() :
|
||||
_key(0),
|
||||
_schemaBuffer(),
|
||||
_texMapArrayBuffer(),
|
||||
// _texMapArrayBuffer(),
|
||||
_textureMaps()
|
||||
{
|
||||
// created from nothing: create the Buffer to store the properties
|
||||
Schema schema;
|
||||
_schemaBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema));
|
||||
|
||||
TexMapArraySchema TexMapArraySchema;
|
||||
_texMapArrayBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(TexMapArraySchema), (const gpu::Byte*) &TexMapArraySchema));
|
||||
// TexMapArraySchema TexMapArraySchema;
|
||||
// _texMapArrayBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(TexMapArraySchema), (const gpu::Byte*) &TexMapArraySchema));
|
||||
}
|
||||
|
||||
Material::Material(const Material& material) :
|
||||
|
@ -41,9 +41,9 @@ Material::Material(const Material& material) :
|
|||
_schemaBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema));
|
||||
_schemaBuffer.edit<Schema>() = material._schemaBuffer.get<Schema>();
|
||||
|
||||
TexMapArraySchema texMapArraySchema;
|
||||
_texMapArrayBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(TexMapArraySchema), (const gpu::Byte*) &texMapArraySchema));
|
||||
_texMapArrayBuffer.edit<TexMapArraySchema>() = material._texMapArrayBuffer.get<TexMapArraySchema>();
|
||||
// TexMapArraySchema texMapArraySchema;
|
||||
// _texMapArrayBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(TexMapArraySchema), (const gpu::Byte*) &texMapArraySchema));
|
||||
// _texMapArrayBuffer.edit<TexMapArraySchema>() = material._texMapArrayBuffer.get<TexMapArraySchema>();
|
||||
}
|
||||
|
||||
Material& Material::operator= (const Material& material) {
|
||||
|
@ -60,9 +60,9 @@ Material& Material::operator= (const Material& material) {
|
|||
_schemaBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema));
|
||||
_schemaBuffer.edit<Schema>() = material._schemaBuffer.get<Schema>();
|
||||
|
||||
TexMapArraySchema texMapArraySchema;
|
||||
_texMapArrayBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(TexMapArraySchema), (const gpu::Byte*) &texMapArraySchema));
|
||||
_texMapArrayBuffer.edit<TexMapArraySchema>() = material._texMapArrayBuffer.get<TexMapArraySchema>();
|
||||
// TexMapArraySchema texMapArraySchema;
|
||||
// _texMapArrayBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(TexMapArraySchema), (const gpu::Byte*) &texMapArraySchema));
|
||||
// _texMapArrayBuffer.edit<TexMapArraySchema>() = material._texMapArrayBuffer.get<TexMapArraySchema>();
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
@ -137,17 +137,17 @@ void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textur
|
|||
resetOpacityMap();
|
||||
|
||||
// update the texcoord0 with albedo
|
||||
_texMapArrayBuffer.edit<TexMapArraySchema>()._texcoordTransforms[0] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
|
||||
_schemaBuffer.edit<Schema>()._texcoordTransforms[0] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
|
||||
}
|
||||
|
||||
if (channel == MaterialKey::OCCLUSION_MAP) {
|
||||
_texMapArrayBuffer.edit<TexMapArraySchema>()._texcoordTransforms[1] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
|
||||
_schemaBuffer.edit<Schema>()._texcoordTransforms[1] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
|
||||
}
|
||||
|
||||
if (channel == MaterialKey::LIGHTMAP_MAP) {
|
||||
// update the texcoord1 with lightmap
|
||||
_texMapArrayBuffer.edit<TexMapArraySchema>()._texcoordTransforms[1] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
|
||||
_texMapArrayBuffer.edit<TexMapArraySchema>()._lightmapParams = (textureMap ? glm::vec4(textureMap->getLightmapOffsetScale(), 0.0, 0.0) : glm::vec4(0.0, 1.0, 0.0, 0.0));
|
||||
_schemaBuffer.edit<Schema>()._texcoordTransforms[1] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4());
|
||||
_schemaBuffer.edit<Schema>()._lightmapParams = (textureMap ? glm::vec4(textureMap->getLightmapOffsetScale(), 0.0, 0.0) : glm::vec4(0.0, 1.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||
|
@ -235,6 +235,6 @@ void Material::setTextureTransforms(const Transform& transform) {
|
|||
}
|
||||
}
|
||||
for (int i = 0; i < NUM_TEXCOORD_TRANSFORMS; i++) {
|
||||
_texMapArrayBuffer.edit<TexMapArraySchema>()._texcoordTransforms[i] = transform.getMatrix();
|
||||
_schemaBuffer.edit<Schema>()._texcoordTransforms[i] = transform.getMatrix();
|
||||
}
|
||||
}
|
|
@ -268,6 +268,9 @@ public:
|
|||
|
||||
typedef glm::vec3 Color;
|
||||
|
||||
// Texture Map Array Schema
|
||||
static const int NUM_TEXCOORD_TRANSFORMS{ 2 };
|
||||
|
||||
typedef MaterialKey::MapChannel MapChannel;
|
||||
typedef std::map<MapChannel, TextureMapPointer> TextureMaps;
|
||||
typedef std::bitset<MaterialKey::NUM_MAP_CHANNELS> MapFlags;
|
||||
|
@ -323,6 +326,11 @@ public:
|
|||
|
||||
// for alignment beauty, Material size == Mat4x4
|
||||
|
||||
// Texture Coord Transform Array
|
||||
glm::mat4 _texcoordTransforms[NUM_TEXCOORD_TRANSFORMS];
|
||||
|
||||
glm::vec4 _lightmapParams{ 0.0, 1.0, 0.0, 0.0 };
|
||||
|
||||
Schema() {}
|
||||
};
|
||||
|
||||
|
@ -340,17 +348,6 @@ public:
|
|||
// conversion from legacy material properties to PBR equivalent
|
||||
static float shininessToRoughness(float shininess) { return 1.0f - shininess / 100.0f; }
|
||||
|
||||
// Texture Map Array Schema
|
||||
static const int NUM_TEXCOORD_TRANSFORMS{ 2 };
|
||||
class TexMapArraySchema {
|
||||
public:
|
||||
glm::mat4 _texcoordTransforms[NUM_TEXCOORD_TRANSFORMS];
|
||||
glm::vec4 _lightmapParams{ 0.0, 1.0, 0.0, 0.0 };
|
||||
TexMapArraySchema() {}
|
||||
};
|
||||
|
||||
const UniformBufferView& getTexMapArrayBuffer() const { return _texMapArrayBuffer; }
|
||||
|
||||
int getTextureCount() const { calculateMaterialInfo(); return _textureCount; }
|
||||
size_t getTextureSize() const { calculateMaterialInfo(); return _textureSize; }
|
||||
bool hasTextureInfo() const { return _hasCalculatedTextureInfo; }
|
||||
|
@ -370,7 +367,6 @@ protected:
|
|||
private:
|
||||
mutable MaterialKey _key;
|
||||
mutable UniformBufferView _schemaBuffer;
|
||||
mutable UniformBufferView _texMapArrayBuffer;
|
||||
mutable gpu::TextureTablePointer _textureTable{ std::make_shared<gpu::TextureTable>() };
|
||||
|
||||
TextureMaps _textureMaps;
|
||||
|
|
|
@ -13,6 +13,36 @@
|
|||
|
||||
<@include graphics/ShaderConstants.h@>
|
||||
|
||||
|
||||
const int MAX_TEXCOORDS = 2;
|
||||
|
||||
struct TexMapArray {
|
||||
mat4 _texcoordTransforms0;
|
||||
mat4 _texcoordTransforms1;
|
||||
vec4 _lightmapParams;
|
||||
};
|
||||
|
||||
<@func declareMaterialTexMapArrayBuffer()@>
|
||||
|
||||
//layout(binding=GRAPHICS_BUFFER_TEXMAPARRAY) uniform texMapArrayBuffer {
|
||||
// TexMapArray _texMapArray;
|
||||
//};
|
||||
|
||||
|
||||
<@func evalTexMapArrayTexcoord0(texMapArray, inTexcoord0, outTexcoord0)@>
|
||||
{
|
||||
<$outTexcoord0$> = (<$texMapArray$>._texcoordTransforms0 * vec4(<$inTexcoord0$>.st, 0.0, 1.0)).st;
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func evalTexMapArrayTexcoord1(texMapArray, inTexcoord1, outTexcoord1)@>
|
||||
{
|
||||
<$outTexcoord1$> = (<$texMapArray$>._texcoordTransforms1 * vec4(<$inTexcoord1$>.st, 0.0, 1.0)).st;
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@endfunc@>
|
||||
|
||||
// The material values (at least the material key) must be precisely bitwise accurate
|
||||
// to what is provided by the uniform buffer, or the material key has the wrong bits
|
||||
|
||||
|
@ -25,11 +55,15 @@ struct Material {
|
|||
|
||||
layout(binding=GRAPHICS_BUFFER_MATERIAL) uniform materialBuffer {
|
||||
Material _mat;
|
||||
TexMapArray _texMapArray;
|
||||
};
|
||||
|
||||
Material getMaterial() {
|
||||
return _mat;
|
||||
}
|
||||
TexMapArray getTexMapArray() {
|
||||
return _texMapArray;
|
||||
}
|
||||
|
||||
vec3 getMaterialEmissive(Material m) { return m._emissiveOpacity.rgb; }
|
||||
float getMaterialOpacity(Material m) { return m._emissiveOpacity.a; }
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
<@if not MODEL_MATERIAL_TEXTURES_SLH@>
|
||||
<@def MODEL_MATERIAL_TEXTURES_SLH@>
|
||||
|
||||
<@include graphics/ShaderConstants.h@>
|
||||
<!<@include graphics/ShaderConstants.h@>!>
|
||||
<@include graphics/Material.slh@>
|
||||
|
||||
<!
|
||||
<@func declareMaterialTexMapArrayBuffer()@>
|
||||
|
||||
const int MAX_TEXCOORDS = 2;
|
||||
|
@ -45,7 +47,7 @@ TexMapArray getTexMapArray() {
|
|||
<@endfunc@>
|
||||
|
||||
<@endfunc@>
|
||||
|
||||
!>
|
||||
|
||||
<@func declareMaterialTextures(withAlbedo, withRoughness, withNormal, withMetallic, withEmissive, withOcclusion, withScattering)@>
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ void evalMeshDeformer(vec4 inPosition, out vec4 outPosition
|
|||
<@endif@>
|
||||
|
||||
<@if USE_BLENDSHAPE@>
|
||||
if (isBlendshapeEnabled()) {
|
||||
if (bool(isBlendshapeEnabled())) {
|
||||
|
||||
<@if USE_TANGENT@>
|
||||
applyBlendshapeOffset(vertexIndex, inPosition, _deformedPosition, inNormal, _deformedNormal, inTangent, _deformedTangent);
|
||||
|
@ -64,7 +64,7 @@ void evalMeshDeformer(vec4 inPosition, out vec4 outPosition
|
|||
<@endif@>
|
||||
|
||||
<@if USE_SKINNING@>
|
||||
if (isSkinningEnabled()) {
|
||||
if (bool(isSkinningEnabled())) {
|
||||
<@if USE_TANGENT@>
|
||||
skinPositionNormalTangent(inSkinClusterIndex, inSkinClusterWeight, _deformedPosition, _deformedNormal, _deformedTangent, _deformedPosition, _deformedNormal, _deformedTangent);
|
||||
<@else@>
|
||||
|
|
|
@ -404,7 +404,7 @@ void RenderPipelines::bindMaterial(const graphics::MaterialPointer& material, gp
|
|||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
|
||||
batch.setUniformBuffer(gr::Buffer::Material, material->getSchemaBuffer());
|
||||
batch.setUniformBuffer(gr::Buffer::TexMapArray, material->getTexMapArrayBuffer());
|
||||
// batch.setUniformBuffer(gr::Buffer::TexMapArray, material->getTexMapArrayBuffer());
|
||||
|
||||
const auto& materialKey = material->getKey();
|
||||
const auto& textureMaps = material->getTextureMaps();
|
||||
|
|
Loading…
Reference in a new issue