Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions include/vsg/io/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/core/ref_ptr.h>
#include <vsg/core/type_name.h>
#include <vsg/io/Path.h>
#include <vsg/lighting/ShadowSettings.h>
#include <vsg/maths/box.h>
#include <vsg/maths/mat3.h>
#include <vsg/maths/mat4.h>
Expand Down Expand Up @@ -313,6 +314,20 @@ namespace vsg
return output;
}

/// output stream support for ShadowMapBias
inline std::ostream& operator<<(std::ostream& output, const ShadowMapBias& shadowMapBias)
{
output << shadowMapBias.constantBias << " " << shadowMapBias.slopeBias << " " << shadowMapBias.normalOffset;
return output;
}

/// input stream support for ShadowMapBias
inline std::istream& operator>>(std::istream& input, ShadowMapBias& shadowMapBias)
{
input >> shadowMapBias.constantBias >> shadowMapBias.slopeBias >> shadowMapBias.normalOffset;
return input;
}

/// output stream support for std::vector<T>
template<typename T>
std::ostream& operator<<(std::ostream& output, const std::vector<T>& values)
Expand Down
10 changes: 10 additions & 0 deletions include/vsg/lighting/ShadowSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
namespace vsg
{

struct ShadowMapBias
{
float constantBias = 0.0002f;
float slopeBias = 0.001f;
float normalOffset = 0.005f;
float padding = 0.0f;
};

VSG_value(ShadowMapBiasValue, ShadowMapBias);

class VSG_DECLSPEC ShadowSettings : public Inherit<Object, ShadowSettings>
{
public:
Expand Down
3 changes: 2 additions & 1 deletion include/vsg/state/ViewDependentState.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ namespace vsg

// shadow map hints
double maxShadowDistance = 1e8;
double shadowMapBias = 0.005;
double lambda = 0.5;
ref_ptr<ShadowMapBiasValue> shadowMapBias;
ref_ptr<BufferInfo> shadowMapBiasBufferInfo;

// map of Light's that we wish to override their ShadowSettings,
// assigning shadowSettingsOverride[{}] = shadowSettings will override all Light not otherwise explicitly matched.
Expand Down
7 changes: 5 additions & 2 deletions src/vsg/state/ViewDependentState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ ViewDependentState::ViewDependentState(View* in_view) :
view(in_view)
{
// info("ViewDependentState::ViewDependentState(view = ", view, ")");
shadowMapBias = ShadowMapBiasValue::create();
shadowMapBiasBufferInfo = BufferInfo::create(shadowMapBias);
}

ViewDependentState::~ViewDependentState()
Expand Down Expand Up @@ -294,6 +296,7 @@ void ViewDependentState::init(ResourceRequirements& requirements)
viewportData->properties.dataVariance = DYNAMIC_DATA_TRANSFER_AFTER_RECORD;
viewportDataBufferInfo = BufferInfo::create(viewportData.get());
descriptorConfigurator->assignDescriptor("viewportData", BufferInfoList{viewportDataBufferInfo});
descriptorConfigurator->assignDescriptor("shadowMapBias", BufferInfoList{shadowMapBiasBufferInfo});

// set up ShadowMaps
auto shadowMapDirectSampler = Sampler::create();
Expand Down Expand Up @@ -800,7 +803,7 @@ void ViewDependentState::traverse(RecordTraversal& rt) const

dmat4 shadowMapProjView = camera->projectionMatrix->transform() * camera->viewMatrix->transform();

dmat4 shadowMapTM = scale(0.5, 0.5, 1.0) * translate(1.0, 1.0, shadowMapBias) * shadowMapProjView * inverse_viewMatrix;
dmat4 shadowMapTM = scale(0.5, 0.5, 1.0) * translate(1.0, 1.0, 0.0) * shadowMapProjView * inverse_viewMatrix;

// convert tex gen matrix to float matrix and assign to light data
mat4 m(shadowMapTM);
Expand Down Expand Up @@ -975,7 +978,7 @@ void ViewDependentState::traverse(RecordTraversal& rt) const

dmat4 shadowMapProjView = camera->projectionMatrix->transform() * camera->viewMatrix->transform();

dmat4 shadowMapTM = scale(0.5, 0.5, 1.0 + shadowMapBias) * translate(1.0, 1.0, 0.0) * shadowMapProjView * inverse_viewMatrix;
dmat4 shadowMapTM = scale(0.5, 0.5, 1.0) * translate(1.0, 1.0, 0.0) * shadowMapProjView * inverse_viewMatrix;

// convert tex gen matrix to float matrix and assign to light data
mat4 m(shadowMapTM);
Expand Down
Loading
Loading