Browse Source

More fixes

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
aac9560dc6

+ 3 - 15
include/anki/renderer/Dbg.h

@@ -52,20 +52,9 @@ public:
 
 	ANKI_USE_RESULT Error run(CommandBufferPtr& jobs);
 
-	Bool getDepthTestEnabled() const
-	{
-		return m_depthTest;
-	}
-
-	void setDepthTestEnabled(Bool enable)
-	{
-		m_depthTest = enable;
-	}
-
-	void switchDepthTestEnabled()
-	{
-		m_depthTest = !m_depthTest;
-	}
+	Bool getDepthTestEnabled() const;
+	void setDepthTestEnabled(Bool enable);
+	void switchDepthTestEnabled();
 	/// @}
 
 private:
@@ -73,7 +62,6 @@ private:
 	DebugDrawer* m_drawer = nullptr;
 	// Have it as ptr because the constructor calls opengl
 	SceneDebugDrawer* m_sceneDrawer = nullptr;
-	Bool m_depthTest = true;
 };
 /// @}
 

+ 14 - 1
include/anki/renderer/DebugDrawer.h

@@ -72,6 +72,16 @@ public:
 	void setViewProjectionMatrix(const Mat4& m);
 	/// @}
 
+	void setDepthTestEnabled(Bool enabled)
+	{
+		m_depthTestEnabled = enabled;
+	}
+
+	Bool getDepthTestEnabled() const
+	{
+		return m_depthTestEnabled;
+	}
+
 	/// This is the function that actualy draws
 	ANKI_USE_RESULT Error flush();
 
@@ -85,7 +95,8 @@ private:
 
 	ShaderResourcePtr m_frag;
 	ShaderResourcePtr m_vert;
-	PipelinePtr m_ppline;
+	PipelinePtr m_pplineLinesDepth;
+	PipelinePtr m_pplineLinesNoDepth;
 	CommandBufferPtr m_cmdb;
 
 	static const U MAX_POINTS_PER_DRAW = 256;
@@ -104,6 +115,8 @@ private:
 
 	DArray<Vec3> m_sphereVerts;
 
+	Bool8 m_depthTestEnabled = true;
+
 	ANKI_USE_RESULT Error flushInternal(GLenum primitive);
 };
 

+ 27 - 27
include/anki/scene/SpatialComponent.h

@@ -21,34 +21,11 @@ class Sector;
 /// @addtogroup scene
 /// @{
 
-/// Spatial flags
-enum class SpatialComponentFlag: U8
-{
-	NONE = 0,
-	VISIBLE_CAMERA = 1 << 1,
-	VISIBLE_LIGHT = 1 << 2,
-
-	/// Visible or not. The visibility tester sets it
-	VISIBLE_ANY = VISIBLE_CAMERA | VISIBLE_LIGHT,
-
-	/// This is used for example in lights. If the light does not collide
-	/// with any surface then it shouldn't be visible and be processed
-	/// further. This flag is being used to check if we should test agains
-	/// near plane when using the tiler for visibility tests.
-	FULLY_TRANSPARENT = 1 << 3,
-
-	MARKED_FOR_UPDATE = 1 << 4
-};
-ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(SpatialComponentFlag, inline)
-
 /// Spatial component for scene nodes. It indicates scene nodes that need to
 /// be placed in the a sector and they participate in the visibility tests
-class SpatialComponent: public SceneComponent,
-	public Bitset<SpatialComponentFlag>
+class SpatialComponent: public SceneComponent
 {
 public:
-	using Flag = SpatialComponentFlag;
-
 	static Bool classof(const SceneComponent& c)
 	{
 		return c.getType() == Type::SPATIAL;
@@ -56,8 +33,7 @@ public:
 
 	SpatialComponent(
 		SceneNode* node,
-		const CollisionShape* shape,
-		Flag flags = Flag::NONE);
+		const CollisionShape* shape);
 
 	~SpatialComponent();
 
@@ -112,7 +88,19 @@ public:
 	/// shape got updated
 	void markForUpdate()
 	{
-		enableBits(Flag::MARKED_FOR_UPDATE);
+		m_bits.enableBits(Flag::MARKED_FOR_UPDATE);
+	}
+
+	/// Set if visible by a camera
+	void setVisibleByCamera(Bool visible)
+	{
+		m_bits.enableBits(Flag::VISIBLE_CAMERA, visible);
+	}
+
+	/// Check if visible by camera
+	Bool getVisibleByCamera() const
+	{
+		return m_bits.bitsEnabled(Flag::VISIBLE_CAMERA);
 	}
 
 	/// @name SceneComponent overrides
@@ -121,7 +109,19 @@ public:
 	/// @}
 
 private:
+	/// Spatial flags
+	enum class Flag: U8
+	{
+		NONE = 0,
+		VISIBLE_CAMERA = 1 << 1,
+		VISIBLE_LIGHT = 1 << 2,
+		VISIBLE_ANY = VISIBLE_CAMERA | VISIBLE_LIGHT,
+		MARKED_FOR_UPDATE = 1 << 3
+	};
+	ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(Flag, friend)
+
 	const CollisionShape* m_shape;
+	Bitset<Flag> m_bits;
 	Aabb m_aabb; ///< A faster shape
 	Vec4 m_origin = Vec4(MAX_F32, MAX_F32, MAX_F32, 0.0);
 	List<Sector*> m_sectorInfo;

+ 3 - 1
shaders/Tonemapping.glsl

@@ -54,7 +54,9 @@ vec3 tonemapUncharted2(in vec3 color)
 vec3 tonemap(in vec3 color, in float avgLum, in float threshold)
 {
 	vec3 c = computeExposedColor(color, avgLum, threshold);
-	return tonemapReinhard(c, 1.0);
+	//float saturation = clamp(avgLum, 0.0, 1.0);
+	float saturation = 1.0;
+	return tonemapReinhard(c, saturation);
 	//return tonemapUncharted2(c);
 }
 

+ 20 - 1
src/renderer/Dbg.cpp

@@ -111,7 +111,7 @@ Error Dbg::run(CommandBufferPtr& cmdb)
 
 	(void)err;
 
-	if(1)
+	if(0)
 	{
 		PhysicsDebugDrawer phyd(m_drawer);
 
@@ -186,4 +186,23 @@ Error Dbg::run(CommandBufferPtr& cmdb)
 	return m_drawer->flush();
 }
 
+//==============================================================================
+Bool Dbg::getDepthTestEnabled() const
+{
+	return m_drawer->getDepthTestEnabled();
+}
+
+//==============================================================================
+void Dbg::setDepthTestEnabled(Bool enable)
+{
+	m_drawer->setDepthTestEnabled(enable);
+}
+
+//==============================================================================
+void Dbg::switchDepthTestEnabled()
+{
+	Bool enabled = m_drawer->getDepthTestEnabled();
+	m_drawer->setDepthTestEnabled(!enabled);
+}
+
 } // end namespace anki

+ 13 - 3
src/renderer/DebugDrawer.cpp

@@ -57,7 +57,10 @@ Error DebugDrawer::create(Renderer* r)
 	init.m_shaders[U(ShaderType::VERTEX)] = m_vert->getGrShader();
 	init.m_shaders[U(ShaderType::FRAGMENT)] = m_frag->getGrShader();
 
-	m_ppline.create(&gl, init);
+	m_pplineLinesDepth.create(&gl, init);
+
+	init.m_depthStencil.m_depthCompareFunction = CompareOperation::ALWAYS;
+	m_pplineLinesNoDepth.create(&gl, init);
 
 	m_vertBuff.create(&gl, GL_ARRAY_BUFFER, nullptr,
 		sizeof(m_clientLineVerts), GL_DYNAMIC_STORAGE_BIT);
@@ -159,7 +162,14 @@ Error DebugDrawer::flushInternal(GLenum primitive)
 
 	m_vertBuff.write(m_cmdb, vertBuff, size, 0, 0, size);
 
-	m_ppline.bind(m_cmdb);
+	if(m_depthTestEnabled)
+	{
+		m_pplineLinesDepth.bind(m_cmdb);
+	}
+	else
+	{
+		m_pplineLinesNoDepth.bind(m_cmdb);
+	}
 
 	m_cmdb.bindVertexBuffer(0, m_vertBuff, 0);
 
@@ -534,7 +544,7 @@ void SceneDebugDrawer::draw(FrustumComponent& fr) const
 //==============================================================================
 void SceneDebugDrawer::draw(SpatialComponent& x) const
 {
-	if(!x.bitsEnabled(SpatialComponent::Flag::VISIBLE_CAMERA))
+	if(!x.getVisibleByCamera())
 	{
 		return;
 	}

+ 6 - 10
src/scene/SpatialComponent.cpp

@@ -11,13 +11,9 @@
 namespace anki {
 
 //==============================================================================
-SpatialComponent::SpatialComponent(
-	SceneNode* node,
-	const CollisionShape* shape,
-	Flag flags)
-:	SceneComponent(Type::SPATIAL, node),
-	Bitset<Flag>(flags),
-	m_shape(shape)
+SpatialComponent::SpatialComponent(SceneNode* node, const CollisionShape* shape)
+	: SceneComponent(Type::SPATIAL, node)
+	, m_shape(shape)
 {
 	ANKI_ASSERT(shape);
 	markForUpdate();
@@ -32,14 +28,14 @@ SpatialComponent::~SpatialComponent()
 //==============================================================================
 Error SpatialComponent::update(SceneNode&, F32, F32, Bool& updated)
 {
-	disableBits(Flag::VISIBLE_ANY);
+	m_bits.disableBits(Flag::VISIBLE_ANY);
 
-	updated = bitsEnabled(Flag::MARKED_FOR_UPDATE);
+	updated = m_bits.bitsEnabled(Flag::MARKED_FOR_UPDATE);
 	if(updated)
 	{
 		m_shape->computeAabb(m_aabb);
 		getSceneGraph().getSectorGroup().spatialUpdated(this);
-		disableBits(Flag::MARKED_FOR_UPDATE);
+		m_bits.disableBits(Flag::MARKED_FOR_UPDATE);
 	}
 
 	return ErrorCode::NONE;

+ 1 - 3
src/scene/Visibility.cpp

@@ -225,9 +225,7 @@ void VisibilityTestTask::test(FrustumComponent& testedFrc,
 				ANKI_ASSERT(spIdx < MAX_U8);
 				sps[count++] = SpatialTemp{&sp, static_cast<U8>(spIdx)};
 
-				/*sp.enableBits(testedNodeShadowCaster
-					? SpatialComponent::Flag::VISIBLE_LIGHT
-					: SpatialComponent::Flag::VISIBLE_CAMERA);*/
+				sp.setVisibleByCamera(true);
 			}
 
 			++spIdx;