clamp and initialize values

This commit is contained in:
raveenajain 2019-06-24 16:42:38 -07:00
parent f0660ba381
commit f68bb957ff
4 changed files with 33 additions and 30 deletions

View file

@ -112,7 +112,7 @@ public:
void setShadowsBiasScale(const float scale);
float getShadowsBiasScale() const;
void setBiasInput(const float bias);
void setBiasInput(float bias);
float getBiasInput() const;
void setOrientation(const Quat& orientation);
@ -203,7 +203,7 @@ protected:
float _shadowsMaxDistance{ 40.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 };
void updateLightRadius();

View file

@ -112,7 +112,7 @@ public:
graphics::LightPointer _light;
float _maxDistance{ 0.0f };
float _biasInput;
float _biasInput{ 0.23f };
Cascades _cascades;
UniformBufferView _schemaBuffer = nullptr;

View file

@ -333,26 +333,28 @@ void RenderShadowSetup::configure(const Config& configuration) {
_biasInput = configuration.biasInput;
_globalMaxDistance = configuration.globalMaxDistance;
// bias is relative to resolution
int resolutionScale = 1024 / resolution;
// the bias is relative to 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);
float furtherScale = 1.0f;
float scaleFactor = 1.0f;
furtherScale = cacasdeDistances[0] / cacasdeDistances[5];
constant0 = (cacasdeDistances[1] / resolution) * _biasInput * furtherScale;
constant1 = (cacasdeDistances[1] / resolution) * _biasInput * furtherScale;
slope0 = (cacasdeDistances[1] / resolution) * _biasInput * furtherScale * 2.5f;
slope1 = (cacasdeDistances[1] / resolution) * _biasInput * furtherScale * 2.75f;
scaleFactor = _biasInput * (cacasdeDistances[0] / glm::clamp(cacasdeDistances[5], 0.0001f, FLT_MAX)) / (float)resolution;
constant0 = cacasdeDistances[1] * scaleFactor;
constant1 = cacasdeDistances[1] * scaleFactor;
slope0 = cacasdeDistances[1] * scaleFactor * 2.5f;
slope1 = cacasdeDistances[1] * scaleFactor * 2.75f;
furtherScale = cacasdeDistances[0] / cacasdeDistances[6];
constant2 = (cacasdeDistances[2] / resolution) * _biasInput * furtherScale;
slope2 = (cacasdeDistances[2] / resolution) * _biasInput * furtherScale * 3.75f;
scaleFactor = _biasInput * (cacasdeDistances[0] / glm::clamp(cacasdeDistances[6], 0.0001f, FLT_MAX)) / (float)resolution;
constant2 = cacasdeDistances[2] * scaleFactor;
slope2 = cacasdeDistances[2] * scaleFactor * 3.75f;
furtherScale = cacasdeDistances[0] / cacasdeDistances[7];
constant3 = (cacasdeDistances[3] / resolution) * _biasInput * furtherScale;
slope3 = (cacasdeDistances[3] / resolution) * _biasInput * furtherScale * 3.75f;
scaleFactor = _biasInput * (cacasdeDistances[0] / glm::clamp(cacasdeDistances[7], 0.0001f, FLT_MAX)) / (float)resolution;
constant3 = cacasdeDistances[3] * scaleFactor;
slope3 = cacasdeDistances[3] * scaleFactor * 3.75f;
}
setConstantBias(0, constant0);
setSlopeBias(0, slope0);
@ -367,18 +369,14 @@ void RenderShadowSetup::configure(const Config& configuration) {
#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) {
if (value > 1.0f) {
value = 1.0f;
}
value = glm::clamp(value, 0.0f, 1.0f);
_bias[cascadeIndex]._constant = value * value * value * 0.004f;
}
void RenderShadowSetup::setSlopeBias(int cascadeIndex, float value) {
if (value > 1.0f) {
value = 1.0f;
}
value = glm::clamp(value, 0.0f, 1.0f);
_bias[cascadeIndex]._slope = value * value * value * 0.001f;
}

View file

@ -75,6 +75,9 @@ public:
CullFunctor _cullFunctor;
};
const float DEFAULT_BIAS_INPUT = 0.23f;
const float DEFAULT_MAX_DISTANCE = 40.0f;
class RenderShadowSetupConfig : public render::Job::Config {
Q_OBJECT
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)
public:
float biasInput{ 0.23f };
float globalMaxDistance{ 40 };
float biasInput{ DEFAULT_BIAS_INPUT };
float globalMaxDistance{ DEFAULT_MAX_DISTANCE };
float constantBias0{ 0.15f };
float constantBias1{ 0.15f };
@ -116,9 +119,9 @@ public:
void configure(const Config& configuration);
void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
float _biasInput;
float _globalMaxDistance;
int resolution{ 1024 };
float _biasInput{ DEFAULT_BIAS_INPUT };
float _globalMaxDistance{ DEFAULT_MAX_DISTANCE };
int resolution{ DEFAULT_RESOLUTION };
QVector<float> cacasdeDistances = QVector<float>(8); // 4 max then 4 min distances
private:
@ -129,6 +132,8 @@ private:
float _slope;
} _bias[SHADOW_CASCADE_MAX_COUNT];
const int DEFAULT_RESOLUTION = 1024;
LightStage::ShadowFrame::Object _globalShadowObject;
LightStage::ShadowFramePointer _shadowFrameCache;