Minor refactor of lightprobe related code
This commit is contained in:
parent
8717076d96
commit
04195e8331
4 changed files with 71 additions and 81 deletions
|
|
@ -1122,6 +1122,7 @@ set (PCH_SOURCES
|
|||
common/rendering/hwrenderer/data/hw_collision.cpp
|
||||
common/rendering/hwrenderer/data/hw_levelmesh.cpp
|
||||
common/rendering/hwrenderer/data/hw_meshbuilder.cpp
|
||||
common/rendering/hwrenderer/data/hw_lightprobe.cpp
|
||||
common/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp
|
||||
common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp
|
||||
common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp
|
||||
|
|
|
|||
52
src/common/rendering/hwrenderer/data/hw_lightprobe.cpp
Normal file
52
src/common/rendering/hwrenderer/data/hw_lightprobe.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include "hw_lightprobe.h"
|
||||
|
||||
void LightProbeIncrementalBuilder::Step(const TArray<LightProbe>& probes, std::function<void(const LightProbe&, TArray<uint16_t>&, TArray<uint16_t>&)> renderScene, std::function<void(TArray<uint16_t>&&, TArray<uint16_t>&&)> uploadEnv)
|
||||
{
|
||||
if (lastIndex >= probes.size())
|
||||
{
|
||||
lastIndex = 0;
|
||||
|
||||
if (!probes.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TArray<uint16_t> irradianceMap;
|
||||
TArray<uint16_t> prefilterMap;
|
||||
|
||||
renderScene(probes[lastIndex++], irradianceMap, prefilterMap);
|
||||
++collected;
|
||||
|
||||
this->irradianceMaps.Append(irradianceMap);
|
||||
this->prefilterMaps.Append(prefilterMap);
|
||||
|
||||
if (lastIndex >= probes.size())
|
||||
{
|
||||
if (collected == probes.size())
|
||||
{
|
||||
uploadEnv(std::move(this->irradianceMaps), std::move(this->prefilterMaps));
|
||||
}
|
||||
this->irradianceMaps.Clear();
|
||||
this->prefilterMaps.Clear();
|
||||
collected = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void LightProbeIncrementalBuilder::Full(const TArray<LightProbe>& probes, std::function<void(const LightProbe&, TArray<uint16_t>&, TArray<uint16_t>&)> renderScene, std::function<void(TArray<uint16_t>&&, TArray<uint16_t>&&)> uploadEnv)
|
||||
{
|
||||
if (lastIndex >= probes.size())
|
||||
{
|
||||
lastIndex = 0;
|
||||
|
||||
if (!probes.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (lastIndex < probes.size())
|
||||
{
|
||||
Step(probes, renderScene, uploadEnv);
|
||||
}
|
||||
}
|
||||
|
|
@ -404,56 +404,42 @@ sector_t* RenderView(player_t* player)
|
|||
|
||||
if (gl_lightprobe)
|
||||
{
|
||||
|
||||
// Render the light probes if not found in a lump
|
||||
// To do: we need light probe actors
|
||||
|
||||
AActor* lightprobe = level.GetThinkerIterator<AActor>(NAME_LightProbe, STAT_DEFAULT).Next();
|
||||
AActor* lightprobe = level.GetThinkerIterator<AActor>(NAME_LightProbe, STAT_INFO).Next();
|
||||
if (lightprobe)
|
||||
{
|
||||
/*TArray<uint16_t> irradianceMap;
|
||||
TArray<uint16_t> prefilteredMap;
|
||||
auto renderEnvMap = [&](const LightProbe& probe, TArray<uint16_t>& irradianceMap, TArray<uint16_t>& prefilteredMap) {
|
||||
lightprobe->SetOrigin(DVector3(probe.position), false); // crime against nature
|
||||
|
||||
screen->RenderEnvironmentMap([=](IntRect& bounds, int side)
|
||||
{
|
||||
// The renderer interpolates camera in its own mechanism that has to be disabled when moving around the single probe
|
||||
bool noInterpolate = r_NoInterpolate;
|
||||
r_NoInterpolate = true;
|
||||
|
||||
screen->RenderEnvironmentMap([&](IntRect& bounds, int side) {
|
||||
FRenderViewpoint probevp;
|
||||
RenderViewpoint(probevp, lightprobe, &bounds, 90.0, 1.0f, 1.0f, false, false, side);
|
||||
}, irradianceMap, prefilteredMap);
|
||||
|
||||
screen->UploadEnvironmentMaps(1, std::move(irradianceMap), std::move(prefilteredMap));*/
|
||||
r_NoInterpolate = noInterpolate;
|
||||
};
|
||||
|
||||
auto renderEnvMap = [&](const LightProbe& probe, TArray<uint16_t>& irradianceMap, TArray<uint16_t>& prefilteredMap)
|
||||
{
|
||||
auto oldPos = lightprobe->Pos();
|
||||
|
||||
lightprobe->SetOrigin(DVector3(probe.position), false); // crime against nature
|
||||
lightprobe->ClearInterpolation();
|
||||
|
||||
r_NoInterpolate = true;
|
||||
|
||||
// Printf("%p | %f %f %f\n", &probe, probe.position.X, probe.position.Y, probe.position.Z);
|
||||
|
||||
screen->RenderEnvironmentMap([&](IntRect& bounds, int side)
|
||||
{
|
||||
FRenderViewpoint probevp;
|
||||
RenderViewpoint(probevp, lightprobe, &bounds, 90.0, 1.0f, 1.0f, false, false, side);
|
||||
}, irradianceMap, prefilteredMap);
|
||||
|
||||
r_NoInterpolate = false;
|
||||
};
|
||||
auto renderEnvScreen = [&](TArray<uint16_t>&& irradianceMaps, TArray<uint16_t>&& prefilteredMaps) {
|
||||
screen->UploadEnvironmentMaps(level.lightProbes.size(), std::move(irradianceMaps), std::move(prefilteredMaps));
|
||||
};
|
||||
|
||||
lightProbeBuilder.Step(
|
||||
level.lightProbes,
|
||||
renderEnvMap,
|
||||
[&](TArray<uint16_t>&& irradianceMaps, TArray<uint16_t>&& prefilteredMaps) {
|
||||
screen->UploadEnvironmentMaps(level.lightProbes.size(), std::move(irradianceMaps), std::move(prefilteredMaps));
|
||||
}
|
||||
renderEnvScreen
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Printf("Warning: spawning LightProbe\n");
|
||||
Spawn(&level, NAME_LightProbe);
|
||||
auto probe = Spawn(&level, NAME_LightProbe);
|
||||
probe->ChangeStatNum(STAT_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -479,57 +465,6 @@ sector_t* RenderView(player_t* player)
|
|||
return retsec;
|
||||
}
|
||||
|
||||
void LightProbeIncrementalBuilder::Step(const TArray<LightProbe>& probes, std::function<void(const LightProbe&, TArray<uint16_t>&, TArray<uint16_t>&)> renderScene, std::function<void(TArray<uint16_t>&&, TArray<uint16_t>&&)> uploadEnv)
|
||||
{
|
||||
if (lastIndex >= probes.size())
|
||||
{
|
||||
lastIndex = 0;
|
||||
|
||||
if (!probes.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TArray<uint16_t> irradianceMap;
|
||||
TArray<uint16_t> prefilterMap;
|
||||
|
||||
renderScene(probes[lastIndex++], irradianceMap, prefilterMap);
|
||||
++collected;
|
||||
|
||||
this->irradianceMaps.Append(irradianceMap);
|
||||
this->prefilterMaps.Append(prefilterMap);
|
||||
|
||||
if (lastIndex >= probes.size())
|
||||
{
|
||||
if (collected == probes.size())
|
||||
{
|
||||
uploadEnv(std::move(this->irradianceMaps), std::move(this->prefilterMaps));
|
||||
}
|
||||
this->irradianceMaps.Clear();
|
||||
this->prefilterMaps.Clear();
|
||||
collected = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void LightProbeIncrementalBuilder::Full(const TArray<LightProbe>& probes, std::function<void(const LightProbe&, TArray<uint16_t>&, TArray<uint16_t>&)> renderScene, std::function<void(TArray<uint16_t>&&, TArray<uint16_t>&&)> uploadEnv)
|
||||
{
|
||||
if (lastIndex >= probes.size())
|
||||
{
|
||||
lastIndex = 0;
|
||||
|
||||
if (!probes.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (lastIndex < probes.size())
|
||||
{
|
||||
Step(probes, renderScene, uploadEnv);
|
||||
}
|
||||
}
|
||||
|
||||
ADD_STAT(lightprobes)
|
||||
{
|
||||
FString out;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
class LightProbe : Actor
|
||||
{
|
||||
// note: thinker is set to STAT_INFO
|
||||
|
||||
Default
|
||||
{
|
||||
+NOINTERACTION
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue