Skip to content

Commit e57bc3d

Browse files
committed
Fix the string lights.
1 parent adf461e commit e57bc3d

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

attachments/simple_engine/renderer_rendering.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -695,25 +695,10 @@ void Renderer::Render(const std::vector<Entity*>& entities, CameraComponent* cam
695695

696696
commandBuffers[currentFrame].bindDescriptorSets(vk::PipelineBindPoint::eGraphics, **currentLayout, 0, {*selectedDescriptorSets[currentFrame]}, {});
697697

698-
// Define PBR push constants structure matching the shader
699-
struct PushConstants {
700-
glm::vec4 baseColorFactor;
701-
float metallicFactor;
702-
float roughnessFactor;
703-
int baseColorTextureSet;
704-
int physicalDescriptorTextureSet;
705-
int normalTextureSet;
706-
int occlusionTextureSet;
707-
int emissiveTextureSet;
708-
float alphaMask;
709-
float alphaMaskCutoff;
710-
glm::vec3 emissiveFactor; // Add emissive factor for HDR emissive sources
711-
float emissiveStrength; // KHR_materials_emissive_strength extension
712-
};
713698

714699
// Set PBR material properties using push constants
715700
if (usePBR) {
716-
PushConstants pushConstants{};
701+
MaterialProperties pushConstants{};
717702

718703
// Try to get material properties for this specific entity
719704
if (modelLoader && entity->GetName().find("_Material_") != std::string::npos) {
@@ -758,7 +743,12 @@ void Renderer::Render(const std::vector<Entity*>& entities, CameraComponent* cam
758743
pushConstants.physicalDescriptorTextureSet = 0;
759744
pushConstants.normalTextureSet = 0;
760745
pushConstants.occlusionTextureSet = 0;
761-
pushConstants.emissiveTextureSet = 0;
746+
// For emissive: indicate absence with -1 so shader uses factor-only emissive
747+
int emissiveSet = -1;
748+
if (meshComponent && !meshComponent->GetEmissiveTexturePath().empty()) {
749+
emissiveSet = 0;
750+
}
751+
pushConstants.emissiveTextureSet = emissiveSet;
762752
pushConstants.alphaMask = 0.0f;
763753
pushConstants.alphaMaskCutoff = 0.5f;
764754

@@ -767,7 +757,7 @@ void Renderer::Render(const std::vector<Entity*>& entities, CameraComponent* cam
767757
**currentLayout,
768758
vk::ShaderStageFlagBits::eFragment,
769759
0,
770-
vk::ArrayProxy<const uint8_t>(sizeof(PushConstants), reinterpret_cast<const uint8_t*>(&pushConstants))
760+
vk::ArrayProxy<const uint8_t>(sizeof(MaterialProperties), reinterpret_cast<const uint8_t*>(&pushConstants))
771761
);
772762
}
773763

attachments/simple_engine/renderer_resources.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ bool Renderer::preAllocateEntityResources(Entity* entity) {
13561356
return false;
13571357
}
13581358

1359+
13591360
// 3. Pre-allocate BOTH basic and PBR descriptor sets
13601361
std::string texturePath = meshComponent->GetTexturePath();
13611362
// Fallback: if legacy texturePath is empty, use PBR baseColor texture

attachments/simple_engine/shaders/pbr.slang

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ float4 PSMain(VSOutput input) : SV_TARGET
148148
float metallic = metallicRoughness.x * material.metallicFactor;
149149
float roughness = metallicRoughness.y * material.roughnessFactor;
150150
float ao = occlusionMap.Sample(uv).r;
151-
float3 emissive = emissiveMap.Sample(uv).rgb * material.emissiveFactor * material.emissiveStrength;
151+
float3 emissiveTex = (material.emissiveTextureSet < 0) ? float3(1.0, 1.0, 1.0) : emissiveMap.Sample(uv).rgb;
152+
float3 emissive = emissiveTex * material.emissiveFactor * material.emissiveStrength;
152153

153154
// Calculate normal in tangent space
154155
float3 N = normalize(input.Normal);

0 commit comments

Comments
 (0)