Implementing switch for image based lighting

This commit is contained in:
2025-07-12 15:50:04 +02:00
parent 106dfe0423
commit d81ea5f8e5
6 changed files with 44 additions and 33 deletions
+6 -4
View File
@@ -345,9 +345,11 @@ struct CookTorrance : IBRDF
float3 k_s = F;
float3 k_d = 1 - k_s;
k_d *= 1 - metallic;
float3 diffuse = baseColor;
float3 specular = 0;
#ifdef IMAGE_BASED_LIGHTING
float3 irradiance = pLightEnv.irradianceMap.SampleLevel(pLightEnv.irradianceSampler, normal, 4).rgb;
float3 diffuse = irradiance * baseColor;
diffuse *= irradiance;
float3 r = reflect(-viewDir_WS, normal);
@@ -355,8 +357,8 @@ struct CookTorrance : IBRDF
float3 prefilteredColor = pLightEnv.prefilteredMap.SampleLevel(pLightEnv.irradianceSampler, r, roughness * MAX_REFLECTION_LOD).xyz;
float2 envBRDF = pLightEnv.brdfLUT.Sample(pLightEnv.lutSampler, float2(max(dot(normal, viewDir_WS), 0), roughness)).rg;
float3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
#endif
return (k_d * diffuse + specular) * ambientOcclusion;
}
float getAlpha()
-1
View File
@@ -1,5 +1,4 @@
#include "PlayView.h"
#include "Component/Mesh.h"
#include "Graphics/Enums.h"
#include "MinimalEngine.h"
#include "Window/Window.h"
@@ -12,6 +12,7 @@
#include "Material/MaterialInstance.h"
#include "Math/Matrix.h"
#include "Math/Vector.h"
#include "MinimalEngine.h"
using namespace Seele;
@@ -148,6 +149,7 @@ void BasePass::render() {
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
permutation.setDepthCulling(true); // always use the culling info
permutation.setPositionOnly(false);
permutation.setImageBasedLighting(getGlobals().useImagebasedLighting);
// Base Rendering
for (VertexData* vertexData : VertexData::getList()) {
transparentData.addAll(vertexData->getTransparentData());
+34 -26
View File
@@ -59,32 +59,38 @@ void ShaderCompiler::compile() {
if (pass.useMaterial) {
for (const auto& [matName, mat] : materials) {
for (int y = 0; y < 2; y++) {
work.add([=, this]() {
ShaderPermutation permutation = getTemplate(name);
permutation.setPositionOnly(false);
permutation.setDepthCulling(y);
permutation.setVertexData(vd->getTypeName());
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
permutation.setMaterial(mat->getName(), mat->getProfile());
createShaders(permutation, std::move(layout), name);
});
for (int z = 0; z < 2; ++z) {
work.add([=, this]() {
ShaderPermutation permutation = getTemplate(name);
permutation.setPositionOnly(false);
permutation.setDepthCulling(y);
permutation.setImageBasedLighting(z);
permutation.setVertexData(vd->getTypeName());
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
permutation.setMaterial(mat->getName(), mat->getProfile());
createShaders(permutation, std::move(layout), name);
});
}
}
}
} else {
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
work.add([=, this]() {
ShaderPermutation permutation = getTemplate(name);
permutation.setPositionOnly(x);
permutation.setDepthCulling(y);
permutation.setVertexData(vd->getTypeName());
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
createShaders(permutation, std::move(layout), name);
});
for (int z = 0; z < 2; z++) {
work.add([=, this]() {
ShaderPermutation permutation = getTemplate(name);
permutation.setPositionOnly(x);
permutation.setDepthCulling(y);
permutation.setImageBasedLighting(z);
permutation.setVertexData(vd->getTypeName());
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
createShaders(permutation, std::move(layout), name);
});
}
}
}
}
@@ -109,7 +115,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
if (std::strlen(permutation.materialName) > 0) {
createInfo.modules.add(permutation.materialName);
createInfo.defines["MATERIAL_FILE_NAME"] = permutation.materialName;
//createInfo.typeParameter.add({"IBRDF", "Phong"});
// createInfo.typeParameter.add({"IBRDF", "Phong"});
}
if (permutation.positionOnly) {
createInfo.defines["POS_ONLY"] = "1";
@@ -120,13 +126,15 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
if (permutation.visibilityPass) {
createInfo.defines["VISIBILITY"] = "1";
}
if (permutation.dumpIntermediates)
{
if (permutation.imageBasedLighting) {
createInfo.defines["IMAGE_BASE_LIGHTING"] = "1";
}
if (permutation.dumpIntermediates) {
createInfo.dumpIntermediate = true;
}
//createInfo.typeParameter.add({Pair<const char*, const char*>("IVertexData", permutation.vertexDataName)});
// createInfo.typeParameter.add({Pair<const char*, const char*>("IVertexData", permutation.vertexDataName)});
createInfo.modules.add(permutation.vertexDataName);
//createInfo.dumpIntermediate = true;
// createInfo.dumpIntermediate = true;
if (permutation.useMeshShading) {
if (permutation.hasTaskShader) {
+2 -1
View File
@@ -102,7 +102,7 @@ struct ShaderPermutation {
uint8 visibilityPass;
uint8 rayTracing;
uint8 dumpIntermediates;
// TODO: lightmapping etc
uint8 imageBasedLighting;
ShaderPermutation() { std::memset(this, 0, sizeof(ShaderPermutation)); }
void setTaskFile(std::string_view name) {
std::memset(taskFile, 0, sizeof(taskFile));
@@ -144,6 +144,7 @@ struct ShaderPermutation {
void setDepthCulling(bool enable) { depthCulling = enable; }
void setVisibilityPass(bool enable) { visibilityPass = enable; }
void setDumpIntermediates(bool enable) { dumpIntermediates = enable; }
void setImageBasedLighting(bool enable) { imageBasedLighting = enable; }
};
// Hashed ShaderPermutation for fast lookup
struct PermutationId {
-1
View File
@@ -18,7 +18,6 @@
#include "Window.h"
#include <GLFW/glfw3.h>
#include <cstring>
#include <numeric>
#include <vulkan/vulkan_core.h>
#define VMA_IMPLEMENTATION