Parcourir la source

Removing reliance on shader semantics

BearishSun il y a 8 ans
Parent
commit
3eb9c8b634

+ 0 - 25
Source/BansheeCore/Include/BsRenderer.h

@@ -17,31 +17,6 @@ namespace bs
 	 *  @{
 	 */
 
-	/**
-	 * Available parameter block semantics that allow the renderer to identify the use of a GPU program parameter block 
-	 * specified in a shader.
-	 */
-	static StringID RBS_Static = "Static";
-	static StringID RBS_PerCamera = "PerCamera";
-	static StringID RBS_PerFrame = "PerFrame";
-	static StringID RBS_PerObject = "PerObject";
-	static StringID RBS_PerCall = "PerCall";
-
-	/**
-	 * Available parameter semantics that allow the renderer to identify the use of a GPU parameter specified in a shader.
-	 */
-	static StringID RPS_WorldViewProjTfrm = "WVP";
-	static StringID RPS_ViewProjTfrm = "VP";
-	static StringID RPS_ProjTfrm = "P";
-	static StringID RPS_ViewTfrm = "V";
-	static StringID RPS_WorldTfrm = "W";
-	static StringID RPS_InvWorldTfrm = "IW";
-	static StringID RPS_WorldNoScaleTfrm = "WNoScale";
-	static StringID RPS_InvWorldNoScaleTfrm = "IWNoScale";
-	static StringID RPS_WorldDeterminantSign = "WorldDeterminantSign";
-	static StringID RPS_Diffuse = "Diffuse";
-	static StringID RPS_ViewDir = "ViewDir";
-
 	/** Technique tags. */
 	static StringID RTag_Skinned = "Skinned";
 	static StringID RTag_Morph = "Morph";

+ 1 - 11
Source/BansheeEditor/Source/BsScenePicking.cpp

@@ -151,17 +151,7 @@ namespace bs
 
 						HTexture mainTexture;
 						if (useAlphaShader)
-						{
-							const Map<String, SHADER_OBJECT_PARAM_DESC>& textureParams = originalMat->getShader()->getTextureParams();
-							for (auto& objectParam : textureParams)
-							{
-								if (objectParam.second.rendererSemantic == ct::RPS_Diffuse)
-								{
-									mainTexture = originalMat->getTexture(objectParam.first);
-									break;
-								}
-							}
-						}
+							mainTexture = originalMat->getTexture("gAlbedoTex");
 
 						idxToRenderable[idx] = so;
 

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

@@ -25,13 +25,6 @@ namespace bs
 	 *  @{
 	 */
 
-	/** Semantics that may be used for signaling the renderer for what is a certain shader parameter used for. */
-	static StringID RPS_GBufferA = "GBufferA";
-	static StringID RPS_GBufferB = "GBufferB";
-	static StringID RPS_GBufferC = "GBufferC";
-	static StringID RPS_GBufferDepth = "GBufferDepth";
-	static StringID RPS_BoneMatrices = "BoneMatrices";
-
 	/**
 	 * Default renderer for Banshee. Performs frustum culling, sorting and renders all scene objects while applying
 	 * lighting, shadowing, special effects and post-processing.

+ 4 - 12
Source/RenderBeast/Source/BsImageBasedLighting.cpp

@@ -127,18 +127,10 @@ namespace bs { namespace ct
 	{
 		SPtr<GpuParams> params = mParamsSet->getGpuParams();
 
-		auto& texParams = mMaterial->getShader()->getTextureParams();
-		for (auto& entry : texParams)
-		{
-			if (entry.second.rendererSemantic == RPS_GBufferA)
-				params->getTextureParam(GPT_COMPUTE_PROGRAM, entry.second.name, mGBufferA);
-			else if (entry.second.rendererSemantic == RPS_GBufferB)
-				params->getTextureParam(GPT_COMPUTE_PROGRAM, entry.second.name, mGBufferB);
-			else if (entry.second.rendererSemantic == RPS_GBufferC)
-				params->getTextureParam(GPT_COMPUTE_PROGRAM, entry.second.name, mGBufferC);
-			else if (entry.second.rendererSemantic == RPS_GBufferDepth)
-				params->getTextureParam(GPT_COMPUTE_PROGRAM, entry.second.name, mGBufferDepth);
-		}
+		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gGBufferATex", mGBufferA);
+		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gGBufferBTex", mGBufferB);
+		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gGBufferCTex", mGBufferC);
+		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gDepthBufferTex", mGBufferDepth);
 
 		if (mSampleCount > 1)
 		{

+ 4 - 12
Source/RenderBeast/Source/BsLightRendering.cpp

@@ -101,18 +101,10 @@ namespace bs { namespace ct
 	{
 		SPtr<GpuParams> params = mParamsSet->getGpuParams();
 
-		auto& texParams = mMaterial->getShader()->getTextureParams();
-		for (auto& entry : texParams)
-		{
-			if (entry.second.rendererSemantic == RPS_GBufferA)
-				params->getTextureParam(GPT_COMPUTE_PROGRAM, entry.second.name, mGBufferA);
-			else if (entry.second.rendererSemantic == RPS_GBufferB)
-				params->getTextureParam(GPT_COMPUTE_PROGRAM, entry.second.name, mGBufferB);
-			else if (entry.second.rendererSemantic == RPS_GBufferC)
-				params->getTextureParam(GPT_COMPUTE_PROGRAM, entry.second.name, mGBufferC);
-			else if (entry.second.rendererSemantic == RPS_GBufferDepth)
-				params->getTextureParam(GPT_COMPUTE_PROGRAM, entry.second.name, mGBufferDepth);
-		}
+		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gGBufferATex", mGBufferA);
+		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gGBufferBTex", mGBufferB);
+		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gGBufferCTex", mGBufferC);
+		params->getTextureParam(GPT_COMPUTE_PROGRAM, "gDepthBufferTex", mGBufferDepth);
 
 		params->getBufferParam(GPT_COMPUTE_PROGRAM, "gLights", mLightBufferParam);
 

+ 14 - 35
Source/RenderBeast/Source/BsObjectRendering.cpp

@@ -33,33 +33,24 @@ namespace bs { namespace ct
 			return;
 		}
 
+		SPtr<GpuParams> gpuParams = element.params->getGpuParams();
+
 		// Note: Perhaps perform buffer validation to ensure expected buffer has the same size and layout as the provided
 		// buffer, and show a warning otherwise. But this is perhaps better handled on a higher level.
-		const Map<String, SHADER_PARAM_BLOCK_DESC>& paramBlockDescs = shader->getParamBlocks();
+		if(shader->hasParamBlock("PerFrame"))
+			element.params->setParamBlockBuffer("PerFrame", mPerFrameParamBuffer, true);
 
-		for (auto& paramBlockDesc : paramBlockDescs)
-		{
-			if (paramBlockDesc.second.rendererSemantic == RBS_PerFrame)
-				element.params->setParamBlockBuffer(paramBlockDesc.second.name, mPerFrameParamBuffer, true);
-			else if (paramBlockDesc.second.rendererSemantic == RBS_PerObject)
-			{
-				element.params->setParamBlockBuffer(paramBlockDesc.second.name,
-													owner.perObjectParamBuffer, true);
-			}
-			else if (paramBlockDesc.second.rendererSemantic == RBS_PerCall)
-			{
-				element.params->setParamBlockBuffer(paramBlockDesc.second.name,
-													owner.perCallParamBuffer, true);
-			}
-			else if(paramBlockDesc.second.rendererSemantic == RBS_PerCamera)
-			{
-				element.perCameraBindingIdx = element.params->getParamBlockBufferIndex(paramBlockDesc.second.name);
-			}
-		}
+		if(shader->hasParamBlock("PerObject"))
+			element.params->setParamBlockBuffer("PerObject", owner.perObjectParamBuffer, true);
+
+		if(shader->hasParamBlock("PerCall"))
+			element.params->setParamBlockBuffer("PerCall", owner.perCallParamBuffer, true);
+
+		if(shader->hasParamBlock("PerCamera"))
+			element.perCameraBindingIdx = element.params->getParamBlockBufferIndex("PerCamera");
 
 		element.gridParamsBindingIdx = element.params->getParamBlockBufferIndex("GridParams");
 
-		SPtr<GpuParams> gpuParams = element.params->getGpuParams();
 		if (gpuParams->hasBuffer(GPT_FRAGMENT_PROGRAM, "gLights"))
 			gpuParams->getBufferParam(GPT_FRAGMENT_PROGRAM, "gLights", element.lightsBufferParam);
 
@@ -74,20 +65,8 @@ namespace bs { namespace ct
 
 		element.imageBasedParams.populate(element.params, GPT_FRAGMENT_PROGRAM, true, true);
 
-		const Map<String, SHADER_OBJECT_PARAM_DESC>& bufferDescs = shader->getBufferParams();
-		String boneMatricesParamName;
-
-		for(auto& entry : bufferDescs)
-		{
-			if (entry.second.rendererSemantic == RPS_BoneMatrices)
-				boneMatricesParamName = entry.second.name;
-		}
-		
-		if (!boneMatricesParamName.empty())
-		{
-			MaterialParamBuffer boneMatricesParam = element.material->getParamBuffer(boneMatricesParamName);
-			boneMatricesParam.set(element.boneMatrixBuffer);
-		}
+		if (gpuParams->hasBuffer(GPT_VERTEX_PROGRAM, "boneMatrices"))
+			gpuParams->setBuffer(GPT_VERTEX_PROGRAM, "boneMatrices", element.boneMatrixBuffer);
 	}
 
 	void ObjectRenderer::setParamFrameParams(float time)