diff --git a/include/vsg/nodes/Light.h b/include/vsg/nodes/Light.h index a7d4c0d15..6c721892d 100644 --- a/include/vsg/nodes/Light.h +++ b/include/vsg/nodes/Light.h @@ -70,6 +70,7 @@ namespace vsg DirectionalLight(const DirectionalLight& rhs, const CopyOp& copyop = {}); dvec3 direction = dvec3(0.0, 0.0, -1.0); + float angleSubtended = 0.0090f; public: ref_ptr clone(const CopyOp& copyop = {}) const override { return DirectionalLight::create(*this, copyop); } diff --git a/src/vsg/nodes/Light.cpp b/src/vsg/nodes/Light.cpp index 5b2d285c2..8e3b3e149 100644 --- a/src/vsg/nodes/Light.cpp +++ b/src/vsg/nodes/Light.cpp @@ -92,7 +92,8 @@ DirectionalLight::DirectionalLight() DirectionalLight::DirectionalLight(const DirectionalLight& rhs, const CopyOp& copyop) : Inherit(rhs, copyop), - direction(rhs.direction) + direction(rhs.direction), + angleSubtended(rhs.angleSubtended) { } @@ -102,7 +103,8 @@ int DirectionalLight::compare(const Object& rhs_object) const if (result != 0) return result; auto& rhs = static_cast(rhs_object); - return compare_value(direction, rhs.direction); + if ((result = compare_value(direction, rhs.direction)) != 0) return result; + return compare_value(angleSubtended, rhs.angleSubtended); } void DirectionalLight::read(Input& input) @@ -110,6 +112,7 @@ void DirectionalLight::read(Input& input) Light::read(input); input.read("direction", direction); + input.read("angleSubtended", angleSubtended); } void DirectionalLight::write(Output& output) const @@ -117,6 +120,7 @@ void DirectionalLight::write(Output& output) const Light::write(output); output.write("direction", direction); + output.write("angleSubtended", angleSubtended); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/vsg/state/ViewDependentState.cpp b/src/vsg/state/ViewDependentState.cpp index 205641c90..54352ed39 100644 --- a/src/vsg/state/ViewDependentState.cpp +++ b/src/vsg/state/ViewDependentState.cpp @@ -569,7 +569,7 @@ void ViewDependentState::traverse(RecordTraversal& rt) const (*light_itr++).set(static_cast(eye_direction.x), static_cast(eye_direction.y), static_cast(eye_direction.z), 0.0f); uint32_t activeNumShadowMaps = std::min(light->shadowMaps, numShadowMaps - shadowMapIndex); - (*light_itr++).set(static_cast(activeNumShadowMaps), 0.0f, 0.0f, 0.0f); // shadow map setting + (*light_itr++).set(static_cast(activeNumShadowMaps), std::tan(light->angleSubtended / 2), 0.0f, 0.0f); // shadow map setting if (activeNumShadowMaps == 0) continue;