Procházet zdrojové kódy

Refactored point light and blit shaders so they share code using the new conditional compilation
Fixed input box caret when deleting the first element using backspace

BearishSun před 10 roky
rodič
revize
bc67031960

+ 14 - 1
BansheeCore/Source/BsResources.cpp

@@ -32,6 +32,13 @@ namespace BansheeEngine
 
 
 	HResource Resources::load(const Path& filePath, bool loadDependencies, bool keepInternalReference)
 	HResource Resources::load(const Path& filePath, bool loadDependencies, bool keepInternalReference)
 	{
 	{
+		if (!FileSystem::isFile(filePath))
+		{
+			LOGWRN_VERBOSE("Cannot load resource. Specified file: " + filePath.toString() + " doesn't exist.");
+
+			return HResource();
+		}
+
 		String uuid;
 		String uuid;
 		bool foundUUID = getUUIDFromFilePath(filePath, uuid);
 		bool foundUUID = getUUIDFromFilePath(filePath, uuid);
 
 
@@ -52,6 +59,13 @@ namespace BansheeEngine
 
 
 	HResource Resources::loadAsync(const Path& filePath, bool loadDependencies, bool keepInternalReference)
 	HResource Resources::loadAsync(const Path& filePath, bool loadDependencies, bool keepInternalReference)
 	{
 	{
+		if (!FileSystem::isFile(filePath))
+		{
+			LOGWRN_VERBOSE("Cannot load resource. Specified file: " + filePath.toString() + " doesn't exist.");
+
+			return HResource();
+		}
+
 		String uuid;
 		String uuid;
 		bool foundUUID = getUUIDFromFilePath(filePath, uuid);
 		bool foundUUID = getUUIDFromFilePath(filePath, uuid);
 
 
@@ -125,7 +139,6 @@ namespace BansheeEngine
 			}
 			}
 		}
 		}
 
 
-
 		// Not loaded and not in progress, start loading of new resource
 		// Not loaded and not in progress, start loading of new resource
 		// (or if already loaded or in progress, load any dependencies)
 		// (or if already loaded or in progress, load any dependencies)
 		if (!alreadyLoading)
 		if (!alreadyLoading)

+ 6 - 2
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -652,10 +652,14 @@ namespace BansheeEngine
 						{
 						{
 							eraseChar(charIdx);
 							eraseChar(charIdx);
 
 
-							if(charIdx > 0)
+							if (charIdx > 0)
+							{
 								charIdx--;
 								charIdx--;
 
 
-							gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
+								gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
+							}
+							else
+								gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_BEFORE);
 
 
 							scrollTextToCaret();
 							scrollTextToCaret();
 
 

+ 3 - 3
BansheeSL/Source/BsIncludeHandler.cpp

@@ -57,14 +57,14 @@ char* includePush(ParseState* state, const char* filename, int line, int column,
 		return output;
 		return output;
 	}
 	}
 
 
-	const char* errorLabel = "Error opening include file :";
+	const char* errorLabel = "Error opening include file: ";
 	int labelLen = (int)strlen(errorLabel);
 	int labelLen = (int)strlen(errorLabel);
 
 
 	int messageLen = filenameLen + labelLen + 1;
 	int messageLen = filenameLen + labelLen + 1;
 	char* message = (char*)mmalloc(state->memContext, messageLen);
 	char* message = (char*)mmalloc(state->memContext, messageLen);
 
 
-	memcpy(message, filename, filenameLen);
-	memcpy(message + filenameLen, errorLabel, labelLen);
+	memcpy(message, errorLabel, labelLen);
+	memcpy(message + labelLen, filenameNoQuote, filenameLen);
 	message[messageLen - 1] = '\0';
 	message[messageLen - 1] = '\0';
 
 
 	state->hasError = 1;
 	state->hasError = 1;

+ 30 - 4
RenderBeast/Include/BsLightRendering.h

@@ -50,13 +50,39 @@ namespace BansheeEngine
 		MaterialParamTextureCore mGBufferDepth;
 		MaterialParamTextureCore mGBufferDepth;
 	};
 	};
 
 
-	/** Shader that renders point (radial & spot) light sources during deferred rendering light pass. */
-	class PointLightMat : public RendererMaterial<PointLightMat>
+	/** 
+	 * Shader that renders point (radial & spot) light sources during deferred rendering light pass. Used when the camera
+	 * is inside the point light geometry.
+	 */
+	class PointLightInMat : public RendererMaterial<PointLightInMat>
 	{
 	{
-		RMAT_DEF("DeferredPointLightPass.bsl");
+		RMAT_DEF("DeferredPointLightPassIn.bsl");
 
 
 	public:
 	public:
-		PointLightMat();
+		PointLightInMat();
+
+		/** Updates parameters that are common for all lights.  */
+		void setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
+
+		/** Updates the parameter buffers used by the material. */
+		void setParameters(const LightCore* light);
+	private:
+		PerLightParams mParams; // Note: Should this buffer be shared between both point and directional lights?
+		MaterialParamTextureCore mGBufferA;
+		MaterialParamTextureCore mGBufferB;
+		MaterialParamTextureCore mGBufferDepth;
+	};
+
+	/** 
+	 * Shader that renders point (radial & spot) light sources during deferred rendering light pass. Used when the camera
+	 * is outside the point light geometry.
+	 */
+	class PointLightOutMat : public RendererMaterial<PointLightOutMat>
+	{
+		RMAT_DEF("DeferredPointLightPassOut.bsl");
+
+	public:
+		PointLightOutMat();
 
 
 		/** Updates parameters that are common for all lights.  */
 		/** Updates parameters that are common for all lights.  */
 		void setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
 		void setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);

+ 2 - 6
RenderBeast/Include/BsRenderBeast.h

@@ -298,15 +298,11 @@ namespace BansheeEngine
 		Vector<LightData> mPointLights;
 		Vector<LightData> mPointLights;
 		Vector<Sphere> mLightWorldBounds;
 		Vector<Sphere> mLightWorldBounds;
 
 
-		SPtr<DepthStencilStateCore> mPointLightInGeomDSState;
-		SPtr<DepthStencilStateCore> mPointLightOutGeomDSState;
-		SPtr<RasterizerStateCore> mPointLightInGeomRState;
-		SPtr<RasterizerStateCore> mPointLightOutGeomRState;
-
 		SPtr<RenderBeastOptions> mCoreOptions;
 		SPtr<RenderBeastOptions> mCoreOptions;
 
 
 		DefaultMaterial* mDefaultMaterial;
 		DefaultMaterial* mDefaultMaterial;
-		PointLightMat* mPointLightMat;
+		PointLightInMat* mPointLightInMat;
+		PointLightOutMat* mPointLightOutMat;
 		DirectionalLightMat* mDirLightMat;
 		DirectionalLightMat* mDirLightMat;
 
 
 		// Sim thread only fields
 		// Sim thread only fields

+ 33 - 3
RenderBeast/Source/BsLightRendering.cpp

@@ -102,7 +102,7 @@ namespace BansheeEngine
 		mParams.setParameters(light);
 		mParams.setParameters(light);
 	}
 	}
 
 
-	PointLightMat::PointLightMat()
+	PointLightInMat::PointLightInMat()
 	{
 	{
 		mMaterial->setParamBlockBuffer("PerLight", mParams.getBuffer());
 		mMaterial->setParamBlockBuffer("PerLight", mParams.getBuffer());
 
 
@@ -118,7 +118,7 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	void PointLightMat::setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera)
+	void PointLightInMat::setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera)
 	{
 	{
 		mGBufferA.set(gbuffer->getTextureA());
 		mGBufferA.set(gbuffer->getTextureA());
 		mGBufferB.set(gbuffer->getTextureB());
 		mGBufferB.set(gbuffer->getTextureB());
@@ -127,7 +127,37 @@ namespace BansheeEngine
 		mMaterial->setParamBlockBuffer("PerCamera", perCamera);
 		mMaterial->setParamBlockBuffer("PerCamera", perCamera);
 	}
 	}
 
 
-	void PointLightMat::setParameters(const LightCore* light)
+	void PointLightInMat::setParameters(const LightCore* light)
+	{
+		mParams.setParameters(light);
+	}
+
+	PointLightOutMat::PointLightOutMat()
+	{
+		mMaterial->setParamBlockBuffer("PerLight", mParams.getBuffer());
+
+		auto& texParams = mMaterial->getShader()->getTextureParams();
+		for (auto& entry : texParams)
+		{
+			if (entry.second.rendererSemantic == RPS_GBufferA)
+				mGBufferA = mMaterial->getParamTexture(entry.second.name);
+			else if (entry.second.rendererSemantic == RPS_GBufferB)
+				mGBufferB = mMaterial->getParamTexture(entry.second.name);
+			else if (entry.second.rendererSemantic == RPS_GBufferDepth)
+				mGBufferDepth = mMaterial->getParamTexture(entry.second.name);
+		}
+	}
+
+	void PointLightOutMat::setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera)
+	{
+		mGBufferA.set(gbuffer->getTextureA());
+		mGBufferB.set(gbuffer->getTextureB());
+		mGBufferDepth.set(gbuffer->getTextureDepth());
+
+		mMaterial->setParamBlockBuffer("PerCamera", perCamera);
+	}
+
+	void PointLightOutMat::setParameters(const LightCore* light)
 	{
 	{
 		mParams.setParameters(light);
 		mParams.setParameters(light);
 	}
 	}

+ 40 - 54
RenderBeast/Source/BsRenderBeast.cpp

@@ -37,7 +37,7 @@ namespace BansheeEngine
 {
 {
 	RenderBeast::RenderBeast()
 	RenderBeast::RenderBeast()
 		:mOptions(bs_shared_ptr_new<RenderBeastOptions>()), mOptionsDirty(true), mStaticHandler(nullptr),
 		:mOptions(bs_shared_ptr_new<RenderBeastOptions>()), mOptionsDirty(true), mStaticHandler(nullptr),
-		mDefaultMaterial(nullptr), mPointLightMat(nullptr), mDirLightMat(nullptr)
+		mDefaultMaterial(nullptr), mPointLightInMat(nullptr), mPointLightOutMat(nullptr), mDirLightMat(nullptr)
 	{
 	{
 
 
 	}
 	}
@@ -71,32 +71,10 @@ namespace BansheeEngine
 		mStaticHandler = bs_new<StaticRenderableHandler>();
 		mStaticHandler = bs_new<StaticRenderableHandler>();
 
 
 		mDefaultMaterial = bs_new<DefaultMaterial>();
 		mDefaultMaterial = bs_new<DefaultMaterial>();
-		mPointLightMat = bs_new<PointLightMat>();
+		mPointLightInMat = bs_new<PointLightInMat>();
+		mPointLightOutMat = bs_new<PointLightOutMat>();
 		mDirLightMat = bs_new<DirectionalLightMat>();
 		mDirLightMat = bs_new<DirectionalLightMat>();
 
 
-		// TODO - Replace these manually assigned states with two different versions of point light shader once I implement
-		// a preprocessor parser for BSL
-		DEPTH_STENCIL_STATE_DESC inGeomDSDesc;
-		inGeomDSDesc.depthWriteEnable = false;
-		inGeomDSDesc.depthReadEnable = false;
-
-		mPointLightInGeomDSState = RenderStateCoreManager::instance().createDepthStencilState(inGeomDSDesc);
-
-		DEPTH_STENCIL_STATE_DESC outGeomDSDesc;
-		outGeomDSDesc.depthWriteEnable = false;
-
-		mPointLightOutGeomDSState = RenderStateCoreManager::instance().createDepthStencilState(outGeomDSDesc);
-
-		RASTERIZER_STATE_DESC inGeomRDesc;
-		inGeomRDesc.cullMode = CULL_CLOCKWISE;
-
-		mPointLightInGeomRState = RenderStateCoreManager::instance().createRasterizerState(inGeomRDesc);
-
-		RASTERIZER_STATE_DESC outGeomRDesc;
-		outGeomRDesc.cullMode = CULL_COUNTERCLOCKWISE;
-
-		mPointLightOutGeomRState = RenderStateCoreManager::instance().createRasterizerState(outGeomRDesc);
-
 		RenderTexturePool::startUp();
 		RenderTexturePool::startUp();
 	}
 	}
 
 
@@ -112,15 +90,10 @@ namespace BansheeEngine
 		RenderTexturePool::shutDown();
 		RenderTexturePool::shutDown();
 
 
 		bs_delete(mDefaultMaterial);
 		bs_delete(mDefaultMaterial);
-		bs_delete(mPointLightMat);
+		bs_delete(mPointLightInMat);
+		bs_delete(mPointLightOutMat);
 		bs_delete(mDirLightMat);
 		bs_delete(mDirLightMat);
 
 
-		mPointLightInGeomDSState = nullptr;
-		mPointLightOutGeomDSState = nullptr;
-
-		mPointLightInGeomRState = nullptr;
-		mPointLightOutGeomRState = nullptr;
-
 		RendererUtility::shutDown();
 		RendererUtility::shutDown();
 
 
 		assert(mSamplerOverrides.empty());
 		assert(mSamplerOverrides.empty());
@@ -614,12 +587,13 @@ namespace BansheeEngine
 				gRendererUtility().drawScreenQuad();
 				gRendererUtility().drawScreenQuad();
 			}
 			}
 
 
-			SPtr<MaterialCore> pointMaterial = mPointLightMat->getMaterial();
-			SPtr<PassCore> pointPass = pointMaterial->getPass(0);
+			// Draw point lights which our camera is within
+			SPtr<MaterialCore> pointInsideMaterial = mPointLightInMat->getMaterial();
+			SPtr<PassCore> pointInsidePass = pointInsideMaterial->getPass(0);
 
 
 			// TODO - Possibly use instanced drawing here as only two meshes are drawn with various properties
 			// TODO - Possibly use instanced drawing here as only two meshes are drawn with various properties
-			setPass(pointPass);
-			mPointLightMat->setStaticParameters(camData.target, perCameraBuffer);
+			setPass(pointInsidePass);
+			mPointLightInMat->setStaticParameters(camData.target, perCameraBuffer);
 
 
 			// TODO - Cull lights based on visibility, right now I just iterate over all of them. 
 			// TODO - Cull lights based on visibility, right now I just iterate over all of them. 
 			for (auto& light : mPointLights)
 			for (auto& light : mPointLights)
@@ -627,32 +601,44 @@ namespace BansheeEngine
 				if (!light.internal->getIsActive())
 				if (!light.internal->getIsActive())
 					continue;
 					continue;
 
 
-				mPointLightMat->setParameters(light.internal);
-
 				float distToLight = (light.internal->getBounds().getCenter() - camera->getPosition()).squaredLength();
 				float distToLight = (light.internal->getBounds().getCenter() - camera->getPosition()).squaredLength();
 				float boundRadius = light.internal->getBounds().getRadius() * 1.05f + camera->getNearClipDistance() * 2.0f;
 				float boundRadius = light.internal->getBounds().getRadius() * 1.05f + camera->getNearClipDistance() * 2.0f;
 
 
-				// TODO - Replace these manually assigned states with two different versions of point light shader once I implement
-				// a preprocessor parser for BSL
-				RenderAPICore& rapi = RenderAPICore::instance();
+				bool cameraInLightGeometry = distToLight < boundRadius * boundRadius;
+				if (!cameraInLightGeometry)
+					continue;
+
+				mPointLightInMat->setParameters(light.internal);
+
+				// TODO - Bind parameters to the pipeline manually as I don't need to re-bind gbuffer textures for every light
+				setPassParams(pointInsideMaterial->getPassParameters(0), nullptr);
+				SPtr<MeshCore> mesh = light.internal->getMesh();
+				gRendererUtility().draw(mesh, mesh->getProperties().getSubMesh(0));
+			}
+
+			// Draw other point lights
+			SPtr<MaterialCore> pointOutsideMaterial = mPointLightOutMat->getMaterial();
+			SPtr<PassCore> pointOutsidePass = pointOutsideMaterial->getPass(0);
+
+			setPass(pointOutsidePass);
+			mPointLightOutMat->setStaticParameters(camData.target, perCameraBuffer);
+
+			for (auto& light : mPointLights)
+			{
+				if (!light.internal->getIsActive())
+					continue;
+
+				float distToLight = (light.internal->getBounds().getCenter() - camera->getPosition()).squaredLength();
+				float boundRadius = light.internal->getBounds().getRadius() * 1.05f + camera->getNearClipDistance() * 2.0f;
 
 
 				bool cameraInLightGeometry = distToLight < boundRadius * boundRadius;
 				bool cameraInLightGeometry = distToLight < boundRadius * boundRadius;
-				if(cameraInLightGeometry)
-				{
-					// Draw back faces with no depth testing
-					rapi.setDepthStencilState(mPointLightInGeomDSState, 0);
-					rapi.setRasterizerState(mPointLightInGeomRState);
+				if (cameraInLightGeometry)
+					continue;
 
 
-				}
-				else
-				{
-					// Draw front faces with depth testing
-					rapi.setDepthStencilState(mPointLightOutGeomDSState, 0);
-					rapi.setRasterizerState(mPointLightOutGeomRState);
-				}
+				mPointLightOutMat->setParameters(light.internal);
 
 
 				// TODO - Bind parameters to the pipeline manually as I don't need to re-bind gbuffer textures for every light
 				// TODO - Bind parameters to the pipeline manually as I don't need to re-bind gbuffer textures for every light
-				setPassParams(pointMaterial->getPassParameters(0), nullptr);
+				setPassParams(pointOutsideMaterial->getPassParameters(0), nullptr);
 				SPtr<MeshCore> mesh = light.internal->getMesh();
 				SPtr<MeshCore> mesh = light.internal->getMesh();
 				gRendererUtility().draw(mesh, mesh->getProperties().getSubMesh(0));
 				gRendererUtility().draw(mesh, mesh->getProperties().getSubMesh(0));
 			}
 			}