Kaynağa Gözat

Reconstructing light

Panagiotis Christopoulos Charitos 13 yıl önce
ebeveyn
işleme
0ab10cafaf
4 değiştirilmiş dosya ile 122 ekleme ve 50 silme
  1. 27 18
      anki/scene/Light.cpp
  2. 83 32
      anki/scene/Light.h
  3. 1 0
      anki/scene/Property.cpp
  4. 11 0
      anki/scene/SceneNode.h

+ 27 - 18
anki/scene/Light.cpp

@@ -18,8 +18,12 @@ Light::Light(LightType t, const char* fmtl, // Light
 		Movable(movableFlags, movParent, *this),
 		Spatial(cs), type(t)
 {
-	mtl.load(fmtl);
-	Renderable::init(*this);
+	addNewProperty(new ReadWritePointerProperty<Vec4>("color", &color));
+
+	addNewProperty(
+		new ReadWritePointerProperty<Vec4>("specularColor", &specColor));
+
+	addNewProperty(new ReadWritePointerProperty<bool>("shadow", &shadow));
 }
 
 
@@ -38,12 +42,11 @@ PointLight::PointLight(const char* fmtl,
 	uint movableFlags, Movable* movParent)
 	: Light(LT_POINT, fmtl, name, scene, movableFlags, movParent, &sphereW)
 {
-	PropertyBase& pbase = findPropertyBaseByName("radius");
-	Property<float>& prop = pbase.upCast<Property<float> >();
-	ANKI_CONNECT(&prop, valueChanged, this, updateRadius);
-
 	sphereL.setCenter(Vec3(0.0));
-	sphereL.setRadius(prop.getValue());
+	sphereL.setRadius(1.0);
+
+	float& r = sphereL.getRadius();
+	addNewProperty(new ReadWritePointerProperty<float>("radius", &r));
 }
 
 
@@ -58,17 +61,23 @@ SpotLight::SpotLight(const char* fmtl,
 	: Light(LT_SPOT, fmtl, name, scene, movableFlags, movParent, &frustum),
 		Frustumable(&frustum)
 {
-	PropertyBase& pbase = findPropertyBaseByName("radius");
-	Property<float>& prop = pbase.upCast<Property<float> >();
-	ANKI_CONNECT(&prop, valueChanged, this, updateZFar);
-
-	float dfltAng = 45.0;
-	ReadWriteProperty<float>* angProp =
-		new ReadWriteProperty<float>("angle", dfltAng);
-	addNewProperty(angProp);
-	ANKI_CONNECT(angProp, valueChanged, this, updateFov);
-
-	frustum.setAll(dfltAng, dfltAng, 0.1, prop.getValue());
+	// Fov
+	//
+	float ang = Math::toRad(45.0);
+	fovProp = new ReadWriteProperty<float>("fov", ang);
+	addNewProperty(fovProp);
+	ANKI_CONNECT(fovProp, valueChanged, this, updateFov);
+
+	// Distance
+	//
+	float dist = 10.0;
+	distProp = new ReadWriteProperty<float>("distance", dist);
+	addNewProperty(distProp);
+	ANKI_CONNECT(distProp, valueChanged, this, updateZFar);
+
+	// Fix frustum
+	//
+	frustum.setAll(ang, ang, 0.1, dist);
 }
 
 

+ 83 - 32
anki/scene/Light.h

@@ -3,7 +3,6 @@
 
 #include "anki/scene/SceneNode.h"
 #include "anki/scene/Movable.h"
-#include "anki/scene/Renderable.h"
 #include "anki/scene/Frustumable.h"
 #include "anki/scene/Spatial.h"
 #include "anki/resource/Material.h"
@@ -29,8 +28,7 @@ namespace anki {
 /// Specular intensity of light:    Sl
 /// Specular intensity of material: Sm
 /// @endcode
-class Light: public SceneNode, public Movable, public Renderable,
-	public Spatial
+class Light: public SceneNode, public Movable, public Spatial
 {
 public:
 	enum LightType
@@ -56,55 +54,77 @@ public:
 	{
 		return type;
 	}
-	/// @}
 
-	/// @name SceneNode virtuals
-	/// @{
-	Movable* getMovable()
+	const Vec4& getColor() const
 	{
-		return this;
+		return color;
 	}
-
-	Renderable* getRenderable()
+	Vec4& getColor()
 	{
-		return this;
+		return color;
+	}
+	void setColor(const Vec4& x)
+	{
+		color = x;
 	}
 
-	Spatial* getSpatial()
+	const Vec4& getSpecularColor() const
 	{
-		return this;
+		return specColor;
+	}
+	Vec4& getSpecularColor()
+	{
+		return specColor;
+	}
+	void setSpecularColor(const Vec4& x)
+	{
+		specColor = x;
 	}
 
-	/// Override SceneNode::frameUpdate
-	void frameUpdate(float prevUpdateTime, float crntTime, int frame)
+	bool getShadow() const
 	{
-		SceneNode::frameUpdate(prevUpdateTime, crntTime, frame);
-		Movable::update();
+		return shadow;
+	}
+	bool& getShadow()
+	{
+		return shadow;
+	}
+	void setShadow(const bool x)
+	{
+		shadow = x;
 	}
 	/// @}
 
-	/// @name Renderable virtuals
+	/// @name SceneNode virtuals
 	/// @{
-	const ModelPatchBase& getModelPatchBase() const
+	Movable* getMovable()
 	{
-		ANKI_ASSERT(0 && "Lights don't support it");
-		throw ""; // Make the compiler not to complain about return val
+		return this;
 	}
 
-	Material& getMaterial()
+	Spatial* getSpatial()
 	{
-		return *mtl;
+		return this;
 	}
 
 	Light* getLight()
 	{
 		return this;
 	}
+
+	/// Override SceneNode::frameUpdate
+	void frameUpdate(float prevUpdateTime, float crntTime, int frame)
+	{
+		SceneNode::frameUpdate(prevUpdateTime, crntTime, frame);
+		Movable::update();
+	}
 	/// @}
 
 private:
 	LightType type;
-	MaterialResourcePointer mtl;
+	Vec4 color;
+	Vec4 specColor;
+	bool shadow;
 };
 
 
@@ -112,8 +132,6 @@ private:
 class PointLight: public Light
 {
 public:
-	ANKI_OBSERVING(PointLight)
-
 	/// @name Constructors/Destructor
 	/// @{
 	PointLight(const char* fmtl,
@@ -121,6 +139,22 @@ public:
 		uint movableFlags, Movable* movParent);
 	/// @}
 
+	/// @name Accessors
+	/// @{
+	float getRadius() const
+	{
+		return sphereL.getRadius();
+	}
+	float& getRadius()
+	{
+		return sphereL.getRadius();
+	}
+	void setRadius(const float x)
+	{
+		sphereL.setRadius(x);
+	}
+	/// @}
+
 	/// @name Movable virtuals
 	/// @{
 
@@ -136,12 +170,6 @@ public:
 public:
 	Sphere sphereW;
 	Sphere sphereL;
-
-	void updateRadius(const float& r)
-	{
-		sphereL.setRadius(r);
-	}
-	ANKI_SLOT(updateRadius, const float&)
 };
 
 
@@ -158,6 +186,27 @@ public:
 		uint movableFlags, Movable* movParent);
 	/// @}
 
+	/// @name Accessors
+	/// @{
+	float getFov() const
+	{
+		return frustum.getFovX();
+	}
+	void setFov(float x)
+	{
+		fovProp->setValue(x);
+	}
+
+	float getDistance() const
+	{
+		return frustum.getFar();
+	}
+	void setDistance(float x)
+	{
+		distProp->setValue(x);
+	}
+	/// @}
+
 	/// @name Movable virtuals
 	/// @{
 
@@ -186,6 +235,8 @@ private:
 	PerspectiveFrustum frustum;
 	Mat4 projectionMat;
 	Mat4 viewMat;
+	ReadWriteProperty<float>* fovProp; ///< Have it here for updates
+	ReadWriteProperty<float>* distProp; ///< Have it here for updates
 
 	void updateZFar(const float& f)
 	{

+ 1 - 0
anki/scene/Property.cpp

@@ -11,6 +11,7 @@ namespace anki {
 
 
 template<> const uint Property<float>::TYPE_ID = __LINE__;
+template<> const uint Property<bool>::TYPE_ID = __LINE__;
 ANKI_DEFINE_PROPERTY_TYPE(Vec2)
 ANKI_DEFINE_PROPERTY_TYPE(Vec3)
 ANKI_DEFINE_PROPERTY_TYPE(OrthographicFrustum)

+ 11 - 0
anki/scene/SceneNode.h

@@ -14,6 +14,7 @@ class Movable;
 class Renderable;
 class Frustumable;
 class Spatial;
+class Light;
 
 
 /// @addtogroup Scene
@@ -66,6 +67,11 @@ public:
 	{
 		return nullptr;
 	}
+
+	virtual Light* getLight()
+	{
+		return nullptr;
+	}
 	/// @}
 
 	/// @name Accessors of components (const version)
@@ -89,6 +95,11 @@ public:
 	{
 		return const_cast<const Spatial*>(getSpatial());
 	}
+
+	const Light* getLight() const
+	{
+		return const_cast<const Light*>(getLight());
+	}
 	/// @}
 
 	/// This is called by the scene every frame after logic and before