mirror of
https://github.com/lubosz/overte.git
synced 2025-04-13 22:26:57 +02:00
init change, bias triggered via script
This commit is contained in:
parent
b9e2443451
commit
44caf67527
7 changed files with 68 additions and 12 deletions
|
@ -89,6 +89,14 @@ float Light::getShadowsBiasScale() const {
|
|||
return _shadowsBiasScale;
|
||||
}
|
||||
|
||||
void Light::setBiasInput(const float bias) {
|
||||
_biasInput = bias;
|
||||
}
|
||||
|
||||
float Light::getBiasInput() const {
|
||||
return _biasInput;
|
||||
}
|
||||
|
||||
void Light::setColor(const Color& color) {
|
||||
_lightSchemaBuffer.edit().irradiance.color = color;
|
||||
updateLightRadius();
|
||||
|
|
|
@ -112,6 +112,9 @@ public:
|
|||
void setShadowsBiasScale(const float scale);
|
||||
float getShadowsBiasScale() const;
|
||||
|
||||
void setBiasInput(const float bias);
|
||||
float getBiasInput() const;
|
||||
|
||||
void setOrientation(const Quat& orientation);
|
||||
const glm::quat& getOrientation() const { return _transform.getRotation(); }
|
||||
|
||||
|
@ -200,6 +203,7 @@ protected:
|
|||
|
||||
float _shadowsMaxDistance{ 40.0f };
|
||||
float _shadowsBiasScale{ 1.0f };
|
||||
float _biasInput{ 0.3f }; // gives default constant and slope values
|
||||
bool _castShadows{ false };
|
||||
|
||||
void updateLightRadius();
|
||||
|
|
1
libraries/render-utils/src/LightStage.cpp
Normal file → Executable file
1
libraries/render-utils/src/LightStage.cpp
Normal file → Executable file
|
@ -151,6 +151,7 @@ LightStage::Shadow::Shadow(graphics::LightPointer light, unsigned int cascadeCou
|
|||
|
||||
if (light) {
|
||||
setMaxDistance(light->getShadowsMaxDistance());
|
||||
setBiasInput(light->getBiasInput());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
3
libraries/render-utils/src/LightStage.h
Normal file → Executable file
3
libraries/render-utils/src/LightStage.h
Normal file → Executable file
|
@ -92,6 +92,8 @@ public:
|
|||
float getMaxDistance() const { return _maxDistance; }
|
||||
void setMaxDistance(float value);
|
||||
|
||||
void setBiasInput(float value) { _biasInput = value; }
|
||||
|
||||
const graphics::LightPointer& getLight() const { return _light; }
|
||||
|
||||
gpu::TexturePointer map;
|
||||
|
@ -110,6 +112,7 @@ public:
|
|||
|
||||
graphics::LightPointer _light;
|
||||
float _maxDistance{ 0.0f };
|
||||
float _biasInput;
|
||||
Cascades _cascades;
|
||||
|
||||
UniformBufferView _schemaBuffer = nullptr;
|
||||
|
|
52
libraries/render-utils/src/RenderShadowTask.cpp
Normal file → Executable file
52
libraries/render-utils/src/RenderShadowTask.cpp
Normal file → Executable file
|
@ -56,7 +56,6 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende
|
|||
auto fadeEffect = DependencyManager::get<FadeEffect>();
|
||||
initZPassPipelines(*shapePlumber, state, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter());
|
||||
}
|
||||
|
||||
const auto setupOutput = task.addJob<RenderShadowSetup>("ShadowSetup", input);
|
||||
const auto queryResolution = setupOutput.getN<RenderShadowSetup::Output>(1);
|
||||
const auto shadowFrame = setupOutput.getN<RenderShadowSetup::Output>(3);
|
||||
|
@ -318,15 +317,43 @@ RenderShadowSetup::RenderShadowSetup() :
|
|||
}
|
||||
|
||||
void RenderShadowSetup::configure(const Config& configuration) {
|
||||
setConstantBias(0, configuration.constantBias0);
|
||||
setSlopeBias(0, configuration.slopeBias0);
|
||||
#if SHADOW_CASCADE_MAX_COUNT>1
|
||||
setConstantBias(1, configuration.constantBias1);
|
||||
setSlopeBias(1, configuration.slopeBias1);
|
||||
setConstantBias(2, configuration.constantBias2);
|
||||
setSlopeBias(2, configuration.slopeBias2);
|
||||
setConstantBias(3, configuration.constantBias3);
|
||||
setSlopeBias(3, configuration.slopeBias3);
|
||||
|
||||
// change shadow map based on distinct constant and slope values
|
||||
float constant0 = configuration.constantBias0;
|
||||
float constant1 = configuration.constantBias1;
|
||||
float constant2 = configuration.constantBias2;
|
||||
float constant3 = configuration.constantBias3;
|
||||
float slope0 = configuration.slopeBias0;
|
||||
float slope1 = configuration.slopeBias1;
|
||||
float slope2 = configuration.slopeBias2;
|
||||
float slope3 = configuration.slopeBias3;
|
||||
|
||||
// based on external bias input
|
||||
if (prevBiasInput != configuration.biasInput) {
|
||||
prevBiasInput = configuration.biasInput;
|
||||
_biasInput = configuration.biasInput;
|
||||
|
||||
constant0 = (cacasdeDepths[0] / resolution) * _biasInput;
|
||||
constant1 = (cacasdeDepths[1] / resolution) * _biasInput;
|
||||
constant2 = (cacasdeDepths[2] / resolution) * _biasInput * 1.1f;
|
||||
constant3 = (cacasdeDepths[3] / resolution) * _biasInput * 1.3f;
|
||||
slope0 = constant0 * 2.7f;
|
||||
slope1 = constant1 * 3.0f;
|
||||
slope2 = constant2 * 3.7f;
|
||||
slope3 = constant3 * 3.3f;
|
||||
}
|
||||
|
||||
setConstantBias(0, constant0);
|
||||
setSlopeBias(0, slope0);
|
||||
|
||||
#if SHADOW_CASCADE_MAX_COUNT > 1
|
||||
setConstantBias(1, constant1);
|
||||
setConstantBias(2, constant2);
|
||||
setConstantBias(3, constant3);
|
||||
|
||||
setSlopeBias(1, slope1);
|
||||
setSlopeBias(2, slope2);
|
||||
setSlopeBias(3, slope3);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -368,7 +395,7 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c
|
|||
if (!_globalShadowObject) {
|
||||
_globalShadowObject = std::make_shared<LightStage::Shadow>(currentKeyLight, SHADOW_CASCADE_COUNT);
|
||||
}
|
||||
|
||||
resolution = _globalShadowObject->MAP_SIZE;
|
||||
_globalShadowObject->setLight(currentKeyLight);
|
||||
_globalShadowObject->setKeylightFrustum(args->getViewFrustum(), SHADOW_FRUSTUM_NEAR, SHADOW_FRUSTUM_FAR);
|
||||
|
||||
|
@ -378,6 +405,7 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c
|
|||
|
||||
// Adjust each cascade frustum
|
||||
const auto biasScale = currentKeyLight->getShadowsBiasScale();
|
||||
setBiasInput(currentKeyLight->getBiasInput());
|
||||
for (cascadeIndex = 0; cascadeIndex < _globalShadowObject->getCascadeCount(); ++cascadeIndex) {
|
||||
auto& bias = _bias[cascadeIndex];
|
||||
_globalShadowObject->setKeylightCascadeFrustum(cascadeIndex, args->getViewFrustum(),
|
||||
|
@ -398,6 +426,7 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c
|
|||
auto bottom = glm::dot(farBottomRight, firstCascadeFrustum->getUp());
|
||||
auto near = firstCascadeFrustum->getNearClip();
|
||||
auto far = firstCascadeFrustum->getFarClip();
|
||||
cacasdeDepths[0] = far;
|
||||
|
||||
for (cascadeIndex = 1; cascadeIndex < _globalShadowObject->getCascadeCount(); ++cascadeIndex) {
|
||||
auto& cascadeFrustum = _globalShadowObject->getCascade(cascadeIndex).getFrustum();
|
||||
|
@ -417,6 +446,7 @@ void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, c
|
|||
top = glm::max(top, cascadeTop);
|
||||
near = glm::min(near, cascadeNear);
|
||||
far = glm::max(far, cascadeFar);
|
||||
cacasdeDepths[cascadeIndex] = far;
|
||||
}
|
||||
|
||||
_coarseShadowFrustum->setPosition(firstCascadeFrustum->getPosition());
|
||||
|
|
10
libraries/render-utils/src/RenderShadowTask.h
Normal file → Executable file
10
libraries/render-utils/src/RenderShadowTask.h
Normal file → Executable file
|
@ -87,8 +87,12 @@ class RenderShadowSetupConfig : public render::Job::Config {
|
|||
Q_PROPERTY(float slopeBias1 MEMBER slopeBias1 NOTIFY dirty)
|
||||
Q_PROPERTY(float slopeBias2 MEMBER slopeBias2 NOTIFY dirty)
|
||||
Q_PROPERTY(float slopeBias3 MEMBER slopeBias3 NOTIFY dirty)
|
||||
Q_PROPERTY(float biasInput MEMBER biasInput NOTIFY dirty)
|
||||
|
||||
public:
|
||||
|
||||
float biasInput { 0.3f };
|
||||
|
||||
float constantBias0{ 0.15f };
|
||||
float constantBias1{ 0.15f };
|
||||
float constantBias2{ 0.175f };
|
||||
|
@ -112,6 +116,11 @@ public:
|
|||
RenderShadowSetup();
|
||||
void configure(const Config& configuration);
|
||||
void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
|
||||
|
||||
float _biasInput;
|
||||
float prevBiasInput { _biasInput };
|
||||
int resolution { 1024 };
|
||||
QVector<float> cacasdeDepths = QVector<float>(4);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -127,6 +136,7 @@ private:
|
|||
|
||||
void setConstantBias(int cascadeIndex, float value);
|
||||
void setSlopeBias(int cascadeIndex, float value);
|
||||
void setBiasInput(float input) { _biasInput = input; }
|
||||
};
|
||||
|
||||
class RenderShadowCascadeSetup {
|
||||
|
|
2
libraries/render-utils/src/Shadow.slh
Normal file → Executable file
2
libraries/render-utils/src/Shadow.slh
Normal file → Executable file
|
@ -63,7 +63,7 @@ ShadowSampleOffsets evalShadowFilterOffsets(vec4 position) {
|
|||
coords.y += (index & 2) >> 1;
|
||||
#endif
|
||||
|
||||
// Offset for efficient PCF, see http://http.developer.nvidia.com/GPUGems/gpugems_ch11.html
|
||||
// Offset for efficient PCF, see https://developer.nvidia.com/gpugems/GPUGems/gpugems_ch11.html
|
||||
ivec2 offset = coords & ivec2(1,1);
|
||||
offset.y = (offset.x+offset.y) & 1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue