Procházet zdrojové kódy

Soft particles seem to be working & refactoring

Panagiotis Christopoulos Charitos před 12 roky
rodič
revize
fc2b1c1562

+ 3 - 1
bench/Main.cpp

@@ -133,11 +133,13 @@ void initSubsystems()
 //#if ANKI_GL == ANKI_GL_ES
 #if 1
 	initializer.get("samples") = 1;
+	initializer.get("is.groundLightEnabled") = false;
 	initializer.get("is.maxPointLights") = 64;
 	initializer.get("is.maxPointLightsPerTile") = 4;
 	initializer.get("is.maxSpotLightsPerTile") = 4;
 	initializer.get("is.maxSpotTexLightsPerTile") = 4;
 	initializer.get("renderingQuality") = 0.5;
+	initializer.get("pps.hdr.renderingQuality") = 0.3;
 	initializer.get("maxTextureSize") = 1024;
 	initializer.get("mrt") = false;
 	initializer.get("pps.sharpen") = false;
@@ -172,7 +174,7 @@ void initScene()
 		1.0));
 	scene.setActiveCamera(cam);
 
-#if 0
+#if 1
 	AnimationResourcePointer anim;
 	anim.load("maps/sponza/animation_0.ankianim");
 	AnimationEvent* event;

+ 15 - 2
include/anki/renderer/Renderer.h

@@ -174,6 +174,17 @@ public:
 	{
 		return maxTextureSize;
 	}
+
+	const UVec2& getTilesCount() const
+	{
+		return tilesCount;
+	}
+
+	/// Get string to pass to the material shaders
+	const std::string& getShaderPostProcessorString() const
+	{
+		return shaderPostProcessorString;
+	}
 	/// @}
 
 	/// Init the renderer given an initialization class
@@ -250,8 +261,7 @@ private:
 	Bool8 isOffscreen; ///< Is offscreen renderer?
 	F32 renderingQuality; ///< Rendering quality. Relevant for offscreen 
 	U32 maxTextureSize; ///< Texture size limit. Just kept here.
-	U16 tilesXCount;
-	U16 tilesYCount;
+	UVec2 tilesCount;
 
 	/// @name For drawing a quad into the active framebuffer
 	/// @{
@@ -279,6 +289,9 @@ private:
 	RenderableDrawer sceneDrawer;
 
 	U framesNum; ///< Frame number
+
+	/// String to pass to the material shaders
+	std::string shaderPostProcessorString;
 };
 
 } // end namespace anki

+ 10 - 8
shaders/BsCommonFrag.glsl

@@ -38,17 +38,19 @@ void particleAlpha(in sampler2D tex, in float alpha)
 #endif
 
 #if defined(PASS_COLOR)
-#	define softness_DEFINED
-float softness(in sampler2D depthMap)
+#	define particleSoft_DEFINED
+void particleSoft(in sampler2D depthMap, in sampler2D tex, in float alpha)
 {
-	float depth = texture(depthMap, gl_FragCoord.xy / vec2(960.0, 540.0)).r;
+	const vec2 screenSize = 
+		vec2(1.0 / float(RENDERING_WIDTH), 1.0 / float(RENDERING_HEIGHT));
+	float depth = texture(depthMap, gl_FragCoord.xy * screenSize).r;
 
 	float delta = depth - gl_FragCoord.z;
-	
-	if (delta > 0)
-		return 1.0;
-	else
-		return 0.0;
+	float softalpha = clamp(delta * 100.0, 0.0, 1.0);
+
+	vec4 color = texture(tex, vTexCoord);
+	color.w *= alpha * softalpha;
+	writeFais(color);
 }
 #endif
 

+ 2 - 2
src/renderer/Is.cpp

@@ -806,8 +806,8 @@ void Is::lightPass()
 		}
 		/*if(spotLightsSize > 0)
 		{
-			lightsUbo.setBindingRange(SPOT_LIGHTS_BLOCK_BINDING, spotLightsOffset,
-				spotLightsSize);
+			lightsUbo.setBindingRange(SPOT_LIGHTS_BLOCK_BINDING, 
+				spotLightsOffset, spotLightsSize);
 		}
 		if(spotTexLightsSize > 0)
 		{

+ 11 - 0
src/renderer/Renderer.cpp

@@ -63,6 +63,8 @@ RendererInitializer::RendererInitializer()
 	newOption("renderingQuality", 1.0); // Applies only to MainRenderer
 	newOption("lodDistance", 10.0); // Distance that used to calculate the LOD
 	newOption("samples", 1);
+	newOption("tilesXCount", 16);
+	newOption("tilesYCount", 16);
 
 	if(GlStateCommonSingleton::get().getGpu() == GlStateCommon::GPU_ARM)
 	{
@@ -103,6 +105,8 @@ void Renderer::init(const RendererInitializer& initializer)
 	isOffscreen = initializer.get("offscreen");
 	renderingQuality = initializer.get("renderingQuality");
 	maxTextureSize = initializer.get("maxTextureSize");
+	tilesCount.x() = initializer.get("tilesXCount");
+	tilesCount.y() = initializer.get("tilesYCount");
 
 	// a few sanity checks
 	if(samples != 1 && samples != 4 && samples != 8 && samples != 16
@@ -135,6 +139,13 @@ void Renderer::init(const RendererInitializer& initializer)
 	quadVao.create();
 	quadVao.attachArrayBufferVbo(
 		&quadPositionsVbo, 0, 2, GL_FLOAT, false, 0, 0);
+
+	// Init the shaderPostProcessorString
+	std::stringstream ss;
+	ss << "#define USE_MRT " << (U)useMrt << "\n"
+		<< "#define RENDERING_WIDTH " << width << "\n"
+		<< "#define RENDERING_HEIGHT " << height << "\n";
+	shaderPostProcessorString = ss.str();
 }
 
 //==============================================================================

+ 49 - 41
src/renderer/Tiler.cpp

@@ -10,14 +10,6 @@
 
 namespace anki {
 
-//==============================================================================
-static const U TILES_X_COUNT = ANKI_RENDERER_TILES_X_COUNT;
-static const U TILES_Y_COUNT = ANKI_RENDERER_TILES_Y_COUNT;
-static const U TILES_COUNT = TILES_X_COUNT * TILES_Y_COUNT;
-
-typedef F32 
-	PixelArray[ANKI_RENDERER_TILES_Y_COUNT][ANKI_RENDERER_TILES_X_COUNT][2];
-
 //==============================================================================
 #define CHECK_PLANE_PTR(p_) \
 	ANKI_ASSERT(p_ < &tiler->allPlanes[tiler->allPlanes.size()]);
@@ -48,13 +40,14 @@ struct UpdatePlanesPerspectiveCameraJob: ThreadJob
 			const F32 n = cam->getNear();
 
 			F32 l = 2.0 * n * tan(fx / 2.0);
-			F32 l6 = l / TILES_X_COUNT;
+			F32 l6 = l / tiler->r->getTilesCount().x();
 			F32 o = 2.0 * n * tan(fy / 2.0);
-			F32 o6 = o / TILES_Y_COUNT;
+			F32 o6 = o / tiler->r->getTilesCount().y();
 
 			// First the top looking planes
 			choseStartEnd(
-				threadId, threadsCount, TILES_Y_COUNT - 1, start, end);
+				threadId, threadsCount, tiler->r->getTilesCount().y() - 1, 
+				start, end);
 
 			for(U i = start; i < end; i++)
 			{
@@ -67,7 +60,8 @@ struct UpdatePlanesPerspectiveCameraJob: ThreadJob
 
 			// Then the right looking planes
 			choseStartEnd(
-				threadId, threadsCount, TILES_X_COUNT - 1, start, end);
+				threadId, threadsCount, tiler->r->getTilesCount().x() - 1, 
+				start, end);
 
 			for(U j = start; j < end; j++)
 			{
@@ -84,7 +78,8 @@ struct UpdatePlanesPerspectiveCameraJob: ThreadJob
 
 			// First the top looking planes
 			choseStartEnd(
-				threadId, threadsCount, TILES_Y_COUNT - 1, start, end);
+				threadId, threadsCount, tiler->r->getTilesCount().y() - 1, 
+				start, end);
 
 			for(U i = start; i < end; i++)
 			{
@@ -95,7 +90,8 @@ struct UpdatePlanesPerspectiveCameraJob: ThreadJob
 
 			// Then the right looking planes
 			choseStartEnd(
-				threadId, threadsCount, TILES_X_COUNT - 1, start, end);
+				threadId, threadsCount, tiler->r->getTilesCount().x() - 1, 
+				start, end);
 
 			for(U j = start; j < end; j++)
 			{
@@ -111,14 +107,16 @@ struct UpdatePlanesPerspectiveCameraJob: ThreadJob
 		Renderer::calcPlanes(Vec2(cam->getNear(), cam->getFar()), rplanes);
 
 		choseStartEnd(
-			threadId, threadsCount, TILES_COUNT, start, end);
+			threadId, threadsCount, 
+			tiler->r->getTilesCount().x() * tiler->r->getTilesCount().y(), 
+			start, end);
 
 		Plane* nearPlanesW = tiler->nearPlanesW + start;
 		Plane* farPlanesW = tiler->farPlanesW + start;
 		for(U k = start; k < end; ++k)
 		{
-			U j = k % TILES_X_COUNT;
-			U i = k / TILES_X_COUNT;
+			U j = k % tiler->r->getTilesCount().x();
+			U i = k / tiler->r->getTilesCount().x();
 
 			// Calculate depth as you do it for the vertex position inside
 			// the shaders
@@ -150,7 +148,10 @@ struct UpdatePlanesPerspectiveCameraJob: ThreadJob
 		Plane& plane = tiler->planesI[i];
 		CHECK_PLANE_PTR(&plane);
 
-		a = Vec3(0.0, (I(i + 1) - I(TILES_Y_COUNT) / 2) * o6, -n);
+		a = Vec3(0.0, 
+			(I(i + 1) - I(tiler->r->getTilesCount().y()) / 2) * o6, 
+			-n);
+
 		b = Vec3(1.0, 0.0, 0.0).cross(a);
 		b.normalize();
 
@@ -165,7 +166,10 @@ struct UpdatePlanesPerspectiveCameraJob: ThreadJob
 		Plane& plane = tiler->planesJ[j];
 		CHECK_PLANE_PTR(&plane);
 
-		a = Vec3((I(j + 1) - I(TILES_X_COUNT) / 2) * l6, 0.0, -n);
+		a = Vec3((I(j + 1) - I(tiler->r->getTilesCount().x()) / 2) * l6, 
+			0.0, 
+			-n);
+
 		b = a.cross(Vec3(0.0, 1.0, 0.0));
 		b.normalize();
 
@@ -206,20 +210,20 @@ void Tiler::initInternal(Renderer* r_)
 	r = r_;
 
 	// Load the program
-	std::string pps =
-		"#define TILES_X_COUNT " + std::to_string(TILES_X_COUNT) + "\n"
-		"#define TILES_Y_COUNT " + std::to_string(TILES_Y_COUNT) + "\n"
-		"#define RENDERER_WIDTH " + std::to_string(r->getWidth()) + "\n"
-		"#define RENDERER_HEIGHT " + std::to_string(r->getHeight()) + "\n";
+	std::stringstream pps;
+	pps << "#define TILES_X_COUNT " << r->getTilesCount().x() << "\n"
+		<< "#define TILES_Y_COUNT " << r->getTilesCount().y() << "\n"
+		<< "#define RENDERER_WIDTH " << r->getWidth() << "\n"
+		<< "#define RENDERER_HEIGHT " << r->getHeight() << "\n";
 
 	prog.load(ShaderProgramResource::createSrcCodeToCache(
-		"shaders/TilerMinMax.glsl", pps.c_str(), "r_").c_str());
+		"shaders/TilerMinMax.glsl", pps.str().c_str(), "r_").c_str());
 
 	depthMapUniform = &(prog->findUniformVariable("depthMap"));
 
 	// Create FBO
-	fai.create2dFai(TILES_X_COUNT, TILES_Y_COUNT, GL_RG32UI,
-		GL_RG_INTEGER, GL_UNSIGNED_INT);
+	fai.create2dFai(r->getTilesCount().x(), r->getTilesCount().y(), 
+		GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT);
 	fai.setFiltering(Texture::TFT_NEAREST);
 
 	fbo.create();
@@ -231,23 +235,25 @@ void Tiler::initInternal(Renderer* r_)
 
 	// Create PBO
 	pbo.create(GL_PIXEL_PACK_BUFFER, 
-		TILES_X_COUNT * TILES_Y_COUNT * 2 * sizeof(F32), nullptr);
+		r->getTilesCount().x() * r->getTilesCount().y() * 2 * sizeof(F32), 
+		nullptr);
 
 	// Init planes
 	U planesCount = 
-		(TILES_X_COUNT - 1) * 2 // planes J
-		+ (TILES_Y_COUNT - 1) * 2  // planes I
-		+ (TILES_COUNT * 2); // near far planes
+		(r->getTilesCount().x() - 1) * 2 // planes J
+		+ (r->getTilesCount().y() - 1) * 2  // planes I
+		+ (r->getTilesCount().x() * r->getTilesCount().y() * 2); 
+		// near far planes
 
 	allPlanes.resize(planesCount);
 
 	planesJ = &allPlanes[0];
-	planesI = planesJ + TILES_X_COUNT - 1;
+	planesI = planesJ + r->getTilesCount().x() - 1;
 
-	planesJW = planesI + TILES_Y_COUNT - 1;
-	planesIW = planesJW + TILES_X_COUNT - 1;
-	nearPlanesW = planesIW + TILES_Y_COUNT - 1;
-	farPlanesW = nearPlanesW + TILES_COUNT;
+	planesJW = planesI + r->getTilesCount().y() - 1;
+	planesIW = planesJW + r->getTilesCount().x() - 1;
+	nearPlanesW = planesIW + r->getTilesCount().y() - 1;
+	farPlanesW = nearPlanesW + r->getTilesCount().x() * r->getTilesCount().y();
 }
 
 //==============================================================================
@@ -258,7 +264,8 @@ void Tiler::runMinMax(const Texture& depthMap)
 
 	// Issue the min/max job
 	fbo.bind();
-	GlStateSingleton::get().setViewport(0, 0, TILES_X_COUNT, TILES_Y_COUNT);
+	GlStateSingleton::get().setViewport(
+		0, 0, r->getTilesCount().x(), r->getTilesCount().y());
 	r->clearAfterBindingFbo(GL_COLOR_BUFFER_BIT);
 	prog->bind();
 	ANKI_ASSERT(depthMapUniform);
@@ -268,8 +275,8 @@ void Tiler::runMinMax(const Texture& depthMap)
 
 	// Issue the async pixel read
 	pbo.bind();
-	glReadPixels(0, 0, TILES_X_COUNT, TILES_Y_COUNT, GL_RG_INTEGER,
-		GL_UNSIGNED_INT, nullptr);
+	glReadPixels(0, 0, r->getTilesCount().x(), r->getTilesCount().y(), 
+		GL_RG_INTEGER, GL_UNSIGNED_INT, nullptr);
 	pbo.unbind();
 #endif
 }
@@ -339,7 +346,8 @@ Bool Tiler::test(
 {
 	Bitset bitset;
 
-	testRange(cs, nearPlane, 0, TILES_Y_COUNT, 0, TILES_X_COUNT, bitset);
+	testRange(cs, nearPlane, 0, r->getTilesCount().y(), 0, 
+		r->getTilesCount().x(), bitset);
 
 	if(outBitset)
 	{
@@ -361,7 +369,7 @@ void Tiler::testRange(const CollisionShape& cs, Bool nearPlane,
 	// Handle final
 	if(mi == 0 || mj == 0)
 	{
-		U tileId = iFrom * TILES_X_COUNT + jFrom;
+		U tileId = iFrom * r->getTilesCount().x() + jFrom;
 
 		Bool inside = true;
 

+ 2 - 2
src/resource/Material.cpp

@@ -280,8 +280,8 @@ void Material::parseMaterialTag(const XmlElement& materialEl)
 
 			src << "#define LOD " << level << "\n"
 				<< "#define PASS_" << passNames[pid] << "\n"
-				<< "#define USE_MRT " 
-				<< MainRendererSingleton::get().getUseMrt() << "\n"
+				<< MainRendererSingleton::get().getShaderPostProcessorString() 
+				<< "\n"
 				<< mspc.getShaderProgramSource() << std::endl;
 
 			std::string filename =