Selaa lähdekoodia

Some optimizations and cleanup

Panagiotis Christopoulos Charitos 7 vuotta sitten
vanhempi
sitoutus
157a8bbceb

+ 7 - 4
shaders/ForwardShadingCommonFrag.glsl

@@ -37,8 +37,10 @@ Vec4 readAnimatedTextureRgba(sampler2DArray tex, F32 period, Vec2 uv, F32 time)
 	return texture(tex, Vec3(uv, layer));
 	return texture(tex, Vec3(uv, layer));
 }
 }
 
 
-Vec3 computeLightColor(Vec3 diffCol, Vec3 worldPos)
+// Iterate the clusters to compute the light color
+Vec3 computeLightColorHigh(Vec3 diffCol, Vec3 worldPos)
 {
 {
+	diffCol = diffuseLambert(diffCol);
 	Vec3 outColor = Vec3(0.0);
 	Vec3 outColor = Vec3(0.0);
 
 
 	// Find the cluster and then the light counts
 	// Find the cluster and then the light counts
@@ -58,7 +60,7 @@ Vec3 computeLightColor(Vec3 diffCol, Vec3 worldPos)
 	{
 	{
 		PointLight light = u_pointLights[u_lightIndices[idxOffset++]];
 		PointLight light = u_pointLights[u_lightIndices[idxOffset++]];
 
 
-		Vec3 diffC = diffuseLambert(diffCol) * light.m_diffuseColorTileSize.rgb;
+		Vec3 diffC = diffCol * light.m_diffuseColorTileSize.rgb;
 
 
 		Vec3 frag2Light = light.m_posRadius.xyz - worldPos;
 		Vec3 frag2Light = light.m_posRadius.xyz - worldPos;
 		F32 att = computeAttenuationFactor(light.m_posRadius.w, frag2Light);
 		F32 att = computeAttenuationFactor(light.m_posRadius.w, frag2Light);
@@ -84,7 +86,7 @@ Vec3 computeLightColor(Vec3 diffCol, Vec3 worldPos)
 	{
 	{
 		SpotLight light = u_spotLights[u_lightIndices[idxOffset++]];
 		SpotLight light = u_spotLights[u_lightIndices[idxOffset++]];
 
 
-		Vec3 diffC = diffuseLambert(diffCol) * light.m_diffuseColorShadowmapId.rgb;
+		Vec3 diffC = diffCol * light.m_diffuseColorShadowmapId.rgb;
 
 
 		Vec3 frag2Light = light.m_posRadius.xyz - worldPos;
 		Vec3 frag2Light = light.m_posRadius.xyz - worldPos;
 		F32 att = computeAttenuationFactor(light.m_posRadius.w, frag2Light);
 		F32 att = computeAttenuationFactor(light.m_posRadius.w, frag2Light);
@@ -111,7 +113,8 @@ Vec3 computeLightColor(Vec3 diffCol, Vec3 worldPos)
 	return outColor;
 	return outColor;
 }
 }
 
 
-Vec3 computeLightColor2(Vec3 diffCol, Vec3 worldPos)
+// Just read the light color from the vol texture
+Vec3 computeLightColorLow(Vec3 diffCol, Vec3 worldPos)
 {
 {
 	Vec2 uv = gl_FragCoord.xy / RENDERER_SIZE;
 	Vec2 uv = gl_FragCoord.xy / RENDERER_SIZE;
 	Vec3 uv3d = computeClustererVolumeTextureUvs(u_clustererMagic, uv, worldPos, m_lightVolumeLastCluster);
 	Vec3 uv3d = computeClustererVolumeTextureUvs(u_clustererMagic, uv, worldPos, m_lightVolumeLastCluster);

+ 1 - 1
shaders/ForwardShadingParticles.glslp

@@ -54,7 +54,7 @@ void main()
 #endif
 #endif
 
 
 #if LIGHT
 #if LIGHT
-	texCol.rgb = computeLightColor(texCol.rgb, in_worldPos);
+	texCol.rgb = computeLightColorHigh(texCol.rgb, in_worldPos);
 #endif
 #endif
 
 
 	Vec4 colScale = colorScale;
 	Vec4 colScale = colorScale;

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

@@ -215,11 +215,6 @@ anki_internal:
 		return m_nodesUuid++;
 		return m_nodesUuid++;
 	}
 	}
 
 
-	SceneComponentLists& getSceneComponentLists()
-	{
-		return m_componentLists;
-	}
-
 	F32 getEarlyZDistance() const
 	F32 getEarlyZDistance() const
 	{
 	{
 		return m_earlyZDist;
 		return m_earlyZDist;
@@ -269,8 +264,6 @@ private:
 
 
 	U64 m_nodesUuid = 0;
 	U64 m_nodesUuid = 0;
 
 
-	SceneComponentLists m_componentLists;
-
 	F32 m_earlyZDist = -1.0;
 	F32 m_earlyZDist = -1.0;
 
 
 	SceneGraphStats m_stats;
 	SceneGraphStats m_stats;

+ 7 - 1
src/anki/scene/components/MoveComponent.cpp

@@ -20,9 +20,15 @@ MoveComponent::~MoveComponent()
 {
 {
 }
 }
 
 
-Error MoveComponent::update(Second, Second, Bool& updated)
+Error MoveComponent::update(Second prevTime, Second crntTime, Bool& updated)
 {
 {
 	updated = updateWorldTransform(*m_node);
 	updated = updateWorldTransform(*m_node);
+
+	if(updated)
+	{
+		onMoveComponentUpdate(*m_node, prevTime, crntTime);
+	}
+
 	return Error::NONE;
 	return Error::NONE;
 }
 }
 
 

+ 0 - 5
src/anki/scene/components/MoveComponent.h

@@ -112,11 +112,6 @@ public:
 	/// @note Don't update if child because we start from roots and go to children and we don't want a child to be
 	/// @note Don't update if child because we start from roots and go to children and we don't want a child to be
 	///       updated before the parent
 	///       updated before the parent
 	ANKI_USE_RESULT Error update(Second, Second, Bool& updated) override;
 	ANKI_USE_RESULT Error update(Second, Second, Bool& updated) override;
-
-	ANKI_USE_RESULT Error onUpdate(Second prevTime, Second crntTime) final
-	{
-		return onMoveComponentUpdate(*m_node, prevTime, crntTime);
-	}
 	/// @}
 	/// @}
 
 
 	/// @name Mess with the local transform
 	/// @name Mess with the local transform

+ 3 - 30
src/anki/scene/components/SceneComponent.cpp

@@ -11,23 +11,15 @@ namespace anki
 {
 {
 
 
 SceneComponent::SceneComponent(SceneComponentType type, SceneNode* node)
 SceneComponent::SceneComponent(SceneComponentType type, SceneNode* node)
-	: m_node(node)
-	, m_type(type)
+	: m_type(type)
+	, m_node(node)
 	, m_uuid(node->getSceneGraph().getNewUuid())
 	, m_uuid(node->getSceneGraph().getNewUuid())
 	, m_idx(node->getComponentCount())
 	, m_idx(node->getComponentCount())
 {
 {
-	if(m_type != SceneComponentType::NONE)
-	{
-		m_node->getSceneGraph().getSceneComponentLists().insertNew(this);
-	}
 }
 }
 
 
 SceneComponent::~SceneComponent()
 SceneComponent::~SceneComponent()
 {
 {
-	if(m_type != SceneComponentType::NONE)
-	{
-		m_node->getSceneGraph().getSceneComponentLists().remove(this);
-	}
 }
 }
 
 
 Timestamp SceneComponent::getGlobalTimestamp() const
 Timestamp SceneComponent::getGlobalTimestamp() const
@@ -40,12 +32,7 @@ Error SceneComponent::updateReal(Second prevTime, Second crntTime, Bool& updated
 	Error err = update(prevTime, crntTime, updated);
 	Error err = update(prevTime, crntTime, updated);
 	if(!err && updated)
 	if(!err && updated)
 	{
 	{
-		err = onUpdate(prevTime, crntTime);
-
-		if(!err)
-		{
-			m_timestamp = getGlobalTimestamp();
-		}
+		m_timestamp = getGlobalTimestamp();
 	}
 	}
 
 
 	return err;
 	return err;
@@ -71,18 +58,4 @@ SceneFrameAllocator<U8> SceneComponent::getFrameAllocator() const
 	return m_node->getFrameAllocator();
 	return m_node->getFrameAllocator();
 }
 }
 
 
-void SceneComponentLists::insertNew(SceneComponent* comp)
-{
-	ANKI_ASSERT(comp);
-
-	m_lists[comp->getType()].pushBack(comp);
-}
-
-void SceneComponentLists::remove(SceneComponent* comp)
-{
-	ANKI_ASSERT(comp);
-
-	m_lists[comp->getType()].erase(comp);
-}
-
 } // end namespace anki
 } // end namespace anki

+ 2 - 42
src/anki/scene/components/SceneComponent.h

@@ -8,7 +8,6 @@
 #include <anki/scene/Common.h>
 #include <anki/scene/Common.h>
 #include <anki/util/Functions.h>
 #include <anki/util/Functions.h>
 #include <anki/util/BitMask.h>
 #include <anki/util/BitMask.h>
-#include <anki/util/List.h>
 
 
 namespace anki
 namespace anki
 {
 {
@@ -42,7 +41,7 @@ enum class SceneComponentType : U16
 };
 };
 
 
 /// Scene node component
 /// Scene node component
-class SceneComponent : public IntrusiveListEnabled<SceneComponent>
+class SceneComponent
 {
 {
 public:
 public:
 	/// Construct the scene component.
 	/// Construct the scene component.
@@ -72,12 +71,6 @@ public:
 		return Error::NONE;
 		return Error::NONE;
 	}
 	}
 
 
-	/// Called if SceneComponent::update returned true.
-	virtual ANKI_USE_RESULT Error onUpdate(Second prevTime, Second crntTime)
-	{
-		return Error::NONE;
-	}
-
 	/// Called only by the SceneGraph
 	/// Called only by the SceneGraph
 	ANKI_USE_RESULT Error updateReal(Second prevTime, Second crntTime, Bool& updated);
 	ANKI_USE_RESULT Error updateReal(Second prevTime, Second crntTime, Bool& updated);
 
 
@@ -115,42 +108,9 @@ protected:
 	Timestamp m_timestamp = 1; ///< Indicates when an update happened
 	Timestamp m_timestamp = 1; ///< Indicates when an update happened
 
 
 private:
 private:
-	SceneComponentType m_type;
 	U64 m_uuid;
 	U64 m_uuid;
 	U32 m_idx;
 	U32 m_idx;
-};
-
-/// Multiple lists of all types of components.
-class SceneComponentLists : public NonCopyable
-{
-anki_internal:
-	SceneComponentLists()
-	{
-	}
-
-	~SceneComponentLists()
-	{
-	}
-
-	void insertNew(SceneComponent* comp);
-
-	void remove(SceneComponent* comp);
-
-	template<typename TSceneComponentType, typename Func>
-	void iterateComponents(Func func)
-	{
-		auto it = m_lists[TSceneComponentType::CLASS_TYPE].getBegin();
-		auto end = m_lists[TSceneComponentType::CLASS_TYPE].getEnd();
-
-		while(it != end)
-		{
-			func(static_cast<TSceneComponentType&>(*it));
-			++it;
-		}
-	}
-
-private:
-	Array<IntrusiveList<SceneComponent>, U(SceneComponentType::COUNT)> m_lists;
+	SceneComponentType m_type;
 };
 };
 /// @}
 /// @}