Browse Source

WIP: Getting OpenGL up to date
- Fixed light probe shaders when MSAA is enabled

BearishSun 8 years ago
parent
commit
38f39b60ea

+ 14 - 5
Data/Raw/Engine/Shaders/TetrahedraRender.bsl

@@ -53,7 +53,12 @@ technique TetrahedraRender
 		#else
 		Texture2D gDepthBufferTex;
 		SamplerState gDepthBufferSamp;
-		#endif		
+		#endif
+		
+		cbuffer Params
+		{
+			int2 gDepthTexSize;
+		};
 		
 		uint fsmain(VStoFS input
 		#if MSAA && !MSAA_RESOLVE_0TH
@@ -61,16 +66,20 @@ technique TetrahedraRender
 		#endif
 		) : SV_Target0
 		{
+			float2 ndcPos = input.clipPos.xy / input.clipPos.w;
+			float2 uv = NDCToUV(ndcPos);
+		
 			float sceneDepth;
 			#if MSAA
+				int2 pixelPos = uv * gDepthTexSize;
+			
 				#if MSAA_RESOLVE_0TH
-					sceneDepth = gDepthBufferTex.Load(trunc(input.position.xy), 0);
+					sceneDepth = gDepthBufferTex.Load(pixelPos, 0);
 				#else
-					sceneDepth = gDepthBufferTex.Load(trunc(input.position.xy), sampleIdx);
+					sceneDepth = gDepthBufferTex.Load(pixelPos, sampleIdx);
 				#endif
 			#else
-				float2 ndcPos = input.clipPos.xy / input.clipPos.w;
-				sceneDepth = gDepthBufferTex.Sample(gDepthBufferSamp, NDCToUV(ndcPos));
+				sceneDepth = gDepthBufferTex.Sample(gDepthBufferSamp, uv);
 			#endif
 			
 			float currentDepth = input.position.z;

+ 10 - 0
Source/RenderBeast/BsLightProbes.cpp

@@ -14,6 +14,8 @@
 
 namespace bs { namespace ct 
 {
+	TetrahedraRenderParamDef gTetrahedraRenderParamDef;
+
 	ShaderVariation TetrahedraRenderMat::VAR_FullMSAA = ShaderVariation({
 		ShaderVariation::Param("MSAA", true)
 	});
@@ -45,6 +47,9 @@ namespace bs { namespace ct
 			SPtr<SamplerState> pointSampState = SamplerState::create(pointSampDesc);
 			params->setSamplerState(GPT_FRAGMENT_PROGRAM, "gDepthBufferSamp", pointSampState);
 		}
+
+		mParamBuffer = gTetrahedraRenderParamDef.createBuffer();
+		mParamsSet->setParamBlockBuffer("Params", mParamBuffer);
 	}
 
 	void TetrahedraRenderMat::_initVariations(ShaderVariations& variations)
@@ -57,6 +62,11 @@ namespace bs { namespace ct
 	void TetrahedraRenderMat::execute(const RendererView& view, const SPtr<Texture>& sceneDepth, const SPtr<Mesh>& mesh, 
 		const SPtr<RenderTexture>& output)
 	{
+		const TextureProperties& texProps = sceneDepth->getProperties();
+
+		Vector2I texSize(texProps.getWidth(), texProps.getHeight());
+		gTetrahedraRenderParamDef.gDepthTexSize.set(mParamBuffer, texSize);
+
 		mDepthBufferTex.set(sceneDepth);
 		mParamsSet->setParamBlockBuffer("PerCamera", view.getPerViewBuffer(), true);
 

+ 7 - 0
Source/RenderBeast/BsLightProbes.h

@@ -22,6 +22,12 @@ namespace bs { namespace ct
 	 *  @{
 	 */
 
+	BS_PARAM_BLOCK_BEGIN(TetrahedraRenderParamDef)
+		BS_PARAM_BLOCK_ENTRY(Vector2I, gDepthTexSize)
+	BS_PARAM_BLOCK_END
+
+	extern TetrahedraRenderParamDef gTetrahedraRenderParamDef;
+
 	/** 
 	 * Shader that renders the tetrahedra used for light probe evaluation. Tetrahedra depth is compare with current scene
 	 * depth, and for each scene pixel the matching tetrahedron index is written to the output target.
@@ -61,6 +67,7 @@ namespace bs { namespace ct
 		 */
 		static TetrahedraRenderMat* getVariation(bool msaa, bool singleSampleMSAA);
 	private:
+		SPtr<GpuParamBlockBuffer> mParamBuffer;
 		GpuParamTexture mDepthBufferTex;
 
 		static ShaderVariation VAR_FullMSAA;