Skip to content

Commit 37150b3

Browse files
committed
Fixes an error where Light->Copy was deferring to point light instead of virtual light. This would cause weird and hard to track down errors once the engine made a copy of a VPL and then tried casting the copy to a VPL.
1 parent 0090a6a commit 37150b3

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Examples/ExampleEnv02/Sponza.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class Sponza : public stratus::Application {
310310
mover->light->setIntensity(worldLight->getIntensity() * 10);
311311
const auto worldLightColor = glm::vec3(1.0f, 0.0f, 0.0f);
312312
mover->light->setColor(worldLightColor.r, worldLightColor.g, worldLightColor.b);
313-
((stratus::VirtualPointLight *)mover->light.get())->SetNumShadowSamples(27);
313+
((stratus::VirtualPointLight *)mover->light.get())->SetNumShadowSamples(9);
314314
mover->position = camera->getPosition();
315315
mover->addToScene();
316316
lightMovers.push_back(std::move(mover));
@@ -323,6 +323,7 @@ class Sponza : public stratus::Application {
323323
mover->light->setIntensity(worldLight->getIntensity() * 10);
324324
const auto worldLightColor = glm::vec3(0.0f, 1.0f, 0.0f);
325325
mover->light->setColor(worldLightColor.r, worldLightColor.g, worldLightColor.b);
326+
((stratus::VirtualPointLight *)mover->light.get())->SetNumShadowSamples(9);
326327
mover->position = camera->getPosition();
327328
mover->addToScene();
328329
lightMovers.push_back(std::move(mover));
@@ -335,6 +336,7 @@ class Sponza : public stratus::Application {
335336
mover->light->setIntensity(worldLight->getIntensity() * 10);
336337
const auto worldLightColor = glm::vec3(0.0f, 0.0f, 1.0f);
337338
mover->light->setColor(worldLightColor.r, worldLightColor.g, worldLightColor.b);
339+
((stratus::VirtualPointLight *)mover->light.get())->SetNumShadowSamples(9);
338340
mover->position = camera->getPosition();
339341
mover->addToScene();
340342
lightMovers.push_back(std::move(mover));

Source/StratusLight.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ namespace stratus {
106106
// as a way of simulating bounce lighting
107107
bool _virtualLight = false;
108108

109+
Light(const bool virtualLight)
110+
: _virtualLight(virtualLight) {}
111+
109112
public:
110113
glm::vec3 position = glm::vec3(0.0f);
111-
112-
Light(const bool virtualLight = false)
113-
: _virtualLight(virtualLight) {}
114114

115+
Light() : Light(false) {}
115116
virtual ~Light() = default;
116117

117118
/**
@@ -264,6 +265,12 @@ namespace stratus {
264265
void SetNumShadowSamples(uint32_t samples) { _numShadowSamples = samples; }
265266
uint32_t GetNumShadowSamples() const { return _numShadowSamples; }
266267

268+
// This MUST be done or else the engine makes copies and it will defer
269+
// to PointLight instead of this and then cause horrible strange errors
270+
LightPtr Copy() const override {
271+
return LightPtr(new VirtualPointLight(*this));
272+
}
273+
267274
private:
268275
uint32_t _numShadowSamples = 3;
269276
};

resources/shaders/pbr_vpl_gi.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,15 @@ vec3 performLightingCalculations(vec3 screenColor, vec2 pixelCoords, vec2 texCoo
9494
for (int baseLightIndex = 0 ; baseLightIndex < numActiveVPLs; baseLightIndex += 1) {
9595
// Calculate true light index via lookup into active light table
9696
int lightIndex = activeLightIndicesPerTile[baseTileIndex + baseLightIndex];
97+
if (lightIndex > MAX_TOTAL_VPLS_PER_FRAME) continue;
98+
9799
vec3 lightPosition = lightPositions[lightIndex].xyz;
98100
float distance = length(lightPosition - fragPos);
99101
vec3 lightColor = lightColors[lightIndex].xyz;
100102
if (distance > lightRadii[lightIndex]) continue;
101103
if (length(vplColor) > (length(infiniteLightColor) * 0.25)) break;
102104

103-
int numSamples = 3;//int(lightNumSamples[lightIndex]);
104-
// This solves an error where sometimes numShadowSamples seems to be uninitialized to some huge
105-
// value - must fix
106-
//if (numSamples > 64) continue;
105+
int numSamples = int(lightNumSamples[lightIndex]);
107106
float shadowFactor = 0.0;
108107
if (length(lightPosition - viewPosition) < 135) {
109108
shadowFactor = calculateShadowValue(shadowCubeMaps[lightIndex], lightFarPlanes[lightIndex], fragPos, lightPosition, dot(lightPosition - fragPos, normal), numSamples);

0 commit comments

Comments
 (0)