ソースを参照

Neater light pass material parameter assignment
Removed some duplicate code from RenderBeast

BearishSun 9 年 前
コミット
0696a5094f

+ 8 - 15
Source/BansheeEditor/Source/BsGizmoManager.cpp

@@ -1109,36 +1109,29 @@ namespace BansheeEngine
 		case GizmoManager::GizmoMaterial::Solid:
 			mSolidMaterial.mViewProj.set(viewProjMat);
 			mSolidMaterial.mViewDir.set((Vector4)viewDir);
-			gRendererUtility().setPass(mSolidMaterial.mat, 0);
-			gRendererUtility().setPassParams(mSolidMaterial.mat);
+			gRendererUtility().setPass(mSolidMaterial.mat);
 			break;
 		case GizmoManager::GizmoMaterial::Wire:
 			mWireMaterial.mViewProj.set(viewProjMat);
-			gRendererUtility().setPass(mWireMaterial.mat, 0);
-			gRendererUtility().setPassParams(mWireMaterial.mat);
+			gRendererUtility().setPass(mWireMaterial.mat);
 			break;
 		case GizmoManager::GizmoMaterial::Line:
 			mLineMaterial.mViewProj.set(viewProjMat);
-			gRendererUtility().setPass(mLineMaterial.mat, 0);
-			gRendererUtility().setPassParams(mLineMaterial.mat);
+			gRendererUtility().setPass(mLineMaterial.mat);
 			break;
 		case GizmoManager::GizmoMaterial::Picking:
 			mPickingMaterial.mViewProj.set(viewProjMat);
-			gRendererUtility().setPass(mPickingMaterial.mat, 0);
-			gRendererUtility().setPassParams(mPickingMaterial.mat);
+			gRendererUtility().setPass(mPickingMaterial.mat);
 			break;
 		case GizmoManager::GizmoMaterial::PickingAlpha:
 			mAlphaPickingMaterial.mViewProj.set(viewProjMat);
 			mAlphaPickingMaterial.mTexture.set(texture);
-			gRendererUtility().setPass(mAlphaPickingMaterial.mat, 0);
-			gRendererUtility().setPassParams(mAlphaPickingMaterial.mat);
+			gRendererUtility().setPass(mAlphaPickingMaterial.mat);
 			break;
 		case GizmoManager::GizmoMaterial::Text:
 			mTextMaterial.mViewProj.set(viewProjMat);
 			mTextMaterial.mTexture.set(texture);
-
-			gRendererUtility().setPass(mTextMaterial.mat, 0);
-			gRendererUtility().setPassParams(mTextMaterial.mat);
+			gRendererUtility().setPass(mTextMaterial.mat);
 			break;
 		}
 		gRendererUtility().draw(mesh, mesh->getProperties().getSubMesh(0));
@@ -1190,7 +1183,7 @@ namespace BansheeEngine
 				for (auto curRenderData : *renderData)
 				{
 					mIconMaterial.mTexture[passIdx].set(curRenderData.texture);
-					RendererUtility::setGpuParams(GPT_FRAGMENT_PROGRAM, mIconMaterial.mFragParams[passIdx]);
+					gRendererUtility().setGpuParams(GPT_FRAGMENT_PROGRAM, mIconMaterial.mFragParams[passIdx]);
 
 					rapi.drawIndexed(curIndexOffset, curRenderData.count * 6, mesh->getVertexOffset(), curRenderData.count * 4);
 					curIndexOffset += curRenderData.count * 6;
@@ -1207,7 +1200,7 @@ namespace BansheeEngine
 			for (auto curRenderData : *renderData)
 			{
 				mAlphaPickingMaterial.mTexture.set(curRenderData.texture);
-				RendererUtility::setGpuParams(GPT_FRAGMENT_PROGRAM, mAlphaPickingMaterial.mFragParams);
+				gRendererUtility().setGpuParams(GPT_FRAGMENT_PROGRAM, mAlphaPickingMaterial.mFragParams);
 
 				rapi.drawIndexed(curIndexOffset, curRenderData.count * 6, mesh->getVertexOffset(), curRenderData.count * 4);
 				curIndexOffset += curRenderData.count * 6;

+ 6 - 9
Source/BansheeEditor/Source/BsHandleDrawManager.cpp

@@ -333,13 +333,13 @@ namespace BansheeEngine
 			currentType = meshes[0].type;
 
 			if (currentType == MeshType::Solid)
-				gRendererUtility().setPass(mSolidMaterial.mat, 0);
+				gRendererUtility().setPass(mSolidMaterial.mat);
 			else if(currentType == MeshType::Line)
-				gRendererUtility().setPass(mLineMaterial.mat, 0);
+				gRendererUtility().setPass(mLineMaterial.mat);
 			else
 			{
 				mTextMaterial.texture.set(meshes[0].texture);
-				gRendererUtility().setPass(mTextMaterial.mat, 0);
+				gRendererUtility().setPass(mTextMaterial.mat);
 			}
 		}
 
@@ -349,19 +349,16 @@ namespace BansheeEngine
 			{
 				if (meshData.type == MeshType::Solid)
 				{
-					gRendererUtility().setPass(mSolidMaterial.mat, 0);
-					gRendererUtility().setPassParams(mSolidMaterial.mat); // TODO - This call shouldn't be necessary, calling set() on parameters should be enough
+					gRendererUtility().setPass(mSolidMaterial.mat);
 				}
 				else if (meshData.type == MeshType::Line)
 				{
-					gRendererUtility().setPass(mLineMaterial.mat, 0);
-					gRendererUtility().setPassParams(mLineMaterial.mat); // TODO - This call shouldn't be necessary, calling set() on parameters should be enough
+					gRendererUtility().setPass(mLineMaterial.mat);
 				}
 				else
 				{
 					mTextMaterial.texture.set(meshData.texture);
-					gRendererUtility().setPass(mTextMaterial.mat, 0);
-					gRendererUtility().setPassParams(mTextMaterial.mat); // TODO - This call shouldn't be necessary, calling set() on parameters should be enough
+					gRendererUtility().setPass(mTextMaterial.mat);
 				}
 
 				currentType = meshData.type;

+ 4 - 4
Source/BansheeEditor/Source/BsScenePicking.cpp

@@ -293,16 +293,16 @@ namespace BansheeEngine
 				md.mParamPickingAlphaColor.set(color);
 				md.mParamPickingAlphaTexture.set(renderable.mainTexture->getCore());
 
-				RendererUtility::setGpuParams(GPT_VERTEX_PROGRAM, md.mParamPickingAlphaVertParams);
-				RendererUtility::setGpuParams(GPT_FRAGMENT_PROGRAM, md.mParamPickingAlphaFragParams);
+				gRendererUtility().setGpuParams(GPT_VERTEX_PROGRAM, md.mParamPickingAlphaVertParams);
+				gRendererUtility().setGpuParams(GPT_FRAGMENT_PROGRAM, md.mParamPickingAlphaFragParams);
 			}
 			else
 			{
 				md.mParamPickingWVP.set(renderable.wvpTransform);
 				md.mParamPickingColor.set(color);
 
-				RendererUtility::setGpuParams(GPT_VERTEX_PROGRAM, md.mParamPickingVertParams);
-				RendererUtility::setGpuParams(GPT_FRAGMENT_PROGRAM, md.mParamPickingFragParams);
+				gRendererUtility().setGpuParams(GPT_VERTEX_PROGRAM, md.mParamPickingVertParams);
+				gRendererUtility().setGpuParams(GPT_FRAGMENT_PROGRAM, md.mParamPickingFragParams);
 			}
 
 			UINT32 numSubmeshes = renderable.mesh->getProperties().getNumSubMeshes();

+ 14 - 8
Source/BansheeEngine/Include/BsRendererUtility.h

@@ -32,22 +32,28 @@ namespace BansheeEngine
 		/**
 		 * Activates the specified material pass for rendering. Any further draw calls will be executed using this pass.
 		 *
-		 * @param[in]	material	Material containing the pass.
-		 * @param[in]	passIdx		Index of the pass in the material.
+		 * @param[in]	material		Material containing the pass.
+		 * @param[in]	passIdx			Index of the pass in the material.
+		 * @param[in]	bindParameters	If true, any GPU program parameters will be bound as well. Otherwise the caller
+		 *								is required to bind them manually via setPassParams() or setGpuParams() before
+		 *								using the pass.
 		 *
 		 * @note	Core thread.
 		 */
-		void setPass(const SPtr<MaterialCore>& material, UINT32 passIdx = 0);
+		void setPass(const SPtr<MaterialCore>& material, UINT32 passIdx = 0, bool bindParameters = true);
 
 		/**
 		 * Activates the specified material pass for compute. Any further dispatch calls will be executed using this pass.
 		 *
-		 * @param[in]	material	Material containing the pass.
-		 * @param[in]	passIdx		Index of the pass in the material.
+		 * @param[in]	material		Material containing the pass.
+		 * @param[in]	passIdx			Index of the pass in the material.
+		 * @param[in]	bindParameters	If true, any GPU program parameters will be bound as well. Otherwise the caller
+		 *								is required to bind them manually via setPassParams() or setGpuParams() before
+		 *								using the pass.
 		 *
 		 * @note	Core thread.
 		 */
-		void setComputePass(const SPtr<MaterialCore>& material, UINT32 passIdx = 0);
+		void setComputePass(const SPtr<MaterialCore>& material, UINT32 passIdx = 0, bool bindParameters = true);
 
 		/**
 		 * Sets parameters (textures, samplers, buffers) for the currently active pass.
@@ -57,7 +63,7 @@ namespace BansheeEngine
 		 *					
 		 * @note	Core thread.
 		 */
-		static void setPassParams(const SPtr<MaterialCore>& material, UINT32 passIdx = 0);
+		void setPassParams(const SPtr<MaterialCore>& material, UINT32 passIdx = 0);
 
 		/**
 		 * Sets parameters (textures, samplers, buffers) for the provided GPU program type.
@@ -65,7 +71,7 @@ namespace BansheeEngine
 		 * @param[in]	type		Type of the GPU program to assign the parameters to.
 		 * @param[in]	params		Parameters to assign.
 		 */
-		static void setGpuParams(GpuProgramType type, const SPtr<GpuParamsCore>& params);
+		void setGpuParams(GpuProgramType type, const SPtr<GpuParamsCore>& params);
 
 		/**
 		 * Draws the specified mesh.

+ 20 - 18
Source/BansheeEngine/Source/BsRendererUtility.cpp

@@ -116,9 +116,9 @@ namespace BansheeEngine
 
 	}
 
-	void RendererUtility::setPass(const SPtr<MaterialCore>& material, UINT32 passIdx)
+	void RendererUtility::setPass(const SPtr<MaterialCore>& material, UINT32 passIdx, bool bindParameters)
 	{
-		RenderAPICore& rs = RenderAPICore::instance();
+		RenderAPICore& rapi = RenderAPICore::instance();
 
 		SPtr<PassCore> pass = material->getPass(passIdx);
 		SPtr<PassParametersCore> passParams = material->getPassParameters(passIdx);
@@ -162,53 +162,55 @@ namespace BansheeEngine
 
 			if (stage.enable)
 			{
-				rs.bindGpuProgram(stage.program);
-				setGpuParams(stage.type, stage.params);
+				rapi.bindGpuProgram(stage.program);
+
+				if(bindParameters)
+					setGpuParams(stage.type, stage.params);
 
 			}
 			else
-				rs.unbindGpuProgram(stage.type);
+				rapi.unbindGpuProgram(stage.type);
 		}
 
 		// Set up non-texture related pass settings
 		if (pass->getBlendState() != nullptr)
-			rs.setBlendState(pass->getBlendState());
+			rapi.setBlendState(pass->getBlendState());
 		else
-			rs.setBlendState(BlendStateCore::getDefault());
+			rapi.setBlendState(BlendStateCore::getDefault());
 
 		if (pass->getDepthStencilState() != nullptr)
-			rs.setDepthStencilState(pass->getDepthStencilState(), pass->getStencilRefValue());
+			rapi.setDepthStencilState(pass->getDepthStencilState(), pass->getStencilRefValue());
 		else
-			rs.setDepthStencilState(DepthStencilStateCore::getDefault(), pass->getStencilRefValue());
+			rapi.setDepthStencilState(DepthStencilStateCore::getDefault(), pass->getStencilRefValue());
 
 		if (pass->getRasterizerState() != nullptr)
-			rs.setRasterizerState(pass->getRasterizerState());
+			rapi.setRasterizerState(pass->getRasterizerState());
 		else
-			rs.setRasterizerState(RasterizerStateCore::getDefault());
+			rapi.setRasterizerState(RasterizerStateCore::getDefault());
 	}
 
-	void RendererUtility::setComputePass(const SPtr<MaterialCore>& material, UINT32 passIdx)
+	void RendererUtility::setComputePass(const SPtr<MaterialCore>& material, UINT32 passIdx, bool bindParameters)
 	{
-		RenderAPICore& rs = RenderAPICore::instance();
+		RenderAPICore& rapi = RenderAPICore::instance();
 
 		SPtr<PassCore> pass = material->getPass(passIdx);
 		SPtr<PassParametersCore> passParams = material->getPassParameters(passIdx);
 
 		if(pass->hasComputeProgram())
 		{
-			rs.bindGpuProgram(pass->getComputeProgram());
-			setGpuParams(GPT_COMPUTE_PROGRAM, passParams->mComputeParams);
+			rapi.bindGpuProgram(pass->getComputeProgram());
+
+			if (bindParameters)
+				setGpuParams(GPT_COMPUTE_PROGRAM, passParams->mComputeParams);
 		}
 		else
-			rs.unbindGpuProgram(GPT_COMPUTE_PROGRAM);
+			rapi.unbindGpuProgram(GPT_COMPUTE_PROGRAM);
 	}
 
 	void RendererUtility::setPassParams(const SPtr<MaterialCore>& material, UINT32 passIdx)
 	{
 		const SPtr<PassParametersCore>& passParams = material->getPassParameters(passIdx);
 
-		RenderAPICore& rs = RenderAPICore::instance();
-
 		struct StageData
 		{
 			GpuProgramType type;

+ 17 - 25
Source/RenderBeast/Include/BsLightRendering.h

@@ -28,7 +28,7 @@ namespace BansheeEngine
 		LightRenderingParams(const SPtr<MaterialCore>& lightMaterial);
 
 		/** Updates parameters that are common for all lights. */
-		void setStaticParameters(RenderAPICore& rapi, const SPtr<RenderTargets>& gbuffer,
+		void setStaticParameters(const SPtr<RenderTargets>& gbuffer,
 			const SPtr<GpuParamBlockBufferCore>& perCamera);
 
 		/** Updates data in the parameter buffer from the data in the provided light. */
@@ -37,16 +37,11 @@ namespace BansheeEngine
 		/** Returns the internal parameter buffer that can be bound to the pipeline. */
 		const SPtr<GpuParamBlockBufferCore>& getBuffer() const;
 	private:
-		GpuParamTextureCore mGBufferA;
-		GpuParamTextureCore mGBufferB;
-		GpuParamTextureCore mGBufferDepth;
-		GpuParamBlockDesc* mPerLightBlockDescFP;
-		GpuParamBlockDesc* mPerLightBlockDescVP;
-		GpuParamBlockDesc* mPerCameraBlockDescFP;
-		GpuParamBlockDesc* mPerCameraBlockDescVP;
-		const GpuParamDesc* mParamDescVP;
-		const GpuParamDesc* mParamDescFP;
+		SPtr<MaterialCore> mMaterial;
 
+		MaterialParamTextureCore mGBufferA;
+		MaterialParamTextureCore mGBufferB;
+		MaterialParamTextureCore mGBufferDepth;
 		PerLightParamBuffer mBuffer;
 	};
 
@@ -58,12 +53,11 @@ namespace BansheeEngine
 	public:
 		DirectionalLightMat();
 
-		/** Updates parameters that are common for all lights. */
-		void setStaticParameters(RenderAPICore& rapi, const SPtr<RenderTargets>& gbuffer, 
-			const SPtr<GpuParamBlockBufferCore>& perCamera);
+		/** Binds the material for rendering and sets up any global parameters. */
+		void bind(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
 
-		/** Updates the parameter buffers used by the material. */
-		void setParameters(const LightCore* light);
+		/** Updates the per-light buffers used by the material. */
+		void setPerLightParams(const LightCore* light);
 	private:
 		LightRenderingParams mParams;
 	};
@@ -79,12 +73,11 @@ namespace BansheeEngine
 	public:
 		PointLightInMat();
 
-		/** Updates parameters that are common for all lights.  */
-		void setStaticParameters(RenderAPICore& rapi, const SPtr<RenderTargets>& gbuffer, 
-			const SPtr<GpuParamBlockBufferCore>& perCamera);
+		/** Binds the material for rendering and sets up any global parameters. */
+		void bind(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
 
-		/** Updates the parameter buffers used by the material. */
-		void setParameters(const LightCore* light);
+		/** Updates the per-light buffers used by the material. */
+		void setPerLightParams(const LightCore* light);
 	private:
 		LightRenderingParams mParams;
 	};
@@ -100,12 +93,11 @@ namespace BansheeEngine
 	public:
 		PointLightOutMat();
 
-		/** Updates parameters that are common for all lights.  */
-		void setStaticParameters(RenderAPICore& rapi, const SPtr<RenderTargets>& gbuffer, 
-			const SPtr<GpuParamBlockBufferCore>& perCamera);
+		/** Binds the material for rendering and sets up any global parameters. */
+		void bind(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
 
-		/** Updates the parameter buffers used by the material. */
-		void setParameters(const LightCore* light);
+		/** Updates the per-light buffers used by the material. */
+		void setPerLightParams(const LightCore* light);
 	private:
 		LightRenderingParams mParams;
 	};

+ 0 - 9
Source/RenderBeast/Include/BsRenderBeast.h

@@ -246,15 +246,6 @@ namespace BansheeEngine
 		 */
 		static CameraShaderData getCameraShaderData(const CameraCore& camera);
 
-		/**
-		 * Activates the specified pass on the pipeline.
-		 *
-		 * @param[in]	pass	Pass to activate.
-		 * 
-		 * @note	Core thread.
-		 */
-		static void setPass(const SPtr<PassCore>& pass);
-
 		/**
 		 * Sets parameters (textures, samplers, buffers) for the currently active pass.
 		 *

+ 24 - 36
Source/RenderBeast/Source/BsLightRendering.cpp

@@ -7,51 +7,36 @@
 #include "BsRenderTargets.h"
 #include "BsGpuParams.h"
 #include "BsLight.h"
+#include "BsRendererUtility.h"
 
 namespace BansheeEngine
 {
 	LightRenderingParams::LightRenderingParams(const SPtr<MaterialCore>& material)
+		:mMaterial(material)
 	{
 		auto& texParams = material->getShader()->getTextureParams();
-		SPtr<GpuParamsCore> fragParams = material->getGpuParams(0, GPT_FRAGMENT_PROGRAM);
 		for (auto& entry : texParams)
 		{
 			if (entry.second.rendererSemantic == RPS_GBufferA)
-				fragParams->getTextureParam(entry.second.name, mGBufferA);
+				mGBufferA = material->getParamTexture(entry.second.name);
 			else if (entry.second.rendererSemantic == RPS_GBufferB)
-				fragParams->getTextureParam(entry.second.name, mGBufferB);
+				mGBufferB = material->getParamTexture(entry.second.name);
 			else if (entry.second.rendererSemantic == RPS_GBufferDepth)
-				fragParams->getTextureParam(entry.second.name, mGBufferDepth);
+				mGBufferDepth = material->getParamTexture(entry.second.name);
 		}
-
-		mParamDescFP = &fragParams->getParamDesc();
-		mPerLightBlockDescFP = fragParams->getParamBlockDesc("PerLight");
-		mPerCameraBlockDescFP = fragParams->getParamBlockDesc("PerCamera");
-
-		SPtr<GpuParamsCore> vertParams = material->getGpuParams(0, GPT_VERTEX_PROGRAM);
-		mParamDescVP = &vertParams->getParamDesc();
-		mPerLightBlockDescVP = vertParams->getParamBlockDesc("PerLight");
-		mPerCameraBlockDescVP = vertParams->getParamBlockDesc("PerCamera");
 	}
 
-	void LightRenderingParams::setStaticParameters(RenderAPICore& rapi, const SPtr<RenderTargets>& gbuffer,
+	void LightRenderingParams::setStaticParameters(const SPtr<RenderTargets>& gbuffer, 
 		const SPtr<GpuParamBlockBufferCore>& perCamera)
 	{
-		rapi.setTexture(GPT_FRAGMENT_PROGRAM, mGBufferA.getDesc().slot, gbuffer->getTextureA());
-		rapi.setTexture(GPT_FRAGMENT_PROGRAM, mGBufferB.getDesc().slot, gbuffer->getTextureB());
-		rapi.setTexture(GPT_FRAGMENT_PROGRAM, mGBufferDepth.getDesc().slot, gbuffer->getTextureDepth());
-
-		rapi.setSamplerState(GPT_FRAGMENT_PROGRAM, 0, SamplerStateCore::getDefault());
-		rapi.setSamplerState(GPT_FRAGMENT_PROGRAM, 1, SamplerStateCore::getDefault());
-		rapi.setSamplerState(GPT_FRAGMENT_PROGRAM, 2, SamplerStateCore::getDefault());
-
-		rapi.setParamBuffer(GPT_FRAGMENT_PROGRAM, mPerLightBlockDescFP->slot, mBuffer.getBuffer(), *mParamDescFP);
-		rapi.setParamBuffer(GPT_FRAGMENT_PROGRAM, mPerCameraBlockDescFP->slot, perCamera, *mParamDescFP);
+		mGBufferA.set(gbuffer->getTextureA());
+		mGBufferB.set(gbuffer->getTextureB());
+		mGBufferDepth.set(gbuffer->getTextureDepth());
 
-		if(mPerLightBlockDescVP != nullptr)
-			rapi.setParamBuffer(GPT_VERTEX_PROGRAM, mPerLightBlockDescVP->slot, mBuffer.getBuffer(), *mParamDescVP);
+		mMaterial->setParamBlockBuffer("PerLight", getBuffer());
+		mMaterial->setParamBlockBuffer("PerCamera", perCamera);
 
-		rapi.setParamBuffer(GPT_VERTEX_PROGRAM, mPerCameraBlockDescVP->slot, perCamera, *mParamDescVP);
+		gRendererUtility().setPassParams(mMaterial);
 	}
 
 	void LightRenderingParams::setParameters(const LightCore* light)
@@ -129,13 +114,14 @@ namespace BansheeEngine
 		// Do nothing
 	}
 
-	void DirectionalLightMat::setStaticParameters(RenderAPICore& rapi, const SPtr<RenderTargets>& gbuffer, 
+	void DirectionalLightMat::bind(const SPtr<RenderTargets>& gbuffer,
 		const SPtr<GpuParamBlockBufferCore>& perCamera)
 	{
-		mParams.setStaticParameters(rapi, gbuffer, perCamera);
+		RendererUtility::instance().setPass(mMaterial, 0, false);
+		mParams.setStaticParameters(gbuffer, perCamera);
 	}
 
-	void DirectionalLightMat::setParameters(const LightCore* light)
+	void DirectionalLightMat::setPerLightParams(const LightCore* light)
 	{
 		mParams.setParameters(light);
 	}
@@ -151,13 +137,14 @@ namespace BansheeEngine
 		// Do nothing
 	}
 
-	void PointLightInMat::setStaticParameters(RenderAPICore& rapi, const SPtr<RenderTargets>& gbuffer, 
+	void PointLightInMat::bind(const SPtr<RenderTargets>& gbuffer, 
 		const SPtr<GpuParamBlockBufferCore>& perCamera)
 	{
-		mParams.setStaticParameters(rapi, gbuffer, perCamera);
+		RendererUtility::instance().setPass(mMaterial, 0, false);
+		mParams.setStaticParameters(gbuffer, perCamera);
 	}
 
-	void PointLightInMat::setParameters(const LightCore* light)
+	void PointLightInMat::setPerLightParams(const LightCore* light)
 	{
 		mParams.setParameters(light);
 	}
@@ -173,13 +160,14 @@ namespace BansheeEngine
 		// Do nothing
 	}
 
-	void PointLightOutMat::setStaticParameters(RenderAPICore& rapi, const SPtr<RenderTargets>& gbuffer, 
+	void PointLightOutMat::bind(const SPtr<RenderTargets>& gbuffer,
 		const SPtr<GpuParamBlockBufferCore>& perCamera)
 	{
-		mParams.setStaticParameters(rapi, gbuffer, perCamera);
+		RendererUtility::instance().setPass(mMaterial, 0, false);
+		mParams.setStaticParameters(gbuffer, perCamera);
 	}
 
-	void PointLightOutMat::setParameters(const LightCore* light)
+	void PointLightOutMat::setPerLightParams(const LightCore* light)
 	{
 		mParams.setParameters(light);
 	}

+ 8 - 79
Source/RenderBeast/Source/BsRenderBeast.cpp

@@ -533,7 +533,6 @@ namespace BansheeEngine
 	{
 		gProfilerCPU().beginSample("Render");
 
-		RenderAPICore& rapi = RenderAPICore::instance();
 		const CameraCore* camera = rtData.cameras[camIdx];
 		CameraData& camData = mCameraData[camera];
 
@@ -591,10 +590,7 @@ namespace BansheeEngine
 			mStaticHandler->bindPerObjectBuffers(*renderElem);
 
 			if (iter->applyPass)
-			{
-				SPtr<PassCore> pass = material->getPass(iter->passIdx);
-				setPass(pass);
-			}
+				RendererUtility::instance().setPass(material, iter->passIdx, false);
 
 			SPtr<PassParametersCore> passParams = material->getPassParameters(iter->passIdx);
 
@@ -612,28 +608,19 @@ namespace BansheeEngine
 		{
 			SPtr<GpuParamBlockBufferCore> perCameraBuffer = mStaticHandler->getPerCameraParams().getBuffer();
 
-			SPtr<MaterialCore> dirMaterial = mDirLightMat->getMaterial();
-			SPtr<PassCore> dirPass = dirMaterial->getPass(0);
-
-			setPass(dirPass);
-			mDirLightMat->setStaticParameters(rapi, camData.target, perCameraBuffer);
-
+			mDirLightMat->bind(camData.target, perCameraBuffer);
 			for (auto& light : mDirectionalLights)
 			{
 				if (!light.internal->getIsActive())
 					continue;
 
-				mDirLightMat->setParameters(light.internal);
+				mDirLightMat->setPerLightParams(light.internal);
 				gRendererUtility().drawScreenQuad();
 			}
 
 			// 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
-			setPass(pointInsidePass);
-			mPointLightInMat->setStaticParameters(rapi, camData.target, perCameraBuffer);
+			mPointLightInMat->bind(camData.target, perCameraBuffer);
 
 			// TODO - Cull lights based on visibility, right now I just iterate over all of them. 
 			for (auto& light : mPointLights)
@@ -648,18 +635,14 @@ namespace BansheeEngine
 				if (!cameraInLightGeometry)
 					continue;
 
-				mPointLightInMat->setParameters(light.internal);
+				mPointLightInMat->setPerLightParams(light.internal);
 
 				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(rapi, camData.target, perCameraBuffer);
+			mPointLightOutMat->bind(camData.target, perCameraBuffer);
 
 			for (auto& light : mPointLights)
 			{
@@ -673,7 +656,7 @@ namespace BansheeEngine
 				if (cameraInLightGeometry)
 					continue;
 
-				mPointLightOutMat->setParameters(light.internal);
+				mPointLightOutMat->setPerLightParams(light.internal);
 
 				SPtr<MeshCore> mesh = light.internal->getMesh();
 				gRendererUtility().draw(mesh, mesh->getProperties().getSubMesh(0));
@@ -697,10 +680,7 @@ namespace BansheeEngine
 			mStaticHandler->bindPerObjectBuffers(*renderElem);
 
 			if (iter->applyPass)
-			{
-				SPtr<PassCore> pass = material->getPass(iter->passIdx);
-				setPass(pass);
-			}
+				RendererUtility::instance().setPass(material, iter->passIdx, false);
 
 			SPtr<PassParametersCore> passParams = material->getPassParameters(iter->passIdx);
 
@@ -997,57 +977,6 @@ namespace BansheeEngine
 		}
 	}
 
-	void RenderBeast::setPass(const SPtr<PassCore>& pass)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		RenderAPICore& rs = RenderAPICore::instance();
-
-		struct StageData
-		{
-			GpuProgramType type;
-			bool enable;
-			SPtr<GpuProgramCore> program;
-		};
-
-		const UINT32 numStages = 6;
-		StageData stages[numStages] =
-		{
-			{ GPT_VERTEX_PROGRAM, pass->hasVertexProgram(), pass->getVertexProgram() },
-			{ GPT_FRAGMENT_PROGRAM, pass->hasFragmentProgram(), pass->getFragmentProgram() },
-			{ GPT_GEOMETRY_PROGRAM, pass->hasGeometryProgram(), pass->getGeometryProgram() },
-			{ GPT_HULL_PROGRAM, pass->hasHullProgram(), pass->getHullProgram() },
-			{ GPT_DOMAIN_PROGRAM, pass->hasDomainProgram(), pass->getDomainProgram() },
-			{ GPT_COMPUTE_PROGRAM, pass->hasComputeProgram(), pass->getComputeProgram() }
-		};
-
-		for (UINT32 i = 0; i < numStages; i++)
-		{
-			const StageData& stage = stages[i];
-
-			if (stage.enable)
-				rs.bindGpuProgram(stage.program);
-			else
-				rs.unbindGpuProgram(stage.type);
-		}
-
-		// Set up non-texture related pass settings
-		if (pass->getBlendState() != nullptr)
-			rs.setBlendState(pass->getBlendState());
-		else
-			rs.setBlendState(BlendStateCore::getDefault());
-
-		if (pass->getDepthStencilState() != nullptr)
-			rs.setDepthStencilState(pass->getDepthStencilState(), pass->getStencilRefValue());
-		else
-			rs.setDepthStencilState(DepthStencilStateCore::getDefault(), pass->getStencilRefValue());
-
-		if (pass->getRasterizerState() != nullptr)
-			rs.setRasterizerState(pass->getRasterizerState());
-		else
-			rs.setRasterizerState(RasterizerStateCore::getDefault());
-	}
-
 	void RenderBeast::setPassParams(const SPtr<PassParametersCore>& passParams, const PassSamplerOverrides* samplerOverrides)
 	{
 		THROW_IF_NOT_CORE_THREAD;