Просмотр исходного кода

Bugfix: Fixing a visual artifact that appeared in the form of a white sphere visible in reflections
- Also fixed handling of default sampler states defined directly in BSL

BearishSun 8 лет назад
Родитель
Сommit
8dd96ab750

BIN
Data/Engine/Includes/ImageBasedLighting.bslinc.asset


BIN
Data/Engine/Shaders/DeferredIBLFinalize.bsl.asset


BIN
Data/Engine/Shaders/DeferredIBLProbe.bsl.asset


BIN
Data/Engine/Shaders/DeferredIBLSetup.bsl.asset


BIN
Data/Engine/Shaders/DeferredIBLSky.bsl.asset


BIN
Data/Engine/Shaders/LightGridLLCreation.bsl.asset


BIN
Data/Engine/Shaders/TiledDeferredImageBasedLighting.bsl.asset


BIN
Data/Engine/Shaders/TiledDeferredLighting.bsl.asset


BIN
Data/Engine/Shaders/Transparent.bsl.asset


+ 24 - 3
Data/Raw/Engine/Includes/ImageBasedLighting.bslinc

@@ -32,15 +32,36 @@ mixin ImageBasedLighting
 		
 		[internal]
 		Texture2D gAmbientOcclusionTex;
-		SamplerState gAmbientOcclusionSamp;
+		
+		[internal] [alias(gAmbientOcclusionTex)]
+		SamplerState gAmbientOcclusionSamp
+		{
+			Filter = MIN_MAG_MIP_POINT;
+			AddressU = CLAMP;
+			AddressV = CLAMP;
+		};
 		
 		[internal]
 		Texture2D gSSRTex;
-		SamplerState gSSRSamp;
+		
+		[internal] [alias(gSSRTex)]
+		SamplerState gSSRSamp
+		{
+			Filter = MIN_MAG_MIP_POINT;
+			AddressU = CLAMP;
+			AddressV = CLAMP;
+		};
 		
 		[internal]
 		Texture2D gPreintegratedEnvBRDF;
-		SamplerState gPreintegratedEnvBRDFSamp;
+		
+		[internal] [alias(gPreintegratedEnvBRDF)]
+		SamplerState gPreintegratedEnvBRDFSamp
+		{
+			Filter = MIN_MAG_MIP_LINEAR;
+			AddressU = CLAMP;
+			AddressV = CLAMP;
+		};
 		
 		#ifndef STANDARD_DEFERRED
 		StructuredBuffer<ReflProbeData> gReflectionProbes;

+ 16 - 10
Source/BansheeCore/Material/BsShader.cpp

@@ -50,7 +50,8 @@ namespace bs
 	}
 
 	template<bool Core>
-	void TSHADER_DESC<Core>::addParameter(const String& name, const String& gpuVariableName, GpuParamObjectType type, StringID rendererSemantic)
+	void TSHADER_DESC<Core>::addParameter(const String& name, const String& gpuVariableName, GpuParamObjectType type, 
+		StringID rendererSemantic)
 	{
 		UINT32 defaultValueIdx = (UINT32)-1;
 
@@ -58,7 +59,8 @@ namespace bs
 	}
 
 	template<bool Core>
-	void TSHADER_DESC<Core>::addParameter(const String& name, const String& gpuVariableName, GpuParamObjectType type, const SamplerStateType& defaultValue, StringID rendererSemantic)
+	void TSHADER_DESC<Core>::addParameter(const String& name, const String& gpuVariableName, GpuParamObjectType type, 
+		const SamplerStateType& defaultValue, StringID rendererSemantic)
 	{
 		UINT32 defaultValueIdx = (UINT32)-1;
 		if (Shader::isSampler(type) && defaultValue != nullptr)
@@ -71,7 +73,8 @@ namespace bs
 	}
 
 	template<bool Core>
-	void TSHADER_DESC<Core>::addParameter(const String& name, const String& gpuVariableName, GpuParamObjectType type, const TextureType& defaultValue, StringID rendererSemantic)
+	void TSHADER_DESC<Core>::addParameter(const String& name, const String& gpuVariableName, GpuParamObjectType type, 
+		const TextureType& defaultValue, StringID rendererSemantic)
 	{
 		UINT32 defaultValueIdx = (UINT32)-1;
 		if (Shader::isTexture(type) && defaultValue != nullptr)
@@ -84,7 +87,8 @@ namespace bs
 	}
 
 	template<bool Core>
-	void TSHADER_DESC<Core>::addParameterInternal(const String& name, const String& gpuVariableName, GpuParamObjectType type, StringID rendererSemantic, UINT32 defaultValueIdx)
+	void TSHADER_DESC<Core>::addParameterInternal(const String& name, const String& gpuVariableName, 
+		GpuParamObjectType type, StringID rendererSemantic, UINT32 defaultValueIdx)
 	{
 		Map<String, SHADER_OBJECT_PARAM_DESC>* DEST_LOOKUP[] = { &textureParams, &bufferParams, &samplerParams };
 		UINT32 destIdx = 0;
@@ -132,7 +136,8 @@ namespace bs
 	}
 
 	template<bool Core>
-	void TSHADER_DESC<Core>::setParamBlockAttribs(const String& name, bool shared, GpuParamBlockUsage usage, StringID rendererSemantic)
+	void TSHADER_DESC<Core>::setParamBlockAttribs(const String& name, bool shared, GpuParamBlockUsage usage, 
+		StringID rendererSemantic)
 	{
 		SHADER_PARAM_BLOCK_DESC desc;
 		desc.name = name;
@@ -147,7 +152,8 @@ namespace bs
 	template struct TSHADER_DESC<true>;
 
 	template<bool Core>
-	TShader<Core>::TShader(const String& name, const TSHADER_DESC<Core>& desc, const Vector<SPtr<TechniqueType>>& techniques, UINT32 id)
+	TShader<Core>::TShader(const String& name, const TSHADER_DESC<Core>& desc, 
+		const Vector<SPtr<TechniqueType>>& techniques, UINT32 id)
 		:mName(name), mDesc(desc), mTechniques(techniques), mId(id)
 	{ }
 
@@ -378,18 +384,18 @@ namespace bs
 		for (UINT32 i = 0; i < (UINT32)desc.samplerDefaultValues.size(); i++)
 		{
 			if (desc.samplerDefaultValues[i] != nullptr)
-				output.samplerDefaultValues.push_back(desc.samplerDefaultValues[i]->getCore());
+				output.samplerDefaultValues[i] = desc.samplerDefaultValues[i]->getCore();
 			else
-				output.samplerDefaultValues.push_back(nullptr);
+				output.samplerDefaultValues[i] = nullptr;
 		}
 
 		output.textureDefaultValues.resize(desc.textureDefaultValues.size());
 		for (UINT32 i = 0; i < (UINT32)desc.textureDefaultValues.size(); i++)
 		{
 			if (desc.textureDefaultValues[i].isLoaded())
-				output.textureDefaultValues.push_back(desc.textureDefaultValues[i]->getCore());
+				output.textureDefaultValues[i] = desc.textureDefaultValues[i]->getCore();
 			else
-				output.textureDefaultValues.push_back(nullptr);
+				output.textureDefaultValues[i] = nullptr;
 		}
 
 		output.queuePriority = desc.queuePriority;

+ 45 - 0
Source/BansheeEngine/Renderer/BsRendererMaterial.h

@@ -186,6 +186,51 @@ namespace bs { namespace ct
 						mParams = GpuParams::create(mComputePipeline);
 					}
 
+					// Assign default values from the shader
+					const auto& textureParams = mMetaData.shader->getTextureParams();
+					for(auto& param : textureParams)
+					{
+						UINT32 defaultValueIdx = param.second.defaultValueIdx;
+						if(defaultValueIdx == (UINT32)-1)
+							continue;
+
+						for (UINT32 i = 0; i < 6; i++)
+						{
+							GpuProgramType progType = (GpuProgramType)i;
+
+							for(auto& varName : param.second.gpuVariableNames)
+							{
+								if(mParams->hasTexture(progType, varName))
+								{
+									SPtr<Texture> texture = mMetaData.shader->getDefaultTexture(defaultValueIdx);
+									mParams->setTexture(progType, varName, texture);
+								}
+							}
+						}
+					}
+
+					const auto& samplerParams = mMetaData.shader->getSamplerParams();
+					for(auto& param : samplerParams)
+					{
+						UINT32 defaultValueIdx = param.second.defaultValueIdx;
+						if(defaultValueIdx == (UINT32)-1)
+							continue;
+
+						for (UINT32 i = 0; i < 6; i++)
+						{
+							GpuProgramType progType = (GpuProgramType)i;
+
+							for(auto& varName : param.second.gpuVariableNames)
+							{
+								if(mParams->hasSamplerState(progType, varName))
+								{
+									SPtr<SamplerState> samplerState = mMetaData.shader->getDefaultSampler(defaultValueIdx);
+									mParams->setSamplerState(progType, varName, samplerState);
+								}
+							}
+						}
+					}
+
 					mStencilRef = pass->getStencilRefValue();
 				}
 			}

+ 15 - 0
Source/BansheeSL/BsSLFXCompiler.cpp

@@ -421,6 +421,11 @@ namespace bs
 					GpuParamObjectType objType = ReflTypeToTextureType((Xsc::Reflection::BufferType)entry.baseType);
 					if(objType != GPOT_UNKNOWN)
 					{
+						// Ignore parameters that were already registered in some previous variation. Note that this implies
+						// you cannot have same names for different parameters in different variations.
+						if (desc.textureParams.find(ident) != desc.textureParams.end())
+							continue;
+
 						if (entry.defaultValue == -1)
 							desc.addParameter(ident, ident, objType);
 						else
@@ -428,6 +433,11 @@ namespace bs
 					}
 					else
 					{
+						// Ignore parameters that were already registered in some previous variation. Note that this implies
+						// you cannot have same names for different parameters in different variations.
+						if (desc.bufferParams.find(ident) != desc.bufferParams.end())
+							continue;
+
 						objType = ReflTypeToBufferType((Xsc::Reflection::BufferType)entry.baseType);
 						desc.addParameter(ident, ident, objType);
 					}
@@ -438,6 +448,11 @@ namespace bs
 				auto findIter = reflData.samplerStates.find(entry.ident);
 				if (findIter != reflData.samplerStates.end())
 				{
+					// Ignore parameters that were already registered in some previous variation. Note that this implies
+					// you cannot have same names for different parameters in different variations.
+					if(desc.samplerParams.find(ident) != desc.samplerParams.end())
+						continue;
+
 					String alias = findIter->second.alias.c_str();
 
 					if(findIter->second.isNonDefault)

+ 1 - 1
Source/CMakeLists.txt

@@ -5,7 +5,7 @@ project (Banshee)
 set (BS_VERSION_MAJOR 0)
 set (BS_VERSION_MINOR 4)
 
-set (BS_PREBUILT_DEPENDENCIES_VERSION 16)
+set (BS_PREBUILT_DEPENDENCIES_VERSION 17)
 set (BS_SRC_DEPENDENCIES_VERSION 15)
 set (BS_BUILTIN_ASSETS_VERSION 3)
 

+ 0 - 26
Source/RenderBeast/BsImageBasedLighting.cpp

@@ -125,26 +125,12 @@ namespace bs { namespace ct
 
 		// AO
 		if (params->hasTexture(programType, "gAmbientOcclusionTex"))
-		{
 			params->getTextureParam(programType, "gAmbientOcclusionTex", ambientOcclusionTexParam);
 
-			if(params->hasSamplerState(programType, "gAmbientOcclusionSamp"))
-				params->getSamplerStateParam(programType, "gAmbientOcclusionSamp", ambientOcclusionSampParam);
-			else
-				params->getSamplerStateParam(programType, "gAmbientOcclusionTex", ambientOcclusionSampParam);
-		}
-
 		// SSR
 		if (params->hasTexture(programType, "gSSRTex"))
-		{
 			params->getTextureParam(programType, "gSSRTex", ssrTexParam);
 
-			if(params->hasSamplerState(programType, "gSSRSamp"))
-				params->getSamplerStateParam(programType, "gSSRSamp", ssrSampParam);
-			else
-				params->getSamplerStateParam(programType, "gSSRTex", ssrSampParam);
-		}
-
 		if(gridIndices)
 		{
 			if (!optional || params->hasBuffer(programType, "gReflectionProbeIndices"))
@@ -224,18 +210,6 @@ namespace bs { namespace ct
 
 		mImageBasedParams.populate(mParams, GPT_COMPUTE_PROGRAM, false, false, true);
 
-		SAMPLER_STATE_DESC desc;
-		desc.minFilter = FO_POINT;
-		desc.magFilter = FO_POINT;
-		desc.mipFilter = FO_POINT;
-		desc.addressMode.u = TAM_CLAMP;
-		desc.addressMode.v = TAM_CLAMP;
-		desc.addressMode.w = TAM_CLAMP;
-
-		SPtr<SamplerState> samplerState = SamplerState::create(desc);
-		mImageBasedParams.ssrSampParam.set(samplerState);
-		mImageBasedParams.ambientOcclusionSampParam.set(samplerState);
-
 		mParams->setParamBlockBuffer("ReflProbeParams", mReflProbeParamBuffer.buffer);
 	}
 

+ 0 - 3
Source/RenderBeast/BsImageBasedLighting.h

@@ -113,9 +113,6 @@ namespace bs { namespace ct
 		GpuParamTexture preintegratedEnvBRDFParam;
 		GpuParamBuffer reflectionProbesParam;
 
-		GpuParamSampState ambientOcclusionSampParam;
-		GpuParamSampState ssrSampParam;
-
 		GpuParamBuffer reflectionProbeIndicesParam;
 		GpuParamBinding reflProbeParamBindings;
 	};

+ 1 - 14
Source/RenderBeast/BsRenderCompositor.cpp

@@ -1170,17 +1170,7 @@ namespace bs { namespace ct
 	}
 
 	RCNodeClusteredForward::RCNodeClusteredForward()
-	{
-		SAMPLER_STATE_DESC desc;
-		desc.minFilter = FO_POINT;
-		desc.magFilter = FO_POINT;
-		desc.mipFilter = FO_POINT;
-		desc.addressMode.u = TAM_CLAMP;
-		desc.addressMode.v = TAM_CLAMP;
-		desc.addressMode.w = TAM_CLAMP;
-
-		mSSRAOSamplerState = SamplerState::create(desc);
-	}
+	{ }
 
 	void RCNodeClusteredForward::render(const RenderCompositorNodeInputs& inputs)
 	{
@@ -1256,9 +1246,6 @@ namespace bs { namespace ct
 
 				iblParams.reflectionProbeCubemapsTexParam.set(sceneInfo.reflProbeCubemapsTex);
 				iblParams.preintegratedEnvBRDFParam.set(RendererTextures::preintegratedEnvGF);
-
-				iblParams.ssrSampParam.set(mSSRAOSamplerState);
-				iblParams.ambientOcclusionSampParam.set(mSSRAOSamplerState);
 			}
 		}
 

+ 0 - 2
Source/RenderBeast/BsRenderCompositor.h

@@ -423,8 +423,6 @@ namespace ct
 
 		/** @copydoc RenderCompositorNode::clear */
 		void clear() override;
-
-		SPtr<SamplerState> mSSRAOSamplerState;
 	};
 
 	/**

+ 0 - 24
Source/RenderBeast/BsStandardDeferredLighting.cpp

@@ -93,18 +93,6 @@ namespace bs { namespace ct {
 		:mGBufferParams(GPT_FRAGMENT_PROGRAM, mParams)
 	{
 		mIBLParams.populate(mParams, GPT_FRAGMENT_PROGRAM, true, false, false);
-
-		SAMPLER_STATE_DESC desc;
-		desc.minFilter = FO_POINT;
-		desc.magFilter = FO_POINT;
-		desc.mipFilter = FO_POINT;
-		desc.addressMode.u = TAM_CLAMP;
-		desc.addressMode.v = TAM_CLAMP;
-		desc.addressMode.w = TAM_CLAMP;
-
-		SPtr<SamplerState> samplerState = SamplerState::create(desc);
-		mIBLParams.ssrSampParam.set(samplerState);
-		mIBLParams.ambientOcclusionSampParam.set(samplerState);
 	}
 
 	void DeferredIBLSetupMat::bind(const GBufferTextures& gBufferInput, const SPtr<GpuParamBlockBuffer>& perCamera, 
@@ -205,18 +193,6 @@ namespace bs { namespace ct {
 		:mGBufferParams(GPT_FRAGMENT_PROGRAM, mParams)
 	{
 		mIBLParams.populate(mParams, GPT_FRAGMENT_PROGRAM, true, false, false);
-
-		SAMPLER_STATE_DESC desc;
-		desc.minFilter = FO_POINT;
-		desc.magFilter = FO_POINT;
-		desc.mipFilter = FO_POINT;
-		desc.addressMode.u = TAM_CLAMP;
-		desc.addressMode.v = TAM_CLAMP;
-		desc.addressMode.w = TAM_CLAMP;
-
-		SPtr<SamplerState> samplerState = SamplerState::create(desc);
-		mIBLParams.ssrSampParam.set(samplerState);
-		mIBLParams.ambientOcclusionSampParam.set(samplerState);
 	}
 
 	void DeferredIBLSkyMat::bind(const GBufferTextures& gBufferInput, const SPtr<GpuParamBlockBuffer>& perCamera,