Просмотр исходного кода

Renderer: Remove some frustum component references

Panagiotis Christopoulos Charitos 8 лет назад
Родитель
Сommit
23b7f2522b

+ 17 - 13
src/anki/renderer/Dbg.cpp

@@ -84,24 +84,28 @@ Error Dbg::run(RenderingContext& ctx)
 	cmdb->beginRenderPass(m_fb);
 	cmdb->beginRenderPass(m_fb);
 	cmdb->setViewport(0, 0, m_r->getWidth(), m_r->getHeight());
 	cmdb->setViewport(0, 0, m_r->getWidth(), m_r->getHeight());
 
 
-	FrustumComponent& camFrc = *ctx.m_frustumComponent;
-	SceneNode& cam = camFrc.getSceneNode();
 	m_drawer->prepareFrame(cmdb);
 	m_drawer->prepareFrame(cmdb);
-	m_drawer->setViewProjectionMatrix(camFrc.getViewProjectionMatrix());
+	m_drawer->setViewProjectionMatrix(ctx.m_viewProjMat);
 	m_drawer->setModelMatrix(Mat4::getIdentity());
 	m_drawer->setModelMatrix(Mat4::getIdentity());
 	// m_drawer->drawGrid();
 	// m_drawer->drawGrid();
 
 
-	SceneGraph& scene = cam.getSceneGraph();
+	const SceneGraph* scene = nullptr;
 
 
 	SceneDebugDrawer sceneDrawer(m_drawer);
 	SceneDebugDrawer sceneDrawer(m_drawer);
-	camFrc.getVisibilityTestResults().iterateAll([&](SceneNode& node) {
-		if(&node == &cam)
+	ctx.m_visResults->iterateAll([&](const SceneNode& node) {
+		// Get the scenegraph
+		if(scene == nullptr)
 		{
 		{
-			return;
+			scene = &node.getSceneGraph();
 		}
 		}
 
 
+		/*if(&node == &cam)
+		{
+			return;
+		}*/
+
 		// Set position
 		// Set position
-		MoveComponent* mv = node.tryGetComponent<MoveComponent>();
+		const MoveComponent* mv = node.tryGetComponent<MoveComponent>();
 		if(mv)
 		if(mv)
 		{
 		{
 			m_drawer->setModelMatrix(Mat4(mv->getWorldTransform()));
 			m_drawer->setModelMatrix(Mat4(mv->getWorldTransform()));
@@ -114,7 +118,7 @@ Error Dbg::run(RenderingContext& ctx)
 		// Spatial
 		// Spatial
 		if(m_flags.get(DbgFlag::SPATIAL_COMPONENT))
 		if(m_flags.get(DbgFlag::SPATIAL_COMPONENT))
 		{
 		{
-			Error err = node.iterateComponentsOfType<SpatialComponent>([&](SpatialComponent& sp) -> Error {
+			Error err = node.iterateComponentsOfType<const SpatialComponent>([&](const SpatialComponent& sp) -> Error {
 				sceneDrawer.draw(sp);
 				sceneDrawer.draw(sp);
 				return ErrorCode::NONE;
 				return ErrorCode::NONE;
 			});
 			});
@@ -125,10 +129,10 @@ Error Dbg::run(RenderingContext& ctx)
 		if(m_flags.get(DbgFlag::FRUSTUM_COMPONENT))
 		if(m_flags.get(DbgFlag::FRUSTUM_COMPONENT))
 		{
 		{
 			Error err = node.iterateComponentsOfType<FrustumComponent>([&](FrustumComponent& frc) -> Error {
 			Error err = node.iterateComponentsOfType<FrustumComponent>([&](FrustumComponent& frc) -> Error {
-				if(&frc != &camFrc)
+				/*if(&frc != &camFrc)
 				{
 				{
 					sceneDrawer.draw(frc);
 					sceneDrawer.draw(frc);
-				}
+				}*/
 				return ErrorCode::NONE;
 				return ErrorCode::NONE;
 			});
 			});
 			(void)err;
 			(void)err;
@@ -160,12 +164,12 @@ Error Dbg::run(RenderingContext& ctx)
 		}
 		}
 	});
 	});
 
 
-	if(m_flags.get(DbgFlag::PHYSICS))
+	if(m_flags.get(DbgFlag::PHYSICS) && scene)
 	{
 	{
 		PhysicsDebugDrawer phyd(m_drawer);
 		PhysicsDebugDrawer phyd(m_drawer);
 
 
 		m_drawer->setModelMatrix(Mat4::getIdentity());
 		m_drawer->setModelMatrix(Mat4::getIdentity());
-		phyd.drawWorld(scene.getPhysicsWorld());
+		phyd.drawWorld(scene->getPhysicsWorld());
 	}
 	}
 
 
 #if 0
 #if 0

+ 2 - 2
src/anki/renderer/DebugDrawer.cpp

@@ -418,7 +418,7 @@ void PhysicsDebugDrawer::drawLines(const Vec3* lines, const U32 linesCount, cons
 	m_dbg->end();
 	m_dbg->end();
 }
 }
 
 
-void SceneDebugDrawer::draw(FrustumComponent& fr) const
+void SceneDebugDrawer::draw(const FrustumComponent& fr) const
 {
 {
 	const Frustum& fs = fr.getFrustum();
 	const Frustum& fs = fr.getFrustum();
 
 
@@ -427,7 +427,7 @@ void SceneDebugDrawer::draw(FrustumComponent& fr) const
 	fs.accept(coldraw);
 	fs.accept(coldraw);
 }
 }
 
 
-void SceneDebugDrawer::draw(SpatialComponent& x) const
+void SceneDebugDrawer::draw(const SpatialComponent& x) const
 {
 {
 	if(!x.getVisibleByCamera())
 	if(!x.getVisibleByCamera())
 	{
 	{

+ 2 - 2
src/anki/renderer/DebugDrawer.h

@@ -163,9 +163,9 @@ public:
 	{
 	{
 	}
 	}
 
 
-	void draw(FrustumComponent& fr) const;
+	void draw(const FrustumComponent& fr) const;
 
 
-	void draw(SpatialComponent& sp) const;
+	void draw(const SpatialComponent& sp) const;
 
 
 	void draw(const PortalComponent& c) const;
 	void draw(const PortalComponent& c) const;
 
 

+ 6 - 11
src/anki/renderer/Fs.cpp

@@ -87,15 +87,13 @@ Error Fs::initVol()
 
 
 void Fs::drawVolumetric(RenderingContext& ctx, CommandBufferPtr cmdb)
 void Fs::drawVolumetric(RenderingContext& ctx, CommandBufferPtr cmdb)
 {
 {
-	const Frustum& fr = ctx.m_frustumComponent->getFrustum();
-
 	cmdb->bindShaderProgram(m_vol.m_prog);
 	cmdb->bindShaderProgram(m_vol.m_prog);
 	cmdb->setBlendFactors(0, BlendFactor::ONE, BlendFactor::ONE);
 	cmdb->setBlendFactors(0, BlendFactor::ONE, BlendFactor::ONE);
 	cmdb->setDepthWrite(false);
 	cmdb->setDepthWrite(false);
 	cmdb->setDepthCompareOperation(CompareOperation::ALWAYS);
 	cmdb->setDepthCompareOperation(CompareOperation::ALWAYS);
 
 
 	Vec4* unis = allocateAndBindUniforms<Vec4*>(sizeof(Vec4), cmdb, 0, 0);
 	Vec4* unis = allocateAndBindUniforms<Vec4*>(sizeof(Vec4), cmdb, 0, 0);
-	computeLinearizeDepthOptimal(fr.getNear(), fr.getFar(), unis->x(), unis->y());
+	computeLinearizeDepthOptimal(ctx.m_near, ctx.m_far, unis->x(), unis->y());
 
 
 	cmdb->informTextureSurfaceCurrentUsage(
 	cmdb->informTextureSurfaceCurrentUsage(
 		m_r->getDepthDownscale().m_qd.m_depthRt, TextureSurfaceInfo(0, 0, 0, 0), TextureUsageBit::SAMPLED_FRAGMENT);
 		m_r->getDepthDownscale().m_qd.m_depthRt, TextureSurfaceInfo(0, 0, 0, 0), TextureUsageBit::SAMPLED_FRAGMENT);
@@ -117,10 +115,7 @@ void Fs::drawVolumetric(RenderingContext& ctx, CommandBufferPtr cmdb)
 
 
 Error Fs::buildCommandBuffers(RenderingContext& ctx, U threadId, U threadCount) const
 Error Fs::buildCommandBuffers(RenderingContext& ctx, U threadId, U threadCount) const
 {
 {
-	// Get some stuff
-	VisibilityTestResults& vis = ctx.m_frustumComponent->getVisibilityTestResults();
-
-	U problemSize = vis.getCount(VisibilityGroupType::RENDERABLES_FS);
+	U problemSize = ctx.m_visResults->getCount(VisibilityGroupType::RENDERABLES_FS);
 	PtrSize start, end;
 	PtrSize start, end;
 	ThreadPoolTask::choseStartEnd(threadId, threadCount, problemSize, start, end);
 	ThreadPoolTask::choseStartEnd(threadId, threadCount, problemSize, start, end);
 
 
@@ -154,11 +149,11 @@ Error Fs::buildCommandBuffers(RenderingContext& ctx, U threadId, U threadCount)
 
 
 	// Start drawing
 	// Start drawing
 	Error err = m_r->getSceneDrawer().drawRange(Pass::MS_FS,
 	Error err = m_r->getSceneDrawer().drawRange(Pass::MS_FS,
-		ctx.m_frustumComponent->getViewMatrix(),
-		ctx.m_frustumComponent->getViewProjectionMatrix(),
+		ctx.m_viewMat,
+		ctx.m_viewProjMat,
 		cmdb,
 		cmdb,
-		vis.getBegin(VisibilityGroupType::RENDERABLES_FS) + start,
-		vis.getBegin(VisibilityGroupType::RENDERABLES_FS) + end);
+		ctx.m_visResults->getBegin(VisibilityGroupType::RENDERABLES_FS) + start,
+		ctx.m_visResults->getBegin(VisibilityGroupType::RENDERABLES_FS) + end);
 
 
 	return err;
 	return err;
 }
 }

+ 1 - 2
src/anki/renderer/FsUpscale.cpp

@@ -68,8 +68,7 @@ void FsUpscale::run(RenderingContext& ctx)
 	CommandBufferPtr cmdb = ctx.m_commandBuffer;
 	CommandBufferPtr cmdb = ctx.m_commandBuffer;
 
 
 	Vec4* linearDepth = allocateAndBindUniforms<Vec4*>(sizeof(Vec4), cmdb, 0, 0);
 	Vec4* linearDepth = allocateAndBindUniforms<Vec4*>(sizeof(Vec4), cmdb, 0, 0);
-	const Frustum& fr = ctx.m_frustumComponent->getFrustum();
-	computeLinearizeDepthOptimal(fr.getNear(), fr.getFar(), linearDepth->x(), linearDepth->y());
+	computeLinearizeDepthOptimal(ctx.m_near, ctx.m_far, linearDepth->x(), linearDepth->y());
 
 
 	cmdb->bindTexture(0, 0, m_r->getMs().m_depthRt);
 	cmdb->bindTexture(0, 0, m_r->getMs().m_depthRt);
 	cmdb->bindTextureAndSampler(0, 1, m_r->getDepthDownscale().m_hd.m_depthRt, m_nearestSampler);
 	cmdb->bindTextureAndSampler(0, 1, m_r->getDepthDownscale().m_hd.m_depthRt, m_nearestSampler);

+ 1 - 2
src/anki/renderer/Ir.cpp

@@ -549,8 +549,7 @@ void Ir::computeIrradiance(RenderingContext& rctx, U layer, U faceIdx)
 Error Ir::run(RenderingContext& rctx)
 Error Ir::run(RenderingContext& rctx)
 {
 {
 	ANKI_TRACE_START_EVENT(RENDER_IR);
 	ANKI_TRACE_START_EVENT(RENDER_IR);
-	FrustumComponent& frc = *rctx.m_frustumComponent;
-	VisibilityTestResults& visRez = frc.getVisibilityTestResults();
+	const VisibilityTestResults& visRez = *rctx.m_visResults;
 
 
 	if(visRez.getCount(VisibilityGroupType::REFLECTION_PROBES) > m_cubemapArrSize)
 	if(visRez.getCount(VisibilityGroupType::REFLECTION_PROBES) > m_cubemapArrSize)
 	{
 	{

+ 10 - 11
src/anki/renderer/Is.cpp

@@ -141,11 +141,11 @@ Error Is::binLights(RenderingContext& ctx)
 {
 {
 	updateCommonBlock(ctx);
 	updateCommonBlock(ctx);
 
 
-	ANKI_CHECK(m_lightBin->bin(ctx.m_frustumComponent->getViewMatrix(),
-		ctx.m_frustumComponent->getProjectionMatrix(),
-		ctx.m_frustumComponent->getViewProjectionMatrix(),
-		Mat4(ctx.m_frustumComponent->getFrustum().getTransform()),
-		ctx.m_frustumComponent->getVisibilityTestResults(),
+	ANKI_CHECK(m_lightBin->bin(ctx.m_viewMat,
+		ctx.m_projMat,
+		ctx.m_viewProjMat,
+		ctx.m_camTrfMat,
+		*ctx.m_visResults,
 		getFrameAllocator(),
 		getFrameAllocator(),
 		m_maxLightIds,
 		m_maxLightIds,
 		true,
 		true,
@@ -200,22 +200,21 @@ void Is::run(RenderingContext& ctx)
 
 
 void Is::updateCommonBlock(RenderingContext& ctx)
 void Is::updateCommonBlock(RenderingContext& ctx)
 {
 {
-	const FrustumComponent& fr = *ctx.m_frustumComponent;
 	ShaderCommonUniforms* blk =
 	ShaderCommonUniforms* blk =
 		allocateUniforms<ShaderCommonUniforms*>(sizeof(ShaderCommonUniforms), ctx.m_is.m_commonToken);
 		allocateUniforms<ShaderCommonUniforms*>(sizeof(ShaderCommonUniforms), ctx.m_is.m_commonToken);
 
 
 	// Start writing
 	// Start writing
-	blk->m_projectionParams = fr.getProjectionParameters();
-	blk->m_nearFarClustererMagicPad1 = Vec4(
-		fr.getFrustum().getNear(), fr.getFrustum().getFar(), m_lightBin->getClusterer().getShaderMagicValue(), 0.0);
+	blk->m_projectionParams = ctx.m_unprojParams;
+	blk->m_nearFarClustererMagicPad1 =
+		Vec4(ctx.m_near, ctx.m_far, m_lightBin->getClusterer().getShaderMagicValue(), 0.0);
 
 
-	blk->m_invViewRotation = Mat3x4(fr.getViewMatrix().getInverse().getRotationPart());
+	blk->m_invViewRotation = Mat3x4(ctx.m_viewMat.getInverse().getRotationPart());
 
 
 	blk->m_rendererSizeTimePad1 = Vec4(m_r->getWidth(), m_r->getHeight(), HighRezTimer::getCurrentTime(), 0.0);
 	blk->m_rendererSizeTimePad1 = Vec4(m_r->getWidth(), m_r->getHeight(), HighRezTimer::getCurrentTime(), 0.0);
 
 
 	blk->m_tileCount = UVec4(m_clusterCounts[0], m_clusterCounts[1], m_clusterCounts[2], m_clusterCount);
 	blk->m_tileCount = UVec4(m_clusterCounts[0], m_clusterCounts[1], m_clusterCounts[2], m_clusterCount);
 
 
-	blk->m_invViewProjMat = fr.getViewProjectionMatrix().getInverse();
+	blk->m_invViewProjMat = ctx.m_viewProjMat.getInverse();
 	blk->m_prevViewProjMat = ctx.m_prevViewProjMat;
 	blk->m_prevViewProjMat = ctx.m_prevViewProjMat;
 }
 }
 
 

+ 9 - 24
src/anki/renderer/Lf.cpp

@@ -108,15 +108,12 @@ Error Lf::initOcclusion(const ConfigSet& config)
 
 
 void Lf::resetOcclusionQueries(RenderingContext& ctx, CommandBufferPtr cmdb)
 void Lf::resetOcclusionQueries(RenderingContext& ctx, CommandBufferPtr cmdb)
 {
 {
-	const FrustumComponent& camFr = *ctx.m_frustumComponent;
-	const VisibilityTestResults& vi = camFr.getVisibilityTestResults();
-
-	if(vi.getCount(VisibilityGroupType::FLARES) > m_maxFlares)
+	if(ctx.m_visResults->getCount(VisibilityGroupType::FLARES) > m_maxFlares)
 	{
 	{
 		ANKI_R_LOGW("Visible flares exceed the limit. Increase lf.maxFlares");
 		ANKI_R_LOGW("Visible flares exceed the limit. Increase lf.maxFlares");
 	}
 	}
 
 
-	const U count = min<U>(vi.getCount(VisibilityGroupType::FLARES), m_maxFlares);
+	const U count = min<U>(ctx.m_visResults->getCount(VisibilityGroupType::FLARES), m_maxFlares);
 	for(U i = 0; i < count; ++i)
 	for(U i = 0; i < count; ++i)
 	{
 	{
 		if(!m_queries[i])
 		if(!m_queries[i])
@@ -130,18 +127,14 @@ void Lf::resetOcclusionQueries(RenderingContext& ctx, CommandBufferPtr cmdb)
 
 
 void Lf::runOcclusionTests(RenderingContext& ctx, CommandBufferPtr cmdb)
 void Lf::runOcclusionTests(RenderingContext& ctx, CommandBufferPtr cmdb)
 {
 {
-	// Retrieve some things
-	const FrustumComponent& camFr = *ctx.m_frustumComponent;
-	const VisibilityTestResults& vi = camFr.getVisibilityTestResults();
-
-	const U count = min<U>(vi.getCount(VisibilityGroupType::FLARES), m_maxFlares);
+	const U count = min<U>(ctx.m_visResults->getCount(VisibilityGroupType::FLARES), m_maxFlares);
 	Vec3* positions = nullptr;
 	Vec3* positions = nullptr;
 	const Vec3* initialPositions;
 	const Vec3* initialPositions;
 	if(count)
 	if(count)
 	{
 	{
 		// Setup MVP UBO
 		// Setup MVP UBO
 		Mat4* mvp = allocateAndBindUniforms<Mat4*>(sizeof(Mat4), cmdb, 0, 0);
 		Mat4* mvp = allocateAndBindUniforms<Mat4*>(sizeof(Mat4), cmdb, 0, 0);
-		*mvp = camFr.getViewProjectionMatrix();
+		*mvp = ctx.m_viewProjMat;
 
 
 		// Alloc dyn mem
 		// Alloc dyn mem
 		StagingGpuMemoryToken vertToken;
 		StagingGpuMemoryToken vertToken;
@@ -163,7 +156,7 @@ void Lf::runOcclusionTests(RenderingContext& ctx, CommandBufferPtr cmdb)
 	for(U i = 0; i < count; ++i)
 	for(U i = 0; i < count; ++i)
 	{
 	{
 		// Iterate lens flare
 		// Iterate lens flare
-		auto it = vi.getBegin(VisibilityGroupType::FLARES) + i;
+		auto it = ctx.m_visResults->getBegin(VisibilityGroupType::FLARES) + i;
 		const LensFlareComponent& lf = (it->m_node)->getComponent<LensFlareComponent>();
 		const LensFlareComponent& lf = (it->m_node)->getComponent<LensFlareComponent>();
 
 
 		*positions = lf.getWorldPosition().xyz();
 		*positions = lf.getWorldPosition().xyz();
@@ -188,11 +181,7 @@ void Lf::runOcclusionTests(RenderingContext& ctx, CommandBufferPtr cmdb)
 
 
 void Lf::updateIndirectInfo(RenderingContext& ctx, CommandBufferPtr cmdb)
 void Lf::updateIndirectInfo(RenderingContext& ctx, CommandBufferPtr cmdb)
 {
 {
-	// Retrieve some things
-	FrustumComponent& camFr = *ctx.m_frustumComponent;
-	VisibilityTestResults& vi = camFr.getVisibilityTestResults();
-
-	U count = min<U>(vi.getCount(VisibilityGroupType::FLARES), m_maxFlares);
+	U count = min<U>(ctx.m_visResults->getCount(VisibilityGroupType::FLARES), m_maxFlares);
 	if(count == 0)
 	if(count == 0)
 	{
 	{
 		return;
 		return;
@@ -227,11 +216,7 @@ void Lf::updateIndirectInfo(RenderingContext& ctx, CommandBufferPtr cmdb)
 
 
 void Lf::run(RenderingContext& ctx, CommandBufferPtr cmdb)
 void Lf::run(RenderingContext& ctx, CommandBufferPtr cmdb)
 {
 {
-	// Retrieve some things
-	FrustumComponent& camFr = *ctx.m_frustumComponent;
-	VisibilityTestResults& vi = camFr.getVisibilityTestResults();
-
-	const U count = min<U>(vi.getCount(VisibilityGroupType::FLARES), m_maxFlares);
+	const U count = min<U>(ctx.m_visResults->getCount(VisibilityGroupType::FLARES), m_maxFlares);
 	if(count == 0)
 	if(count == 0)
 	{
 	{
 		return;
 		return;
@@ -246,12 +231,12 @@ void Lf::run(RenderingContext& ctx, CommandBufferPtr cmdb)
 
 
 	for(U i = 0; i < count; ++i)
 	for(U i = 0; i < count; ++i)
 	{
 	{
-		auto it = vi.getBegin(VisibilityGroupType::FLARES) + i;
+		auto it = ctx.m_visResults->getBegin(VisibilityGroupType::FLARES) + i;
 		const LensFlareComponent& lf = (it->m_node)->getComponent<LensFlareComponent>();
 		const LensFlareComponent& lf = (it->m_node)->getComponent<LensFlareComponent>();
 
 
 		// Compute position
 		// Compute position
 		Vec4 lfPos = Vec4(lf.getWorldPosition().xyz(), 1.0);
 		Vec4 lfPos = Vec4(lf.getWorldPosition().xyz(), 1.0);
-		Vec4 posClip = camFr.getViewProjectionMatrix() * lfPos;
+		Vec4 posClip = ctx.m_viewProjMat * lfPos;
 
 
 		/*if(posClip.x() > posClip.w() || posClip.x() < -posClip.w() || posClip.y() > posClip.w()
 		/*if(posClip.x() > posClip.w() || posClip.x() < -posClip.w() || posClip.y() > posClip.w()
 			|| posClip.y() < -posClip.w())
 			|| posClip.y() < -posClip.w())

+ 9 - 1
src/anki/renderer/MainRenderer.cpp

@@ -114,7 +114,15 @@ Error MainRenderer::render(SceneGraph& scene)
 	}
 	}
 
 
 	ctx.m_commandBuffer = cmdb;
 	ctx.m_commandBuffer = cmdb;
-	ctx.m_frustumComponent = &scene.getActiveCamera().getComponent<FrustumComponent>();
+	const FrustumComponent& frc = scene.getActiveCamera().getComponent<FrustumComponent>();
+	ctx.m_visResults = &frc.getVisibilityTestResults();
+	ctx.m_viewMat = frc.getViewMatrix();
+	ctx.m_projMat = frc.getProjectionMatrix();
+	ctx.m_viewProjMat = frc.getViewProjectionMatrix();
+	ctx.m_camTrfMat = Mat4(frc.getFrustum().getTransform());
+	ctx.m_near = frc.getFrustum().getNear();
+	ctx.m_far = frc.getFrustum().getFar();
+	ctx.m_unprojParams = frc.getProjectionParameters();
 	ANKI_CHECK(m_r->render(ctx));
 	ANKI_CHECK(m_r->render(ctx));
 
 
 	// Blit renderer's result to default FB if needed
 	// Blit renderer's result to default FB if needed

+ 3 - 3
src/anki/renderer/Ms.cpp

@@ -97,7 +97,7 @@ Error Ms::buildCommandBuffers(RenderingContext& ctx, U threadId, U threadCount)
 	ANKI_TRACE_START_EVENT(RENDER_MS);
 	ANKI_TRACE_START_EVENT(RENDER_MS);
 
 
 	// Get some stuff
 	// Get some stuff
-	VisibilityTestResults& vis = ctx.m_frustumComponent->getVisibilityTestResults();
+	const VisibilityTestResults& vis = *ctx.m_visResults;
 
 
 	U problemSize = vis.getCount(VisibilityGroupType::RENDERABLES_MS);
 	U problemSize = vis.getCount(VisibilityGroupType::RENDERABLES_MS);
 	PtrSize start, end;
 	PtrSize start, end;
@@ -124,8 +124,8 @@ Error Ms::buildCommandBuffers(RenderingContext& ctx, U threadId, U threadCount)
 
 
 		// Start drawing
 		// Start drawing
 		ANKI_CHECK(m_r->getSceneDrawer().drawRange(Pass::MS_FS,
 		ANKI_CHECK(m_r->getSceneDrawer().drawRange(Pass::MS_FS,
-			ctx.m_frustumComponent->getViewMatrix(),
-			ctx.m_frustumComponent->getViewProjectionMatrix(),
+			ctx.m_viewMat,
+			ctx.m_viewProjMat,
 			cmdb,
 			cmdb,
 			vis.getBegin(VisibilityGroupType::RENDERABLES_MS) + start,
 			vis.getBegin(VisibilityGroupType::RENDERABLES_MS) + start,
 			vis.getBegin(VisibilityGroupType::RENDERABLES_MS) + end));
 			vis.getBegin(VisibilityGroupType::RENDERABLES_MS) + end));

+ 3 - 7
src/anki/renderer/Renderer.cpp

@@ -34,9 +34,7 @@ namespace anki
 static Bool threadWillDoWork(
 static Bool threadWillDoWork(
 	const RenderingContext& ctx, VisibilityGroupType typeOfWork, U32 threadId, PtrSize threadCount)
 	const RenderingContext& ctx, VisibilityGroupType typeOfWork, U32 threadId, PtrSize threadCount)
 {
 {
-	const VisibilityTestResults& vis = ctx.m_frustumComponent->getVisibilityTestResults();
-
-	U problemSize = vis.getCount(typeOfWork);
+	U problemSize = ctx.m_visResults->getCount(typeOfWork);
 	PtrSize start, end;
 	PtrSize start, end;
 	ThreadPoolTask::choseStartEnd(threadId, threadCount, problemSize, start, end);
 	ThreadPoolTask::choseStartEnd(threadId, threadCount, problemSize, start, end);
 
 
@@ -171,8 +169,6 @@ Error Renderer::render(RenderingContext& ctx)
 {
 {
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 
 
-	ANKI_ASSERT(ctx.m_frustumComponent->getFrustum().getType() == FrustumType::PERSPECTIVE);
-
 	ctx.m_prevViewProjMat = m_prevViewProjMat;
 	ctx.m_prevViewProjMat = m_prevViewProjMat;
 	ctx.m_prevCamTransform = m_prevCamTransform;
 	ctx.m_prevCamTransform = m_prevCamTransform;
 
 
@@ -315,8 +311,8 @@ Error Renderer::render(RenderingContext& ctx)
 	ANKI_CHECK(m_pps->run(ctx));
 	ANKI_CHECK(m_pps->run(ctx));
 
 
 	++m_frameCount;
 	++m_frameCount;
-	m_prevViewProjMat = ctx.m_frustumComponent->getViewProjectionMatrix();
-	m_prevCamTransform = Mat4(ctx.m_frustumComponent->getFrustum().getTransform());
+	m_prevViewProjMat = ctx.m_viewProjMat;
+	m_prevCamTransform = ctx.m_camTrfMat;
 
 
 	return ErrorCode::NONE;
 	return ErrorCode::NONE;
 }
 }

+ 10 - 2
src/anki/renderer/Renderer.h

@@ -24,6 +24,7 @@ namespace anki
 class ConfigSet;
 class ConfigSet;
 class ResourceManager;
 class ResourceManager;
 class StagingGpuMemoryManager;
 class StagingGpuMemoryManager;
+class VisibilityTestResults;
 
 
 /// @addtogroup renderer
 /// @addtogroup renderer
 /// @{
 /// @{
@@ -32,8 +33,15 @@ class StagingGpuMemoryManager;
 class RenderingContext
 class RenderingContext
 {
 {
 public:
 public:
-	/// Active frustum.
-	FrustumComponent* m_frustumComponent ANKI_DBG_NULLIFY;
+	const VisibilityTestResults* m_visResults ANKI_DBG_NULLIFY;
+	Mat4 m_viewMat;
+	Mat4 m_projMat;
+	Mat4 m_viewProjMat;
+	Mat4 m_camTrfMat;
+	F32 m_near;
+	F32 m_far;
+	Vec4 m_unprojParams;
+
 	Mat4 m_prevViewProjMat;
 	Mat4 m_prevViewProjMat;
 	Mat4 m_prevCamTransform;
 	Mat4 m_prevCamTransform;
 
 

+ 1 - 1
src/anki/renderer/Sm.cpp

@@ -343,7 +343,7 @@ void Sm::prepareBuildCommandBuffers(RenderingContext& ctx)
 	ANKI_TRACE_START_EVENT(RENDER_SM);
 	ANKI_TRACE_START_EVENT(RENDER_SM);
 
 
 	// Gather the lights
 	// Gather the lights
-	VisibilityTestResults& vi = ctx.m_frustumComponent->getVisibilityTestResults();
+	const VisibilityTestResults& vi = *ctx.m_visResults;
 
 
 	const U MAX = 64;
 	const U MAX = 64;
 	Array<SceneNode*, MAX> spotCasters;
 	Array<SceneNode*, MAX> spotCasters;

+ 2 - 3
src/anki/renderer/Ssao.cpp

@@ -101,9 +101,8 @@ void SsaoMain::run(RenderingContext& ctx)
 	cmdb->bindTexture(0, 2, m_noiseTex->getGrTexture());
 	cmdb->bindTexture(0, 2, m_noiseTex->getGrTexture());
 
 
 	Vec4* unis = allocateAndBindUniforms<Vec4*>(sizeof(Vec4) * 2, cmdb, 0, 0);
 	Vec4* unis = allocateAndBindUniforms<Vec4*>(sizeof(Vec4) * 2, cmdb, 0, 0);
-	const FrustumComponent& frc = *ctx.m_frustumComponent;
-	const Mat4& pmat = frc.getProjectionMatrix();
-	*unis = frc.getProjectionParameters();
+	const Mat4& pmat = ctx.m_projMat;
+	*unis = ctx.m_unprojParams;
 	++unis;
 	++unis;
 	*unis = Vec4(pmat(0, 0), pmat(1, 1), pmat(2, 2), pmat(2, 3));
 	*unis = Vec4(pmat(0, 0), pmat(1, 1), pmat(2, 2), pmat(2, 3));
 
 

+ 4 - 8
src/anki/renderer/Volumetric.cpp

@@ -64,7 +64,6 @@ void VolumetricMain::setPreRunBarriers(RenderingContext& ctx)
 void VolumetricMain::run(RenderingContext& ctx)
 void VolumetricMain::run(RenderingContext& ctx)
 {
 {
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
-	const Frustum& frc = ctx.m_frustumComponent->getFrustum();
 
 
 	//
 	//
 	// Main pass
 	// Main pass
@@ -82,23 +81,20 @@ void VolumetricMain::run(RenderingContext& ctx)
 	bindUniforms(cmdb, 0, 2, ctx.m_is.m_spotLightsToken);
 	bindUniforms(cmdb, 0, 2, ctx.m_is.m_spotLightsToken);
 
 
 	Vec4* uniforms = allocateAndBindUniforms<Vec4*>(sizeof(Vec4) * 2, cmdb, 0, 3);
 	Vec4* uniforms = allocateAndBindUniforms<Vec4*>(sizeof(Vec4) * 2, cmdb, 0, 3);
-	computeLinearizeDepthOptimal(frc.getNear(), frc.getFar(), uniforms[0].x(), uniforms[0].y());
+	computeLinearizeDepthOptimal(ctx.m_near, ctx.m_far, uniforms[0].x(), uniforms[0].y());
 
 
 	F32 texelOffset = 1.0 / m_noiseTex->getWidth();
 	F32 texelOffset = 1.0 / m_noiseTex->getWidth();
 	uniforms[0].z() = m_r->getFrameCount() * texelOffset;
 	uniforms[0].z() = m_r->getFrameCount() * texelOffset;
 	uniforms[0].w() = m_r->getFrameCount() & (m_noiseTex->getLayerCount() - 1);
 	uniforms[0].w() = m_r->getFrameCount() & (m_noiseTex->getLayerCount() - 1);
 
 
 	// Compute the blend factor. If the camera rotated or moved alot don't blend with previous frames
 	// Compute the blend factor. If the camera rotated or moved alot don't blend with previous frames
-	F32 dotZ = ctx.m_frustumComponent->getFrustum().getTransform().getRotation().getZAxis().xyz().dot(
-		ctx.m_prevCamTransform.getZAxis().xyz());
-	F32 dotY = ctx.m_frustumComponent->getFrustum().getTransform().getRotation().getYAxis().xyz().dot(
-		ctx.m_prevCamTransform.getYAxis().xyz());
+	F32 dotZ = ctx.m_camTrfMat.getZAxis().xyz().dot(ctx.m_prevCamTransform.getZAxis().xyz());
+	F32 dotY = ctx.m_camTrfMat.getYAxis().xyz().dot(ctx.m_prevCamTransform.getYAxis().xyz());
 
 
 	const F32 ANG_TOLERANCE = cos(toRad(1.0f / 8.0f));
 	const F32 ANG_TOLERANCE = cos(toRad(1.0f / 8.0f));
 	const F32 DIST_TOLERANCE = 0.1f;
 	const F32 DIST_TOLERANCE = 0.1f;
 	F32 blendFactor;
 	F32 blendFactor;
-	const F32 dist = (ctx.m_frustumComponent->getFrustum().getTransform().getOrigin().xyz0()
-						 - ctx.m_prevCamTransform.getTranslationPart().xyz0())
+	const F32 dist = (ctx.m_camTrfMat.getTranslationPart().xyz0() - ctx.m_prevCamTransform.getTranslationPart().xyz0())
 						 .getLengthSquared();
 						 .getLengthSquared();
 	if(clamp(dotZ, 0.0f, 1.0f) > ANG_TOLERANCE && clamp(dotY, 0.0f, 1.0f) > ANG_TOLERANCE
 	if(clamp(dotZ, 0.0f, 1.0f) > ANG_TOLERANCE && clamp(dotY, 0.0f, 1.0f) > ANG_TOLERANCE
 		&& dist < DIST_TOLERANCE * DIST_TOLERANCE)
 		&& dist < DIST_TOLERANCE * DIST_TOLERANCE)

+ 5 - 0
src/anki/scene/SceneGraph.h

@@ -168,6 +168,11 @@ anki_internal:
 		return *m_physics;
 		return *m_physics;
 	}
 	}
 
 
+	const PhysicsWorld& getPhysicsWorld() const
+	{
+		return *m_physics;
+	}
+
 	const Input& getInput() const
 	const Input& getInput() const
 	{
 	{
 		ANKI_ASSERT(m_input);
 		ANKI_ASSERT(m_input);

+ 7 - 2
src/anki/scene/SceneNode.h

@@ -41,6 +41,11 @@ public:
 		return *m_scene;
 		return *m_scene;
 	}
 	}
 
 
+	const SceneGraph& getSceneGraph() const
+	{
+		return *m_scene;
+	}
+
 	/// Return the name. It may be empty for nodes that we don't want to track
 	/// Return the name. It may be empty for nodes that we don't want to track
 	CString getName() const
 	CString getName() const
 	{
 	{
@@ -121,14 +126,14 @@ public:
 
 
 	/// Iterate all components of a specific type
 	/// Iterate all components of a specific type
 	template<typename Component, typename Func>
 	template<typename Component, typename Func>
-	ANKI_USE_RESULT Error iterateComponentsOfType(Func func)
+	ANKI_USE_RESULT Error iterateComponentsOfType(Func func) const
 	{
 	{
 		Error err = ErrorCode::NONE;
 		Error err = ErrorCode::NONE;
 		auto it = m_components.getBegin();
 		auto it = m_components.getBegin();
 		auto end = it + m_componentsCount;
 		auto end = it + m_componentsCount;
 		for(; !err && it != end; ++it)
 		for(; !err && it != end; ++it)
 		{
 		{
-			SceneComponent* comp = *it;
+			auto* comp = *it;
 			if(comp->getType() == Component::CLASS_TYPE)
 			if(comp->getType() == Component::CLASS_TYPE)
 			{
 			{
 				err = func(*static_cast<Component*>(comp));
 				err = func(*static_cast<Component*>(comp));

+ 3 - 3
src/anki/scene/Visibility.h

@@ -144,12 +144,12 @@ public:
 	void combineWith(SceneFrameAllocator<U8> alloc, WeakArray<VisibilityTestResults*>& results);
 	void combineWith(SceneFrameAllocator<U8> alloc, WeakArray<VisibilityTestResults*>& results);
 
 
 	template<typename TFunc>
 	template<typename TFunc>
-	void iterateAll(TFunc f)
+	void iterateAll(TFunc f) const
 	{
 	{
 		for(VisibilityGroupType i = VisibilityGroupType::FIRST; i < VisibilityGroupType::TYPE_COUNT; ++i)
 		for(VisibilityGroupType i = VisibilityGroupType::FIRST; i < VisibilityGroupType::TYPE_COUNT; ++i)
 		{
 		{
-			VisibleNode* it = getBegin(i);
-			VisibleNode* end = getEnd(i);
+			const VisibleNode* it = getBegin(i);
+			const VisibleNode* end = getEnd(i);
 			while(it != end)
 			while(it != end)
 			{
 			{
 				f(*it->m_node);
 				f(*it->m_node);