Panagiotis Christopoulos Charitos 13 anos atrás
pai
commit
e029e00b92

+ 1 - 0
include/anki/gl/Gl.h

@@ -5,6 +5,7 @@
 #define ANKI_GL_GL_H
 
 #include "anki/gl/BufferObject.h"
+#include "anki/gl/Ubo.h"
 #include "anki/gl/Fbo.h"
 #include "anki/gl/GlException.h"
 #include "anki/gl/GlState.h"

+ 4 - 5
include/anki/gl/ShaderProgram.h

@@ -207,11 +207,10 @@ public:
 	}
 	void setBindingPoint(GLuint bp) const
 	{
-		if(bindingPoint != bp)
-		{
-			glUniformBlockBinding(progId, index, bp);
-			bindingPoint = bp;
-		}
+		// Don't try any opts with existing binding point. Binding points 
+		// should break
+		glUniformBlockBinding(progId, index, bp);
+		bindingPoint = bp;
 	}
 	/// @}
 

+ 18 - 0
include/anki/gl/Ubo.h

@@ -0,0 +1,18 @@
+#ifndef ANKI_GL_UBO_H
+#define ANKI_GL_UBO_H
+
+#include "anki/gl/BufferObject.h"
+
+namespace anki {
+
+/// @addtogroup gl
+/// @{
+	
+/// Uniform buffer object
+typedef BufferObject Ubo;
+
+/// @}
+
+} // end namespace anki
+
+#endif

+ 71 - 0
include/anki/renderer/Is.h

@@ -9,6 +9,7 @@
 #include "anki/math/Math.h"
 #include "anki/renderer/Sm.h"
 #include "anki/renderer/Smo.h"
+#include "anki/util/StdTypes.h"
 
 namespace anki {
 
@@ -35,6 +36,76 @@ public:
 	/// @}
 
 private:
+	enum LightSubType
+	{
+		LST_POINT,
+		LST_SPOT,
+		LST_SPOT_SHADOW
+	};
+
+	/// A screen tile
+	struct Tile
+	{
+		/// depth[0] = min depth, depth[1] = max depth
+		Vec2 depth;
+
+		/// Used for 2D light culling
+		/// @note The coords are in NDC
+		/// @note coords[0] is the bottom left coord, and the coords[1] the 
+		///       top right
+		Vec2 coords[2]; 
+
+		Vector<PointLight*> plights;
+		Vector<SpotLight*> slights;
+		Vector<SpotLight*> slightsShadow;
+		Ubo lightIndicesUbo;
+	};
+
+	static const U TILES_X_COUNT = 16;
+	static const U TILES_Y_COUNT = 16;
+
+	static const U MAX_LIGHTS_PER_TILE = 128;
+
+	static const U MAX_LIGHTS = 1024;
+
+	/// @note The [0][0] is the bottom left tile
+	Tile tiles[TILES_X_COUNT][TILES_Y_COUNT];
+
+	/// A texture of TILES_X_COUNT*TILES_Y_COUNT size and format RG16F. Used to
+	/// to fill the Tile::depth
+	Texture minMaxFai;
+
+	/// An FBO to write to the minMaxTex
+	Fbo minMaxTilerFbo;
+
+	/// Min max shader program
+	ShaderProgramResourcePointer minMaxPassSprog;
+
+	/// Project a sphere to a circle
+	static void projectShape(const Mat4& projectionMat, 
+		const Sphere& sphere, Vec2& circleCenter, F32& circleRadius);
+	/// Project a perspective frustum to a triangle
+	static void projectShape(const Mat4& projectionMat,
+		const PerspectiveFrustum& fr, std::array<Vec2, 3>& coords);
+
+	/// For intersecting of point lights
+	static Bool circleIntersects(const Tile& tile, const Vec2& circleCenter, 
+		F32 circleRadius);
+	/// For intersecting of spot lights
+	static Bool triangleIntersects(const Tile& tile, 
+		const std::array<Vec2, 3>& coords);
+
+	/// Fill the minMaxFai
+	void minMaxPass();
+
+	/// See if the light is inside the tile and if it is assign it to the tile
+	void cullLight(Tile& tile, Light& light);
+
+	/// Do the light culling
+	void tileCulling();
+
+	void initTiles();
+
 	Smo smo;
 	Sm sm;
 	Texture fai;

+ 3 - 3
include/anki/util/StdTypes.h

@@ -11,16 +11,16 @@ typedef int16_t I16;
 typedef int32_t I32;
 typedef int64_t I64;
 
-typedef int_fast32_t IFast;
+typedef int_fast32_t I; ///< Fast integer
 
 typedef uint8_t U8;
 typedef uint16_t U16;
 typedef uint32_t U32;
 typedef uint64_t U64;
 
-typedef uint_fast32_t UFast;
+typedef uint_fast32_t U; ///< fast unigned integer
 
-typedef size_t Size;
+typedef size_t PtrSize; ///< Like size_t
 
 typedef float F32;
 typedef double F64;

+ 39 - 0
src/renderer/Is.cpp

@@ -29,6 +29,45 @@ struct GeneralUniformBlock
 	PointLightUniformBlock light;
 };
 
+//==============================================================================
+void Is::initTiles()
+{
+	// FBO
+	Renderer::createFai(TILES_X_COUNT, TILES_Y_COUNT, GL_RGB32F, GL_RGB, 
+		GL_FLOAT, minMaxFai);
+	minMaxTilerFbo.create();
+	minMaxTilerFbo.setColorAttachments({&minMaxFai});
+	if(!minMaxTilerFbo.isComplete())
+	{
+		throw ANKI_EXCEPTION("minMaxTilerFbo creation failed");
+	}
+
+	// Shader program
+	std::string preproc = 
+		"#define TILES_X_COUNT " + std::to_string(TILES_X_COUNT) + "\n"
+		"#define TILES_Y_COUNT " + std::to_string(TILES_Y_COUNT) + "\n";
+	std::string filename = ShaderProgramResource::createSrcCodeToCache(
+		"shaders/IsMinMax.glsl", 
+		preproc.c_str());
+	minMaxPassSprog.load(filename.c_str());
+
+	// Tiles
+	F32 tileWidth = 1.0 / TILES_X_COUNT;
+	F32 tileHeight = 1.0 / TILES_Y_COUNT;
+
+	for(U i = 0; i < TILES_X_COUNT; i++)
+	{
+		for(U j = 0; j < TILES_Y_COUNT; j++)
+		{
+		}
+	}
+}
+
+//==============================================================================
+void Is::minMaxPass()
+{
+}
+
 //==============================================================================
 Is::Is(Renderer* r_)
 	: RenderingPass(r_), smo(r_), sm(r_)