Procházet zdrojové kódy

Lens flare WIP & fixing MacOS build

Panagiotis Christopoulos Charitos před 12 roky
rodič
revize
219cee35c8

+ 1 - 1
CMakeLists.txt

@@ -208,7 +208,7 @@ INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/anki/Config.h" DESTINATION "${INCLUDE
 INCLUDE_DIRECTORIES("extern/tinyxml2/include" "extern/lua" "extern/png" "extern/bullet" "include"
 	"${CMAKE_CURRENT_BINARY_DIR}")
 
-IF(ANKI_WINDOW_BACKEND STREQUAL "GLXX11")
+IF(ANKI_WINDOW_BACKEND STREQUAL "GLXX11" OR ANKI_WINDOW_BACKEND STREQUAL "MACOS")
 	INCLUDE_DIRECTORIES("extern/GLEW/include")
 ELSE()
 	INCLUDE_DIRECTORIES("extern/GLES3/include")

+ 8 - 0
include/anki/resource/ResourcePointer.h

@@ -70,15 +70,18 @@ public:
 
 	const Value* get() const
 	{
+		ANKI_ASSERT(hook != nullptr);
 		return hook->resource;
 	}
 	Value* get()
 	{
+		ANKI_ASSERT(hook != nullptr);
 		return hook->resource;
 	}
 
 	const std::string& getResourceName() const
 	{
+		ANKI_ASSERT(hook != nullptr);
 		return hook->uuid;
 	}
 	/// @}
@@ -105,6 +108,11 @@ public:
 		hook = &ResourceManagerSingleton::get().load(filename);
 	}
 
+	Bool isLoaded() const
+	{
+		return hook != nullptr;
+	}
+
 private:
 	/// Points to an element located in a container in the resource manager
 	Hook* hook = nullptr;

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

@@ -101,7 +101,7 @@ public:
 
 	Bool hasLensFlare() const
 	{
-		return lensFlareTex.get() != nullptr;
+		return lensFlareTex.isLoaded();
 	}
 
 	const Texture& getLensFlareTexture() const

+ 1 - 1
shaders/PpsLfPass.glsl

@@ -36,5 +36,5 @@ out vec3 fColor;
 
 void main()
 {
-	fColor = texture(images, vec3(vTexCoords.st, 0.0)).rgb;
+	fColor = texture(images, vTexCoords).rgb;
 }

+ 26 - 16
src/renderer/Lf.cpp

@@ -65,6 +65,12 @@ void Lf::run()
 	VisibilityTestResults& vi = *cam.getVisibilityTestResults();
 
 	// Iterate the lights and update the UBO
+	Array<Flare, 256> flareBuff; // XXX 256?
+	ANKI_ASSERT(
+		maxLensFlareCount * maxLightsWidthFlaresCount < flareBuff.size());
+
+	U count = 0;
+
 	for(auto it = vi.getLightsBegin(); it != vi.getLightsEnd(); ++it)
 	{
 		SceneNode& sn = *(*it).node;
@@ -75,33 +81,37 @@ void Lf::run()
 		{
 			continue;
 		}
-	}
 
-	// Update the UBO
-	{
-		SceneGraph& scene = r->getSceneGraph();
-		const Camera& cam = scene.getActiveCamera();
+		// Transform
+		Vec3 posworld = sn.getMovable()->getWorldTransform().getOrigin();
+		Vec4 posclip = cam.getViewProjectionMatrix() * Vec4(posworld, 1.0);
+		Vec2 posndc = (posclip.xyz() / posclip.w()).xy();
 
-		SceneNode& sn = scene.findSceneNode("vase_plight0");
-		Vec4 snPos = Vec4(sn.getMovable()->getWorldTransform().getOrigin(), 1.0);
-		snPos = cam.getViewProjectionMatrix() * snPos;
-		Vec2 posNdc = snPos.xy() / snPos.w();
+		Vec2 dir = -posndc;
+		F32 len = dir.getLength() * 2.0;
+		dir /= len;
 
-		Flare flare;
-		flare.pos = posNdc;
-		flare.scale = Vec2(0.1 * 3.0, r->getAspectRatio() * 0.1);
-		//flare.alpha = 0.2;
+		const Texture& tex = light.getLensFlareTexture();
+		const U depth = tex.getDepth();
 
-		flareDataUbo.write(&flare, 0, sizeof(Flare));
+		for(U d = 0; d < depth; d++)
+		{
+			flareBuff[count].pos = posndc + dir * (len * (d / (F32)depth));
+			flareBuff[count].scale = Vec2(0.1 * 3.0, r->getAspectRatio() * 0.1);
+			++count;
+		}
 	}
-	
+
+	flareDataUbo.write(&flareBuff[0], 0, sizeof(Flare) * count);
+
+	// Draw
 	drawProg->bind();
 	drawProg->findUniformVariable("images").set(*tex);
 	flareDataUbo.setBinding(0);
 
 	GlStateSingleton::get().enable(GL_BLEND);
 	GlStateSingleton::get().setBlendFunctions(GL_ONE, GL_ONE);
-	r->drawQuad();
+	r->drawQuadInstanced(tex->getDepth());
 }
 
 } // end namespace anki