mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 04:37:59 +02:00
clamp and initialize values
This commit is contained in:
parent
f0660ba381
commit
f68bb957ff
4 changed files with 33 additions and 30 deletions
|
@ -112,7 +112,7 @@ public:
|
||||||
void setShadowsBiasScale(const float scale);
|
void setShadowsBiasScale(const float scale);
|
||||||
float getShadowsBiasScale() const;
|
float getShadowsBiasScale() const;
|
||||||
|
|
||||||
void setBiasInput(const float bias);
|
void setBiasInput(float bias);
|
||||||
float getBiasInput() const;
|
float getBiasInput() const;
|
||||||
|
|
||||||
void setOrientation(const Quat& orientation);
|
void setOrientation(const Quat& orientation);
|
||||||
|
@ -203,7 +203,7 @@ protected:
|
||||||
|
|
||||||
float _shadowsMaxDistance{ 40.0f };
|
float _shadowsMaxDistance{ 40.0f };
|
||||||
float _shadowsBiasScale{ 1.0f };
|
float _shadowsBiasScale{ 1.0f };
|
||||||
float _biasInput{ 0.23f }; // gives default constant and slope values
|
float _biasInput{ 0.23f }; // roughly gives default constant and slope values
|
||||||
bool _castShadows{ false };
|
bool _castShadows{ false };
|
||||||
|
|
||||||
void updateLightRadius();
|
void updateLightRadius();
|
||||||
|
|
|
@ -112,7 +112,7 @@ public:
|
||||||
|
|
||||||
graphics::LightPointer _light;
|
graphics::LightPointer _light;
|
||||||
float _maxDistance{ 0.0f };
|
float _maxDistance{ 0.0f };
|
||||||
float _biasInput;
|
float _biasInput{ 0.23f };
|
||||||
Cascades _cascades;
|
Cascades _cascades;
|
||||||
|
|
||||||
UniformBufferView _schemaBuffer = nullptr;
|
UniformBufferView _schemaBuffer = nullptr;
|
||||||
|
|
|
@ -333,26 +333,28 @@ void RenderShadowSetup::configure(const Config& configuration) {
|
||||||
_biasInput = configuration.biasInput;
|
_biasInput = configuration.biasInput;
|
||||||
_globalMaxDistance = configuration.globalMaxDistance;
|
_globalMaxDistance = configuration.globalMaxDistance;
|
||||||
|
|
||||||
// bias is relative to resolution
|
// the bias is relative to resolution
|
||||||
int resolutionScale = 1024 / resolution;
|
// to remain consistant with the constant and slope bias values, the biasInput
|
||||||
|
// value is in the 0.0 - 1.0 range but needs to be scaled up for further calculations
|
||||||
|
int resolutionScale = DEFAULT_RESOLUTION / resolution;
|
||||||
_biasInput *= (100.0f / resolutionScale);
|
_biasInput *= (100.0f / resolutionScale);
|
||||||
float furtherScale = 1.0f;
|
float scaleFactor = 1.0f;
|
||||||
|
|
||||||
furtherScale = cacasdeDistances[0] / cacasdeDistances[5];
|
scaleFactor = _biasInput * (cacasdeDistances[0] / glm::clamp(cacasdeDistances[5], 0.0001f, FLT_MAX)) / (float)resolution;
|
||||||
constant0 = (cacasdeDistances[1] / resolution) * _biasInput * furtherScale;
|
constant0 = cacasdeDistances[1] * scaleFactor;
|
||||||
constant1 = (cacasdeDistances[1] / resolution) * _biasInput * furtherScale;
|
constant1 = cacasdeDistances[1] * scaleFactor;
|
||||||
slope0 = (cacasdeDistances[1] / resolution) * _biasInput * furtherScale * 2.5f;
|
slope0 = cacasdeDistances[1] * scaleFactor * 2.5f;
|
||||||
slope1 = (cacasdeDistances[1] / resolution) * _biasInput * furtherScale * 2.75f;
|
slope1 = cacasdeDistances[1] * scaleFactor * 2.75f;
|
||||||
|
|
||||||
furtherScale = cacasdeDistances[0] / cacasdeDistances[6];
|
scaleFactor = _biasInput * (cacasdeDistances[0] / glm::clamp(cacasdeDistances[6], 0.0001f, FLT_MAX)) / (float)resolution;
|
||||||
constant2 = (cacasdeDistances[2] / resolution) * _biasInput * furtherScale;
|
constant2 = cacasdeDistances[2] * scaleFactor;
|
||||||
slope2 = (cacasdeDistances[2] / resolution) * _biasInput * furtherScale * 3.75f;
|
slope2 = cacasdeDistances[2] * scaleFactor * 3.75f;
|
||||||
|
|
||||||
furtherScale = cacasdeDistances[0] / cacasdeDistances[7];
|
scaleFactor = _biasInput * (cacasdeDistances[0] / glm::clamp(cacasdeDistances[7], 0.0001f, FLT_MAX)) / (float)resolution;
|
||||||
constant3 = (cacasdeDistances[3] / resolution) * _biasInput * furtherScale;
|
constant3 = cacasdeDistances[3] * scaleFactor;
|
||||||
slope3 = (cacasdeDistances[3] / resolution) * _biasInput * furtherScale * 3.75f;
|
slope3 = cacasdeDistances[3] * scaleFactor * 3.75f;
|
||||||
}
|
}
|
||||||
|
|
||||||
setConstantBias(0, constant0);
|
setConstantBias(0, constant0);
|
||||||
setSlopeBias(0, slope0);
|
setSlopeBias(0, slope0);
|
||||||
|
|
||||||
|
@ -367,18 +369,14 @@ void RenderShadowSetup::configure(const Config& configuration) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// cap constant and slope at 1 to prevent peter panning
|
// clamp constant and slope at 1 to prevent peter panning
|
||||||
void RenderShadowSetup::setConstantBias(int cascadeIndex, float value) {
|
void RenderShadowSetup::setConstantBias(int cascadeIndex, float value) {
|
||||||
if (value > 1.0f) {
|
value = glm::clamp(value, 0.0f, 1.0f);
|
||||||
value = 1.0f;
|
|
||||||
}
|
|
||||||
_bias[cascadeIndex]._constant = value * value * value * 0.004f;
|
_bias[cascadeIndex]._constant = value * value * value * 0.004f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderShadowSetup::setSlopeBias(int cascadeIndex, float value) {
|
void RenderShadowSetup::setSlopeBias(int cascadeIndex, float value) {
|
||||||
if (value > 1.0f) {
|
value = glm::clamp(value, 0.0f, 1.0f);
|
||||||
value = 1.0f;
|
|
||||||
}
|
|
||||||
_bias[cascadeIndex]._slope = value * value * value * 0.001f;
|
_bias[cascadeIndex]._slope = value * value * value * 0.001f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,9 @@ public:
|
||||||
CullFunctor _cullFunctor;
|
CullFunctor _cullFunctor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const float DEFAULT_BIAS_INPUT = 0.23f;
|
||||||
|
const float DEFAULT_MAX_DISTANCE = 40.0f;
|
||||||
|
|
||||||
class RenderShadowSetupConfig : public render::Job::Config {
|
class RenderShadowSetupConfig : public render::Job::Config {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(float constantBias0 MEMBER constantBias0 NOTIFY dirty)
|
Q_PROPERTY(float constantBias0 MEMBER constantBias0 NOTIFY dirty)
|
||||||
|
@ -89,8 +92,8 @@ class RenderShadowSetupConfig : public render::Job::Config {
|
||||||
Q_PROPERTY(float globalMaxDistance MEMBER globalMaxDistance NOTIFY dirty)
|
Q_PROPERTY(float globalMaxDistance MEMBER globalMaxDistance NOTIFY dirty)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float biasInput{ 0.23f };
|
float biasInput{ DEFAULT_BIAS_INPUT };
|
||||||
float globalMaxDistance{ 40 };
|
float globalMaxDistance{ DEFAULT_MAX_DISTANCE };
|
||||||
|
|
||||||
float constantBias0{ 0.15f };
|
float constantBias0{ 0.15f };
|
||||||
float constantBias1{ 0.15f };
|
float constantBias1{ 0.15f };
|
||||||
|
@ -116,9 +119,9 @@ public:
|
||||||
void configure(const Config& configuration);
|
void configure(const Config& configuration);
|
||||||
void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
|
void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
|
||||||
|
|
||||||
float _biasInput;
|
float _biasInput{ DEFAULT_BIAS_INPUT };
|
||||||
float _globalMaxDistance;
|
float _globalMaxDistance{ DEFAULT_MAX_DISTANCE };
|
||||||
int resolution{ 1024 };
|
int resolution{ DEFAULT_RESOLUTION };
|
||||||
QVector<float> cacasdeDistances = QVector<float>(8); // 4 max then 4 min distances
|
QVector<float> cacasdeDistances = QVector<float>(8); // 4 max then 4 min distances
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -129,6 +132,8 @@ private:
|
||||||
float _slope;
|
float _slope;
|
||||||
} _bias[SHADOW_CASCADE_MAX_COUNT];
|
} _bias[SHADOW_CASCADE_MAX_COUNT];
|
||||||
|
|
||||||
|
const int DEFAULT_RESOLUTION = 1024;
|
||||||
|
|
||||||
LightStage::ShadowFrame::Object _globalShadowObject;
|
LightStage::ShadowFrame::Object _globalShadowObject;
|
||||||
LightStage::ShadowFramePointer _shadowFrameCache;
|
LightStage::ShadowFramePointer _shadowFrameCache;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue