瀏覽代碼

Refactoring lights, cameras and frustum. Removing obsolete SMO

Panagiotis Christopoulos Charitos 13 年之前
父節點
當前提交
59a33b46c4

+ 1 - 1
include/anki/collision/Frustum.h

@@ -95,7 +95,7 @@ public:
 	/// the @a trf, it just replaces it
 	virtual void setTransform(const Transform& trf) = 0;
 
-public: // XXX
+protected:
 	/// @name Viewing variables
 	/// @{
 	F32 near = 0.0;

+ 3 - 1
include/anki/renderer/Is.h

@@ -8,13 +8,15 @@
 #include "anki/gl/Gl.h"
 #include "anki/math/Math.h"
 #include "anki/renderer/Sm.h"
-#include "anki/renderer/Smo.h"
 #include "anki/util/StdTypes.h"
 #include "anki/util/Array.h"
 #include "anki/core/Timestamp.h"
+#include "anki/collision/Plane.h"
 
 namespace anki {
 
+class Camera;
+class PerspectiveCamera;
 class PointLight;
 class SpotLight;
 struct ShaderPointLights;

+ 0 - 54
include/anki/renderer/Smo.h

@@ -1,54 +0,0 @@
-#ifndef ANKI_RENDERER_SMO_H
-#define ANKI_RENDERER_SMO_H
-
-#include "anki/renderer/RenderingPass.h"
-#include "anki/resource/Resource.h"
-#include "anki/gl/Vao.h"
-#include "anki/scene/Camera.h"
-#include <array>
-
-namespace anki {
-
-class PointLight;
-class SpotLight;
-
-/// Stencil masking optimizations
-class Smo: public RenderingPass
-{
-public:
-	Smo(Renderer* r_)
-		: RenderingPass(r_)
-	{}
-
-	~Smo();
-
-	void init(const RendererInitializer& initializer);
-	void run(const PointLight& light);
-	void run(const SpotLight& light);
-
-private:
-	/// XXX
-	struct Geom
-	{
-		Geom();
-		~Geom();
-
-		MeshResourcePointer mesh;
-		Vao vao;
-	};
-
-	Geom sphereGeom;
-
-	/// An array of geometry stuff. For perspective cameras the shape is a
-	/// pyramid, see the blend file with the vertex positions
-	std::array<Geom, Camera::CT_COUNT> camGeom;
-
-	ShaderProgramResourcePointer sProg;
-
-	static void setupGl(bool inside);
-	static void restoreGl(bool inside);
-};
-
-} // end namespace anki
-
-#endif

+ 72 - 48
include/anki/scene/Camera.h

@@ -13,7 +13,8 @@ namespace anki {
 /// @{
 
 /// Camera SceneNode interface class
-class Camera: public SceneNode, public Movable, public Spatial
+class Camera: public SceneNode, public Movable, public Spatial, 
+	public Frustumable
 {
 public:
 	/// @note Don't EVER change the order
@@ -29,9 +30,9 @@ public:
 	Camera(CameraType type_,
 		const char* name, Scene* scene, // SceneNode
 		uint movableFlags, Movable* movParent, // Movable
-		Frustum* frustum) // Spatial
+		Frustum* frustum) // Spatial & Frustumable
 		: SceneNode(name, scene), Movable(movableFlags, movParent, *this),
-			Spatial(frustum), type(type_)
+			Spatial(frustum), Frustumable(frustum), type(type_)
 	{}
 
 	virtual ~Camera();
@@ -85,6 +86,12 @@ public:
 		return this;
 	}
 
+	/// Override SceneNode::getFrustumable()
+	Frustumable* getFrustumable()
+	{
+		return this;
+	}
+
 	/// Override SceneNode::frameUpdate
 	void frameUpdate(float prevUpdateTime, float crntTime, int frame)
 	{
@@ -125,7 +132,7 @@ private:
 };
 
 /// Perspective camera
-class PerspectiveCamera: public Camera, public PerspectiveFrustumable
+class PerspectiveCamera: public Camera
 {
 public:
 	ANKI_HAS_SLOTS(PerspectiveCamera)
@@ -136,6 +143,8 @@ public:
 		uint movableFlags, Movable* movParent);
 	/// @}
 
+	/// @name Accessors
+	/// @{
 	float getNear() const
 	{
 		return frustum.getNear();
@@ -146,13 +155,30 @@ public:
 		return frustum.getFar();
 	}
 
-	/// @name SceneNode virtuals
-	/// @{
+	F32 getFovX() const
+	{
+		return frustum.getFovX();
+	}
+	void setFovX(F32 x)
+	{
+		frustumUpdate();
+		frustum.setFovX(x);
+	}
 
-	/// Override SceneNode::getFrustumable()
-	Frustumable* getFrustumable()
+	F32 getFovY() const
 	{
-		return this;
+		return frustum.getFovY();
+	}
+	void setFovY(F32 x)
+	{
+		frustumUpdate();
+		frustum.setFovY(x);
+	}
+
+	void setAll(F32 fovX_, F32 fovY_, F32 near_, F32 far_)
+	{
+		frustum.setAll(fovX_, fovY_, near_, far_);
+		frustumUpdate();
 	}
 	/// @}
 
@@ -173,34 +199,23 @@ public:
 	}
 	/// @}
 
-	/// @name Frustumable virtuals
-	/// @{
+private:
+	PerspectiveFrustum frustum;
 
-	/// Overrides Frustumable::frustumUpdate(). Calculate the projection
-	/// matrix
+	/// Called when something changes in the frustum
 	void frustumUpdate()
 	{
-		Frustumable::frustumUpdate();
+		frustumableMarkUpdated();
+
 		projectionMat = frustum.calculateProjectionMatrix();
 		invProjectionMat = projectionMat.getInverse();
 		updateViewProjectionMatrix();
 		spatialMarkUpdated();
 	}
-	/// @}
-
-private:
-	PerspectiveFrustum frustum;
-
-	/// Called when the property changes
-	void updateFrustumSlot(const PerspectiveFrustum&)
-	{
-		frustumUpdate();
-	}
-	ANKI_SLOT(updateFrustumSlot, const PerspectiveFrustum&)
 };
 
 /// Orthographic camera
-class OrthographicCamera: public Camera, public OrthographicFrustumable
+class OrthographicCamera: public Camera
 {
 public:
 	ANKI_HAS_SLOTS(OrthographicCamera)
@@ -211,23 +226,41 @@ public:
 		uint movableFlags, Movable* movParent);
 	/// @}
 
-	float getNear() const
+	/// @name Accessors
+	/// @{
+	F32 getNear() const
 	{
 		return frustum.getNear();
 	}
 
-	float getFar() const
+	F32 getFar() const
 	{
 		return frustum.getFar();
 	}
 
-	/// @name SceneNode virtuals
-	/// @{
+	F32 getLeft() const
+	{
+		return frustum.getLeft();
+	}
 
-	/// Override SceneNode::getFrustumable()
-	Frustumable* getFrustumable()
+	F32 getRight() const
 	{
-		return this;
+		return frustum.getRight();
+	}
+
+	F32 getBottom() const
+	{
+		return frustum.getBottom();
+	}
+
+	F32 getTop() const
+	{
+		return frustum.getTop();
+	}
+
+	void setAll(F32 left, F32 right, F32 near, F32 far, F32 top, F32 bottom)
+	{
+		frustum.setAll(left, right, near, far, top, bottom);
 	}
 	/// @}
 
@@ -247,28 +280,19 @@ public:
 	}
 	/// @}
 
-	/// @name Frustumable virtuals
-	/// @{
+private:
+	OrthographicFrustum frustum;
 
-	/// Overrides Frustumable::frustumUpdate(). Calculate the projection
-	/// matrix
+	/// Called when something changes in the frustum
 	void frustumUpdate()
 	{
-		Frustumable::frustumUpdate();
+		frustumableMarkUpdated();
+
 		projectionMat = frustum.calculateProjectionMatrix();
 		invProjectionMat = projectionMat.getInverse();
 		updateViewProjectionMatrix();
+		spatialMarkUpdated();
 	}
-	/// @}
-
-private:
-	OrthographicFrustum frustum;
-
-	void updateFrustumSlot(const OrthographicFrustum&)
-	{
-		frustumUpdate();
-	}
-	ANKI_SLOT(updateFrustumSlot, const OrthographicFrustum&)
 };
 /// @}
 

+ 0 - 156
include/anki/scene/Frustumable.h

@@ -30,26 +30,6 @@ public:
 		return *frustum;
 	}
 
-	F32 getNear() const
-	{
-		return frustum->getNear();
-	}
-	void setNear(const F32 x)
-	{
-		frustum->setNear(x);
-		frustumUpdate();
-	}
-
-	F32 getFar() const
-	{
-		return frustum->getFar();
-	}
-	void setFar(const F32 x)
-	{
-		frustum->setFar(x);
-		frustumUpdate();
-	}
-
 	const VisibilityInfo& getVisibilityInfo() const
 	{
 		return vinfo;
@@ -65,12 +45,6 @@ public:
 	}
 	/// @}
 
-	/// Called when a frustum parameter changes
-	virtual void frustumUpdate()
-	{
-		frustumableMarkUpdated();
-	}
-
 	void frustumableMarkUpdated()
 	{
 		timestamp = Timestamp::getTimestamp();
@@ -96,136 +70,6 @@ private:
 	U32 timestamp = Timestamp::getTimestamp();
 };
 
-/// Perspective prustumable interface for scene nodes
-class PerspectiveFrustumable: public Frustumable
-{
-public:
-	/// @name Constructors
-	/// @{
-
-	/// Pass the frustum here so we can avoid the virtuals
-	PerspectiveFrustumable(PerspectiveFrustum* fr)
-		: Frustumable(fr)
-	{}
-	/// @}
-
-	/// @name Accessors
-	/// @{
-	F32 getFovX() const
-	{
-		return get().getFovX();
-	}
-	void setFovX(F32 ang)
-	{
-		get().setFovX(ang);
-		frustumUpdate();
-	}
-
-	F32 getFovY() const
-	{
-		return get().getFovY();
-	}
-	void setFovY(F32 ang)
-	{
-		get().setFovY(ang);
-		frustumUpdate();
-	}
-
-	/// Set all the parameters and recalculate the planes and shape
-	void setAll(F32 fovX_, F32 fovY_, F32 near_, F32 far_)
-	{
-		get().setAll(fovX_, fovY_, near_, far_);
-		frustumUpdate();
-	}
-	/// @}
-
-private:
-	PerspectiveFrustum& get()
-	{
-		return *static_cast<PerspectiveFrustum*>(frustum);
-	}
-	const PerspectiveFrustum& get() const
-	{
-		return *static_cast<const PerspectiveFrustum*>(frustum);
-	}
-};
-
-/// Orthographic prustumable interface for scene nodes
-class OrthographicFrustumable: public Frustumable
-{
-public:
-	/// @name Constructors
-	/// @{
-
-	/// Pass the frustum here so we can avoid the virtuals
-	OrthographicFrustumable(OrthographicFrustum* fr)
-		: Frustumable(fr)
-	{}
-	/// @}
-
-	/// @name Accessors
-	/// @{
-	F32 getLeft() const
-	{
-		return get().getLeft();
-	}
-	void setLeft(F32 f)
-	{
-		get().setLeft(f);
-		frustumUpdate();
-	}
-
-	F32 getRight() const
-	{
-		return get().getRight();
-	}
-	void setRight(F32 f)
-	{
-		get().setRight(f);
-		frustumUpdate();
-	}
-
-	F32 getTop() const
-	{
-		return get().getTop();
-	}
-	void setTop(F32 f)
-	{
-		get().setTop(f);
-		frustumUpdate();
-	}
-
-	F32 getBottom() const
-	{
-		return get().getBottom();
-	}
-	void setBottom(F32 f)
-	{
-		get().setBottom(f);
-		frustumUpdate();
-	}
-
-	/// Set all
-	void setAll(F32 left_, F32 right_, F32 near_,
-		F32 far_, F32 top_, F32 bottom_)
-	{
-		get().setAll(left_, right_, near_, far_, top_, bottom_);
-		frustumUpdate();
-	}
-	/// @}
-
-private:
-	OrthographicFrustum& get()
-	{
-		return *static_cast<OrthographicFrustum*>(frustum);
-	}
-	const OrthographicFrustum& get() const
-	{
-		return *static_cast<const OrthographicFrustum*>(frustum);
-	}
-};
-/// @}
-
 } // end namespace anki
 
 #endif

+ 40 - 40
include/anki/scene/Light.h

@@ -40,7 +40,7 @@ public:
 	/// @{
 	Light(LightType t, // Light
 		const char* name, Scene* scene, // Scene
-		uint32_t movableFlags, Movable* movParent, // Movable
+		U32 movableFlags, Movable* movParent, // Movable
 		CollisionShape* cs); // Spatial
 	/// @}
 
@@ -111,7 +111,7 @@ public:
 	}
 
 	/// Override SceneNode::frameUpdate
-	void frameUpdate(float prevUpdateTime, float crntTime, int frame)
+	void frameUpdate(F32 prevUpdateTime, F32 crntTime, int frame)
 	{
 		SceneNode::frameUpdate(prevUpdateTime, crntTime, frame);
 	}
@@ -131,16 +131,16 @@ public:
 	/// @name Constructors/Destructor
 	/// @{
 	PointLight(const char* name, Scene* scene,
-		uint32_t movableFlags, Movable* movParent);
+		U32 movableFlags, Movable* movParent);
 	/// @}
 
 	/// @name Accessors
 	/// @{
-	float getRadius() const
+	F32 getRadius() const
 	{
 		return sphereW.getRadius();
 	}
-	void setRadius(const float x)
+	void setRadius(const F32 x)
 	{
 		sphereW.setRadius(x);
 		spatialMarkUpdated();
@@ -170,7 +170,7 @@ public:
 };
 
 /// Spot light
-class SpotLight: public Light, public PerspectiveFrustumable
+class SpotLight: public Light, public Frustumable
 {
 public:
 	ANKI_HAS_SLOTS(SpotLight)
@@ -178,7 +178,7 @@ public:
 	/// @name Constructors/Destructor
 	/// @{
 	SpotLight(const char* name, Scene* scene,
-		uint32_t movableFlags, Movable* movParent);
+		U32 movableFlags, Movable* movParent);
 	/// @}
 
 	/// @name Accessors
@@ -202,23 +202,40 @@ public:
 		return *tex;
 	}
 
-	float getFov() const
+	F32 getOuterAngle() const
 	{
-		return getFovX();
+		return frustum.getFovX();
 	}
-	void setFov(float x)
+	void setOuterAngle(F32 x)
 	{
-		setFovX(x);
-		setFovY(x);
+		frustum.setFovX(x);
+		frustum.setFovY(x);
+		cosOuterAngle = cos(x / 2.0);
+		frustumUpdate();
 	}
 
-	float getDistance() const
+	F32 getOuterAngleCos() const
 	{
-		return getFar();
+		return cosOuterAngle;
 	}
-	void setDistance(float f)
+
+	void setInnerAngle(F32 ang)
+	{
+		cosInnerAngle = cos(ang / 2.0);
+	}
+	F32 getInnerAngleCos() const
+	{
+		return cosInnerAngle;
+	}
+
+	F32 getDistance() const
 	{
-		setFar(f);
+		return frustum.getFar();
+	}
+	void setDistance(F32 f)
+	{
+		frustum.setFar(f);
+		frustumUpdate();
 	}
 
 	const PerspectiveFrustum& getFrustum() const
@@ -233,7 +250,7 @@ public:
 	/// Override SceneNode::getFrustumable()
 	Frustumable* getFrustumable()
 	{
-		return this;
+		return (getShadowEnabled()) ? this : nullptr;
 	}
 	/// @}
 
@@ -247,19 +264,7 @@ public:
 		Movable::movableUpdate();
 		frustum.setTransform(getWorldTransform());
 		viewMat = Mat4(getWorldTransform().getInverse());
-		spatialMarkUpdated();
-	}
-	/// @}
-
-	/// @name Frustumable virtuals
-	/// @{
 
-	/// Overrides Frustumable::frustumUpdate(). Calculate the projection
-	/// matrix
-	void frustumUpdate()
-	{
-		Frustumable::frustumUpdate();
-		projectionMat = frustum.calculateProjectionMatrix();
 		spatialMarkUpdated();
 	}
 	/// @}
@@ -274,21 +279,16 @@ private:
 	Mat4 projectionMat;
 	Mat4 viewMat;
 	TextureResourcePointer tex;
-	ReadWriteProperty<float>* fovProp; ///< Have it here for updates
-	ReadWriteProperty<float>* distProp; ///< Have it here for updates
+	F32 cosOuterAngle;
+	F32 cosInnerAngle;
 
-	void updateFar(const float& f)
+	void frustumUpdate()
 	{
-		frustum.setFar(f);
-	}
-	ANKI_SLOT(updateFar, const float&)
+		projectionMat = frustum.calculateProjectionMatrix();
 
-	void updateFov(const float& f)
-	{
-		frustum.setFovX(f);
-		frustum.setFovY(f);
+		spatialMarkUpdated();
+		frustumableMarkUpdated();
 	}
-	ANKI_SLOT(updateFov, const float&)
 };
 
 } // end namespace anki

+ 3 - 3
shaders/IsLpGeneric.glsl

@@ -191,14 +191,14 @@ void main()
 		vec3 pureColor = doPhong(fragPosVspace, normal, diffuseAndSpec.rgb, 
 			specularAll, slights[lightId].light);
 
-		vec4 lightDirAndAng = slights[lightId].lightDirection;
+		const vec4 lightDirAndAng = slights[lightId].lightDirection;
 
 		vec3 l = 
 			normalize(fragPosVspace - slights[lightId].light.posAndRadius.xyz);
 
 		float costheta = dot(l, lightDirAndAng.xyz);
-		float spotFactor = smoothstep(lightDirAndAng.w,
-			cos(0.75 / 10), costheta);
+		float spotFactor = smoothstep(slights[lightId].light.diffuseColor.w,
+			slights[lightId].light.specularColor.w, costheta);
 
 		fColor += pureColor * spotFactor;
 	}

+ 5 - 3
src/renderer/Is.cpp

@@ -480,12 +480,14 @@ void Is::writeLightUbo(ShaderSpotLights& shaderLights, U32 maxShaderLights,
 			cam->getViewMatrix());
 
 		slight.posAndRadius = Vec4(pos, light.getDistance());
-		slight.diffuseColor = light.getDiffuseColor();
-		slight.specularColor = light.getSpecularColor();
+		slight.diffuseColor = Vec4(light.getDiffuseColor().xyz(),
+			light.getOuterAngleCos());
+		slight.specularColor = Vec4(light.getSpecularColor().xyz(),
+			light.getInnerAngleCos());
 
 		Vec3 lightDir = -light.getWorldTransform().getRotation().getZAxis();
 		lightDir = cam->getViewMatrix().getRotationPart() * lightDir;
-		slight.lightDirection = Vec4(lightDir, cos(light.getFov() / 2.0));
+		slight.lightDirection = Vec4(lightDir, 0.0);
 		
 		static const Mat4 biasMat4(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 
 			0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);

+ 0 - 160
src/renderer/Smo.cpp

@@ -1,160 +0,0 @@
-#include "anki/renderer/Smo.h"
-#include "anki/renderer/Renderer.h"
-#include "anki/scene/Light.h"
-#include "anki/scene/Scene.h"
-#include "anki/resource/Mesh.h"
-
-namespace anki {
-
-//==============================================================================
-
-static const float THRESHOLD = 0.2;
-
-//==============================================================================
-Smo::Geom::Geom()
-{}
-
-//==============================================================================
-Smo::Geom::~Geom()
-{}
-
-//==============================================================================
-Smo::~Smo()
-{}
-
-//==============================================================================
-void Smo::init(const RendererInitializer& /*initializer*/)
-{
-	sProg.load("shaders/IsSmo.glsl");
-
-	// Geometry stuff
-	//
-
-	// Sphere
-	sphereGeom.mesh.load("engine-rsrc/sphere.mesh");
-	sphereGeom.vao.create();
-	sphereGeom.vao.attachArrayBufferVbo(
-		*sphereGeom.mesh->getVbo(Mesh::VBO_POSITIONS),
-		sProg->findAttributeVariable("position"), 3, GL_FLOAT,
-		GL_FALSE, 0, NULL);
-	sphereGeom.vao.attachElementArrayBufferVbo(
-		*sphereGeom.mesh->getVbo(Mesh::VBO_INDICES));
-
-	// Cameras
-	std::array<const char*, Camera::CT_COUNT> files = {{
-		"engine-rsrc/pyramid.mesh", "engine-rsrc/cube.mesh"}};
-
-	for(int i = 0; i < Camera::CT_COUNT; i++)
-	{
-		camGeom[i].mesh.load(files[i]);
-		camGeom[i].vao.create();
-		camGeom[i].vao.attachArrayBufferVbo(
-			*camGeom[i].mesh->getVbo(Mesh::VBO_POSITIONS),
-			sProg->findAttributeVariable("position"), 3, GL_FLOAT,
-			GL_FALSE, 0, NULL);
-		camGeom[i].vao.attachElementArrayBufferVbo(
-			*camGeom[i].mesh->getVbo(Mesh::VBO_INDICES));
-	}
-}
-
-//==============================================================================
-void Smo::setupGl(bool inside)
-{
-	glStencilFunc(GL_ALWAYS, 0x1, 0x1);
-	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-	glClear(GL_STENCIL_BUFFER_BIT);
-
-	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_REPLACE, GL_KEEP);
-	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_ZERO, GL_KEEP);
-
-	//glCullFace(GL_FRONT);
-	glDisable(GL_CULL_FACE);
-	//glDepthFunc(GL_GEQUAL);
-
-	GlStateSingleton::get().enable(GL_DEPTH_TEST);
-}
-
-//==============================================================================
-void Smo::restoreGl(bool inside)
-{
-	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-	glStencilFunc(GL_EQUAL, 0x1, 0x1);
-
-	//glDepthFunc(GL_LESS);
-	//glCullFace(GL_BACK);
-	glEnable(GL_CULL_FACE);
-}
-
-//==============================================================================
-void Smo::run(const PointLight& light)
-{
-	// set GL state
-	const Camera& cam = r->getScene().getActiveCamera();
-	const Vec3& o = light.getWorldTransform().getOrigin();
-	const Vec3& c = cam.getWorldTransform().getOrigin();
-	bool inside =  (o - c).getLength() <=
-		(light.getRadius() + cam.getNear() + THRESHOLD);
-	setupGl(inside);
-
-	// set shared prog
-	static const float SCALE = 1.0; // we scale the sphere a little
-	sProg->bind();
-	Mat4 modelMat = Mat4(light.getWorldTransform().getOrigin(),
-	Mat3::getIdentity(), light.getRadius() * SCALE);
-	Mat4 trf = cam.getViewProjectionMatrix() * modelMat;
-	sProg->findUniformVariable("modelViewProjectionMat").set(trf);
-
-	// render sphere to the stencil buffer
-	sphereGeom.vao.bind();
-	glDrawElements(GL_TRIANGLES, sphereGeom.mesh->getIndicesNumber(0),
-		GL_UNSIGNED_SHORT, 0);
-
-	// Render again
-
-
-	// restore GL
-	restoreGl(inside);
-
-}
-
-//==============================================================================
-void Smo::run(const SpotLight& light)
-{
-	const Camera& cam = r->getScene().getActiveCamera();
-	const Vec3& origin = cam.getWorldTransform().getOrigin();
-	float radius = cam.getNear() + THRESHOLD;
-	bool inside =  light.insideFrustum(Sphere(origin, radius));
-
-	// set GL state
-	setupGl(inside);
-
-	// Calc the camera shape scale matrix
-	Mat4 localMat(Mat4::getIdentity());
-
-	// Scale in x
-	localMat(0, 0) = tan(light.getFovX() / 2.0) * light.getFar();
-	// Scale in y
-	localMat(1, 1) = tan(light.getFovY() / 2.0) * light.getFar();
-	localMat(2, 2) = light.getFar(); // Scale in z
-
-	const Geom& cg = camGeom[0];
-
-	// Setup the sprog
-	sProg->bind();
-	Mat4 modelMat = Mat4(light.getWorldTransform());
-
-	Mat4 trf = cam.getViewProjectionMatrix() * modelMat * localMat;
-	sProg->findUniformVariable("modelViewProjectionMat").set(trf);
-
-	// Render
-	//
-	cg.vao.bind();
-	glDrawElements(GL_TRIANGLES, cg.mesh->getIndicesNumber(0),
-		GL_UNSIGNED_SHORT, 0);
-
-	// restore GL state
-	restoreGl(inside);
-}
-
-} // end namespace anki

+ 4 - 20
src/scene/Camera.cpp

@@ -31,16 +31,8 @@ void Camera::lookAtPoint(const Vec3& point)
 PerspectiveCamera::PerspectiveCamera(const char* name, Scene* scene,
 	uint movableFlags, Movable* movParent)
 	: Camera(CT_PERSPECTIVE, name, scene, movableFlags, movParent, 
-		&frustum), PerspectiveFrustumable(&frustum)
-{
-	Property<PerspectiveFrustum>* prop =
-		new ReadWritePointerProperty<PerspectiveFrustum>("frustum", 
-		&frustum);
-
-	addNewProperty(prop);
-
-	ANKI_CONNECT(prop, valueChanged, this, updateFrustumSlot);
-}
+		&frustum)
+{}
 
 //==============================================================================
 // OrthographicCamera                                                          =
@@ -50,15 +42,7 @@ PerspectiveCamera::PerspectiveCamera(const char* name, Scene* scene,
 OrthographicCamera::OrthographicCamera(const char* name, Scene* scene,
 	uint movableFlags, Movable* movParent)
 	: Camera(CT_ORTHOGRAPHIC, name, scene, movableFlags, movParent, 
-		&frustum), OrthographicFrustumable(&frustum)
-{
-	Property<OrthographicFrustum>* prop =
-		new ReadWritePointerProperty<OrthographicFrustum>("frustum", 
-		&frustum);
-
-	addNewProperty(prop);
-
-	ANKI_CONNECT(prop, valueChanged, this, updateFrustumSlot);
-}
+		&frustum)
+{}
 
 } // end namespace

+ 10 - 19
src/scene/Light.cpp

@@ -9,7 +9,7 @@ namespace anki {
 //==============================================================================
 Light::Light(LightType t, // Light
 	const char* name, Scene* scene, // Scene
-	uint32_t movableFlags, Movable* movParent, // Movable
+	U32 movableFlags, Movable* movParent, // Movable
 	CollisionShape* cs) // Spatial
 	: SceneNode(name, scene),
 		Movable(movableFlags, movParent, *this),
@@ -33,11 +33,11 @@ Light::~Light()
 
 //==============================================================================
 PointLight::PointLight(const char* name, Scene* scene,
-	uint32_t movableFlags, Movable* movParent)
+	U32 movableFlags, Movable* movParent)
 	: Light(LT_POINT, name, scene, movableFlags, movParent, &sphereW)
 {
-	float& r = sphereW.getRadius();
-	addNewProperty(new ReadWritePointerProperty<float>("radius", &r));
+	F32& r = sphereW.getRadius();
+	addNewProperty(new ReadWritePointerProperty<F32>("radius", &r));
 }
 
 //==============================================================================
@@ -46,27 +46,18 @@ PointLight::PointLight(const char* name, Scene* scene,
 
 //==============================================================================
 SpotLight::SpotLight(const char* name, Scene* scene,
-	uint32_t movableFlags, Movable* movParent)
+	U32 movableFlags, Movable* movParent)
 	: Light(LT_SPOT, name, scene, movableFlags, movParent, &frustum),
-		PerspectiveFrustumable(&frustum)
+		Frustumable(&frustum)
 {
-	// 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, updateFar);
+	const F32 ang = Math::toRad(45.0);
+	setOuterAngle(ang / 2.0);
+	const F32 dist = 1.0;
 
 	// Fix frustum
 	//
 	frustum.setAll(ang, ang, 0.1, dist);
+	frustumUpdate();
 }
 
 } // end namespace anki

+ 7 - 5
testapp/Main.cpp

@@ -102,15 +102,16 @@ void init()
 	}
 
 
-#if 0
+#if 1
 	SpotLight* spot = new SpotLight("spot0", &scene, Movable::MF_NONE, nullptr);
-	spot->setFov(Math::toRad(45.0));
+	spot->setOuterAngle(Math::toRad(45.0));
+	spot->setInnerAngle(Math::toRad(15.0));
 	spot->setLocalTransform(Transform(Vec3(1.3, 4.3, 3.0),
 		Mat3::getIdentity(), 1.0));
 	spot->setDiffuseColor(Vec4(1.0));
 	spot->setSpecularColor(Vec4(1.0));
 	spot->loadTexture("gfx/lights/flashlight.tga");
-	spot->setDistance(20.0);
+	spot->setDistance(30.0);
 	spot->setShadowEnabled(true);
 #endif
 
@@ -216,7 +217,8 @@ void mainLoopExtra()
 
 	if(in.getKey(SDL_SCANCODE_P) == 1)
 	{
-		SceneSingleton::get().getActiveCamera().getFrustumable()->setFar(250.0);
+		/*SceneSingleton::get().getActiveCamera().
+			getFrustumable()->getFrustum().setFar(250.0);*/
 	}
 
 	if(in.getKey(SDL_SCANCODE_UP)) mover->rotateLocalX(ang);
@@ -278,7 +280,7 @@ void mainLoop()
 
 		// Sleep
 		//
-#if 0
+#if 1
 		timer.stop();
 		if(timer.getElapsedTime() < AppSingleton::get().getTimerTick())
 		{