Explorar el Código

Some config additions for the scene

Panagiotis Christopoulos Charitos hace 5 años
padre
commit
62873e3436

+ 4 - 12
anki/scene/CameraNode.cpp

@@ -71,8 +71,6 @@ CameraNode::~CameraNode()
 
 Error CameraNode::init(FrustumType frustumType)
 {
-	constexpr F32 defaultFar = 500.0f;
-
 	// Move component
 	newComponent<MoveComponent>();
 
@@ -91,22 +89,16 @@ Error CameraNode::init(FrustumType frustumType)
 		| FrustumComponentVisibilityTestFlag::ALL_SHADOWS_ENABLED
 		| FrustumComponentVisibilityTestFlag::GENERIC_COMPUTE_JOB_COMPONENTS;
 	frc->setEnabledVisibilityTests(visibilityFlags);
-	if(frustumType == FrustumType::PERSPECTIVE)
-	{
-		frc->setPerspective(0.1f, defaultFar, toRad(45.0f), toRad(45.0f));
-	}
-	else
-	{
-		frc->setOrthographic(0.1f, defaultFar, 5.0f, -5.0f, 5.0f, -5.0f);
-	}
 
 	// Extended frustum for RT
-	if(getSceneGraph().getRayTracedShadowsEnabled())
+	if(getSceneGraph().getConfig().m_rayTracedShadows)
 	{
 		FrustumComponent* rtFrustumComponent = newComponent<FrustumComponent>(this, FrustumType::ORTHOGRAPHIC);
 		rtFrustumComponent->setEnabledVisibilityTests(FrustumComponentVisibilityTestFlag::RAY_TRACING_SHADOWS);
 
-		rtFrustumComponent->setOrthographic(0.1f, defaultFar * 2.0f, defaultFar, -defaultFar, defaultFar, -defaultFar);
+		const F32 dist = getSceneGraph().getConfig().m_rayTracingExtendedFrustumDistance;
+
+		rtFrustumComponent->setOrthographic(0.1f, dist * 2.0f, dist, -dist, dist, -dist);
 	}
 
 	// Feedback component #2

+ 3 - 0
anki/scene/ConfigDefs.h

@@ -3,9 +3,12 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+ANKI_CONFIG_OPTION(scene_octreeMaxDepth, 5, 2, 10, "The max depth of the octree")
 ANKI_CONFIG_OPTION(scene_earlyZDistance, 10.0, 0.0, MAX_F64,
 				   "Objects with distance lower than that will be used in early Z")
 ANKI_CONFIG_OPTION(scene_reflectionProbeEffectiveDistance, 256.0, 1.0, MAX_F64, "How far reflection probes can look")
 ANKI_CONFIG_OPTION(scene_reflectionProbeShadowEffectiveDistance, 32.0, 1.0, MAX_F64,
 				   "How far to render shadows for reflection probes")
 ANKI_CONFIG_OPTION(scene_rayTracedShadows, 0, 0, 1, "Enable or not ray traced shadows. Ignored if RT is not supported")
+ANKI_CONFIG_OPTION(scene_rayTracingExtendedFrustumDistance, 100.0, 10.0, 10000.0,
+				   "Every object that its distance from the camera is bellow that value will take part in ray tracing")

+ 2 - 2
anki/scene/GlobalIlluminationProbeNode.cpp

@@ -119,7 +119,7 @@ Error GlobalIlluminationProbeNode::init()
 		frc->setPerspective(zNear, tempEffectiveDistance, ang, ang);
 		frc->setTransform(m_cubeFaceTransforms[i]);
 		frc->setEnabledVisibilityTests(FrustumComponentVisibilityTestFlag::NONE);
-		frc->setEffectiveShadowDistance(getSceneGraph().getLimits().m_reflectionProbeShadowEffectiveDistance);
+		frc->setEffectiveShadowDistance(getSceneGraph().getConfig().m_reflectionProbeShadowEffectiveDistance);
 	}
 
 	// Spatial component
@@ -156,7 +156,7 @@ void GlobalIlluminationProbeNode::onShapeUpdateOrProbeNeedsRendering()
 			max(effectiveDistance, gic.getAlignedBoundingBoxMax().y() - gic.getAlignedBoundingBoxMin().y());
 		effectiveDistance =
 			max(effectiveDistance, gic.getAlignedBoundingBoxMax().z() - gic.getAlignedBoundingBoxMin().z());
-		effectiveDistance = max(effectiveDistance, getSceneGraph().getLimits().m_reflectionProbeEffectiveDistance);
+		effectiveDistance = max(effectiveDistance, getSceneGraph().getConfig().m_reflectionProbeEffectiveDistance);
 
 		// Update frustum components
 		U count = 0;

+ 2 - 2
anki/scene/ReflectionProbeNode.cpp

@@ -55,7 +55,7 @@ Error ReflectionProbeNode::init(const Vec4& aabbMinLSpace, const Vec4& aabbMaxLS
 	F32 effectiveDistance = aabbMaxLSpace.x() - aabbMinLSpace.x();
 	effectiveDistance = max(effectiveDistance, aabbMaxLSpace.y() - aabbMinLSpace.y());
 	effectiveDistance = max(effectiveDistance, aabbMaxLSpace.z() - aabbMinLSpace.z());
-	effectiveDistance = max(effectiveDistance, getSceneGraph().getLimits().m_reflectionProbeEffectiveDistance);
+	effectiveDistance = max(effectiveDistance, getSceneGraph().getConfig().m_reflectionProbeEffectiveDistance);
 
 	// Move component first
 	newComponent<MoveComponent>();
@@ -91,7 +91,7 @@ Error ReflectionProbeNode::init(const Vec4& aabbMinLSpace, const Vec4& aabbMaxLS
 		frc->setPerspective(zNear, effectiveDistance, ang, ang);
 		frc->setTransform(m_cubeSides[i].m_localTrf);
 		frc->setEnabledVisibilityTests(FrustumComponentVisibilityTestFlag::NONE);
-		frc->setEffectiveShadowDistance(getSceneGraph().getLimits().m_reflectionProbeShadowEffectiveDistance);
+		frc->setEffectiveShadowDistance(getSceneGraph().getConfig().m_reflectionProbeShadowEffectiveDistance);
 	}
 
 	// Spatial component

+ 8 - 7
anki/scene/SceneGraph.cpp

@@ -68,16 +68,19 @@ Error SceneGraph::init(AllocAlignedCallback allocCb, void* allocCbData, ThreadHi
 	m_alloc = SceneAllocator<U8>(allocCb, allocCbData);
 	m_frameAlloc = SceneFrameAllocator<U8>(allocCb, allocCbData, 1 * 1024 * 1024);
 
-	// Limits
-	m_limits.m_earlyZDistance = config.getNumberF32("scene_earlyZDistance");
-	m_limits.m_reflectionProbeEffectiveDistance = config.getNumberF32("scene_reflectionProbeEffectiveDistance");
-	m_limits.m_reflectionProbeShadowEffectiveDistance =
+	// Limits & stuff
+	m_config.m_earlyZDistance = config.getNumberF32("scene_earlyZDistance");
+	m_config.m_reflectionProbeEffectiveDistance = config.getNumberF32("scene_reflectionProbeEffectiveDistance");
+	m_config.m_reflectionProbeShadowEffectiveDistance =
 		config.getNumberF32("scene_reflectionProbeShadowEffectiveDistance");
+	m_config.m_rayTracedShadows =
+		config.getBool("scene_rayTracedShadows") && m_gr->getDeviceCapabilities().m_rayTracingEnabled;
+	m_config.m_rayTracingExtendedFrustumDistance = config.getNumberF32("scene_rayTracingExtendedFrustumDistance");
 
 	ANKI_CHECK(m_events.init(this));
 
 	m_octree = m_alloc.newInstance<Octree>(m_alloc);
-	m_octree->init(m_sceneMin, m_sceneMax, 5); // TODO
+	m_octree->init(m_sceneMin, m_sceneMax, config.getNumberU32("scene_octreeMaxDepth"));
 
 	// Init the default main camera
 	ANKI_CHECK(newSceneNode<PerspectiveCameraNode>("mainCamera", m_defaultMainCam));
@@ -89,8 +92,6 @@ Error SceneGraph::init(AllocAlignedCallback allocCb, void* allocCbData, ThreadHi
 	PhysicsDebugNode* pnode;
 	ANKI_CHECK(newSceneNode<PhysicsDebugNode>("_physicsDebugNode", pnode));
 
-	m_enableRtShadows = config.getBool("scene_rayTracedShadows") && m_gr->getDeviceCapabilities().m_rayTracingEnabled;
-
 	return Error::NONE;
 }
 

+ 6 - 11
anki/scene/SceneGraph.h

@@ -40,12 +40,14 @@ public:
 };
 
 /// SceneGraph limits.
-class SceneGraphLimits
+class SceneGraphConfig
 {
 public:
 	F32 m_earlyZDistance = -1.0f; ///< Objects with distance lower than that will be used in early Z.
 	F32 m_reflectionProbeEffectiveDistance = -1.0f; ///< How far reflection probes can look.
 	F32 m_reflectionProbeShadowEffectiveDistance = -1.0f; ///< How far to render shadows for reflection probes.
+	Bool m_rayTracedShadows = false;
+	F32 m_rayTracingExtendedFrustumDistance = 100.0f; ///< The frustum distance from the eye to every direction.
 };
 
 /// The scene graph that  all the scene entities
@@ -165,9 +167,9 @@ public:
 		return m_stats;
 	}
 
-	const SceneGraphLimits& getLimits() const
+	const SceneGraphConfig& getConfig() const
 	{
-		return m_limits;
+		return m_config;
 	}
 
 	const Vec3& getSceneMin() const
@@ -223,11 +225,6 @@ public:
 		return *m_octree;
 	}
 
-	Bool getRayTracedShadowsEnabled() const
-	{
-		return m_enableRtShadows;
-	}
-
 private:
 	class UpdateSceneNodesCtx;
 
@@ -264,11 +261,9 @@ private:
 
 	Atomic<U64> m_nodesUuid = {1};
 
-	SceneGraphLimits m_limits;
+	SceneGraphConfig m_config;
 	SceneGraphStats m_stats;
 
-	Bool m_enableRtShadows = false;
-
 	/// Put a node in the appropriate containers
 	ANKI_USE_RESULT Error registerNode(SceneNode* node);
 	void unregisterNode(SceneNode* node);

+ 1 - 1
anki/scene/Visibility.cpp

@@ -822,7 +822,7 @@ void SceneGraph::doVisibilityTests(SceneNode& fsn, SceneGraph& scene, RenderQueu
 
 	VisibilityContext ctx;
 	ctx.m_scene = &scene;
-	ctx.m_earlyZDist = scene.getLimits().m_earlyZDistance;
+	ctx.m_earlyZDist = scene.getConfig().m_earlyZDistance;
 	ctx.submitNewWork(fsn.getFirstComponentOfType<FrustumComponent>(), rqueue, hive);
 
 	hive.waitAllTasks();