FIX: AO/Emissive loading fix
This commit is contained in:
@@ -68,9 +68,15 @@ void main() {
|
|||||||
outNorm = vec4(Nw, roughness);
|
outNorm = vec4(Nw, roughness);
|
||||||
outAlbedo = vec4(albedo, metallic);
|
outAlbedo = vec4(albedo, metallic);
|
||||||
// Extra G-buffer: x = AO, yzw = emissive
|
// Extra G-buffer: x = AO, yzw = emissive
|
||||||
|
// extra[0].y = AO strength, extra[0].z = hasAO flag (1 = use AO texture)
|
||||||
|
float hasAO = materialData.extra[0].z;
|
||||||
float aoStrength = clamp(materialData.extra[0].y, 0.0, 1.0);
|
float aoStrength = clamp(materialData.extra[0].y, 0.0, 1.0);
|
||||||
float aoTex = texture(occlusionTex, inUV).r;
|
float aoTex = texture(occlusionTex, inUV).r;
|
||||||
float ao = 1.0 - aoStrength + aoStrength * aoTex;
|
float ao = 1.0;
|
||||||
|
if (hasAO > 0.5)
|
||||||
|
{
|
||||||
|
ao = 1.0 - aoStrength + aoStrength * aoTex;
|
||||||
|
}
|
||||||
vec3 emissiveFactor = materialData.extra[1].rgb;
|
vec3 emissiveFactor = materialData.extra[1].rgb;
|
||||||
vec3 emissiveTex = texture(emissiveTex, inUV).rgb;
|
vec3 emissiveTex = texture(emissiveTex, inUV).rgb;
|
||||||
vec3 emissive = emissiveTex * emissiveFactor;
|
vec3 emissive = emissiveTex * emissiveFactor;
|
||||||
|
|||||||
@@ -70,9 +70,15 @@ void main()
|
|||||||
vec3 diffIBL = (1.0 - metallic) * albedo * sh_eval_irradiance(N);
|
vec3 diffIBL = (1.0 - metallic) * albedo * sh_eval_irradiance(N);
|
||||||
|
|
||||||
// Ambient occlusion from texture + strength (indirect only)
|
// Ambient occlusion from texture + strength (indirect only)
|
||||||
|
// extra[0].y = AO strength, extra[0].z = hasAO flag (1 = use AO texture)
|
||||||
|
float hasAO = materialData.extra[0].z;
|
||||||
float aoStrength = clamp(materialData.extra[0].y, 0.0, 1.0);
|
float aoStrength = clamp(materialData.extra[0].y, 0.0, 1.0);
|
||||||
float aoTex = texture(occlusionTex, inUV).r;
|
float aoTex = texture(occlusionTex, inUV).r;
|
||||||
float ao = 1.0 - aoStrength + aoStrength * aoTex;
|
float ao = 1.0;
|
||||||
|
if (hasAO > 0.5)
|
||||||
|
{
|
||||||
|
ao = 1.0 - aoStrength + aoStrength * aoTex;
|
||||||
|
}
|
||||||
|
|
||||||
// Emissive from texture and factor
|
// Emissive from texture and factor
|
||||||
vec3 emissiveFactor = materialData.extra[1].rgb;
|
vec3 emissiveFactor = materialData.extra[1].rgb;
|
||||||
|
|||||||
@@ -220,8 +220,28 @@ std::shared_ptr<MeshAsset> AssetManager::createMesh(const MeshCreateInfo &info)
|
|||||||
{
|
{
|
||||||
const auto &opt = info.material.options;
|
const auto &opt = info.material.options;
|
||||||
|
|
||||||
// Fallbacks are bound now; real textures will patch in via TextureCache
|
GLTFMetallic_Roughness::MaterialConstants constants = opt.constants;
|
||||||
AllocatedBuffer matBuffer = createMaterialBufferWithConstants(opt.constants);
|
|
||||||
|
if (!opt.occlusionPath.empty())
|
||||||
|
{
|
||||||
|
if (constants.extra[0].y == 0.0f && constants.extra[0].z == 0.0f)
|
||||||
|
{
|
||||||
|
constants.extra[0].y = 1.0f; // AO strength
|
||||||
|
constants.extra[0].z = 1.0f; // hasAO flag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!opt.emissivePath.empty())
|
||||||
|
{
|
||||||
|
if (constants.extra[1].x == 0.0f &&
|
||||||
|
constants.extra[1].y == 0.0f &&
|
||||||
|
constants.extra[1].z == 0.0f)
|
||||||
|
{
|
||||||
|
constants.extra[1] = glm::vec4(1.0f, 1.0f, 1.0f, constants.extra[1].w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AllocatedBuffer matBuffer = createMaterialBufferWithConstants(constants);
|
||||||
|
|
||||||
GLTFMetallic_Roughness::MaterialResources res{};
|
GLTFMetallic_Roughness::MaterialResources res{};
|
||||||
res.colorImage = _engine->_errorCheckerboardImage;
|
res.colorImage = _engine->_errorCheckerboardImage;
|
||||||
@@ -519,10 +539,6 @@ AllocatedBuffer AssetManager::createMaterialBufferWithConstants(
|
|||||||
{
|
{
|
||||||
matConstants->extra[0].x = 1.0f; // normal scale default
|
matConstants->extra[0].x = 1.0f; // normal scale default
|
||||||
}
|
}
|
||||||
if (matConstants->extra[0].y == 0.0f)
|
|
||||||
{
|
|
||||||
matConstants->extra[0].y = 1.0f;
|
|
||||||
}
|
|
||||||
// Ensure writes are visible on non-coherent memory
|
// Ensure writes are visible on non-coherent memory
|
||||||
vmaFlushAllocation(_engine->_deviceManager->allocator(), matBuffer.allocation, 0,
|
vmaFlushAllocation(_engine->_deviceManager->allocator(), matBuffer.allocation, 0,
|
||||||
sizeof(GLTFMetallic_Roughness::MaterialConstants));
|
sizeof(GLTFMetallic_Roughness::MaterialConstants));
|
||||||
|
|||||||
@@ -91,12 +91,12 @@ void GeometryPass::register_graph(RenderGraph *graph,
|
|||||||
builder.write_color(gbufferPosition, true, clear);
|
builder.write_color(gbufferPosition, true, clear);
|
||||||
builder.write_color(gbufferNormal, true, clear);
|
builder.write_color(gbufferNormal, true, clear);
|
||||||
builder.write_color(gbufferAlbedo, true, clear);
|
builder.write_color(gbufferAlbedo, true, clear);
|
||||||
VkClearValue clearExtra{};
|
|
||||||
clearExtra.color = {{1.f, 0.f, 0.f, 0.f}}; // AO=1, emissive=0
|
|
||||||
builder.write_color(gbufferExtra, true, clearExtra);
|
|
||||||
VkClearValue clearID{};
|
VkClearValue clearID{};
|
||||||
clearID.color.uint32[0] = 0u;
|
clearID.color.uint32[0] = 0u;
|
||||||
builder.write_color(idHandle, true, clearID);
|
builder.write_color(idHandle, true, clearID);
|
||||||
|
VkClearValue clearExtra{};
|
||||||
|
clearExtra.color = {{1.f, 0.f, 0.f, 0.f}}; // AO=1, emissive=0
|
||||||
|
builder.write_color(gbufferExtra, true, clearExtra);
|
||||||
|
|
||||||
// Reverse-Z: clear depth to 0.0
|
// Reverse-Z: clear depth to 0.0
|
||||||
VkClearValue depthClear{};
|
VkClearValue depthClear{};
|
||||||
|
|||||||
@@ -389,12 +389,35 @@ std::optional<std::shared_ptr<LoadedGLTF> > loadGltf(VulkanEngine *engine,
|
|||||||
constants.metal_rough_factors.y = mat.pbrData.roughnessFactor;
|
constants.metal_rough_factors.y = mat.pbrData.roughnessFactor;
|
||||||
// extra[0].x: normalScale (default 1.0)
|
// extra[0].x: normalScale (default 1.0)
|
||||||
constants.extra[0].x = 1.0f;
|
constants.extra[0].x = 1.0f;
|
||||||
// extra[0].y: occlusionStrength (0..1, default 1.0)
|
// extra[0].y: occlusionStrength (0..1)
|
||||||
constants.extra[0].y = mat.occlusionTexture.has_value() ? mat.occlusionTexture->strength : 1.0f;
|
// extra[0].z: hasAO flag (1.0 if an occlusionTexture is present, 0.0 otherwise)
|
||||||
|
if (mat.occlusionTexture.has_value())
|
||||||
|
{
|
||||||
|
constants.extra[0].y = mat.occlusionTexture->strength;
|
||||||
|
constants.extra[0].z = 1.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
constants.extra[0].y = 0.0f;
|
||||||
|
constants.extra[0].z = 0.0f;
|
||||||
|
}
|
||||||
// extra[1].rgb: emissiveFactor
|
// extra[1].rgb: emissiveFactor
|
||||||
constants.extra[1].x = mat.emissiveFactor[0];
|
constants.extra[1].x = mat.emissiveFactor[0];
|
||||||
constants.extra[1].y = mat.emissiveFactor[1];
|
constants.extra[1].y = mat.emissiveFactor[1];
|
||||||
constants.extra[1].z = mat.emissiveFactor[2];
|
constants.extra[1].z = mat.emissiveFactor[2];
|
||||||
|
// If an emissive texture is present but the factor is left at 0,
|
||||||
|
// default to white so the texture is visible (common authoring pattern).
|
||||||
|
if (mat.emissiveTexture.has_value())
|
||||||
|
{
|
||||||
|
if (constants.extra[1].x == 0.0f &&
|
||||||
|
constants.extra[1].y == 0.0f &&
|
||||||
|
constants.extra[1].z == 0.0f)
|
||||||
|
{
|
||||||
|
constants.extra[1].x = 1.0f;
|
||||||
|
constants.extra[1].y = 1.0f;
|
||||||
|
constants.extra[1].z = 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
// extra[2].x: alphaCutoff for MASK materials (>0 enables alpha test)
|
// extra[2].x: alphaCutoff for MASK materials (>0 enables alpha test)
|
||||||
constants.extra[2].x = 0.0f;
|
constants.extra[2].x = 0.0f;
|
||||||
if (mat.alphaMode == fastgltf::AlphaMode::Mask)
|
if (mat.alphaMode == fastgltf::AlphaMode::Mask)
|
||||||
|
|||||||
Reference in New Issue
Block a user