Przeglądaj źródła

WIP: Deferred MSAA
- MSAA functional without no coverage evaluation

BearishSun 8 lat temu
rodzic
commit
af3f03f836

+ 15 - 14
Data/Raw/Engine/Includes/TemporalResolve.bslinc

@@ -267,6 +267,7 @@ mixin TemporalResolve
 			float exposureScale,
 			#endif // TEMPORAL_TONEMAP
 			float2 uv,
+			float2 uvColor, // Relevant for MSAA as uv is in screen space, but we might need the normalized one for color
 			float2 ndcPos, // Can be derived from UV, but we usually have it for free, so pass it directly
 			int sampleIdx)
 		{
@@ -317,11 +318,11 @@ mixin TemporalResolve
 			#if TEMPORAL_YCOCG
 			// YCOCG only requires a + pattern for good quality
 			float3 neighbor[5];
-			neighbor[0] = _SAMPLE_COLOR(sceneColor, uv, int2(-1,  0));
-			neighbor[1] = _SAMPLE_COLOR(sceneColor, uv, int2( 0, -1));
-			neighbor[2] = _SAMPLE_COLOR(sceneColor, uv, int2( 0,  0));
-			neighbor[3] = _SAMPLE_COLOR(sceneColor, uv, int2( 1,  0));
-			neighbor[4] = _SAMPLE_COLOR(sceneColor, uv, int2( 0,  1));
+			neighbor[0] = _SAMPLE_COLOR(sceneColor, uvColor, int2(-1,  0));
+			neighbor[1] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 0, -1));
+			neighbor[2] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 0,  0));
+			neighbor[3] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 1,  0));
+			neighbor[4] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 0,  1));
 			
 			float3 filtered = 0;
 			[unroll]
@@ -338,15 +339,15 @@ mixin TemporalResolve
 			
 			#else // TEMPORAL_YCOCG
 			float3 neighbor[9];
-			neighbor[0] = _SAMPLE_COLOR(sceneColor, uv, int2(-1, -1));
-			neighbor[1] = _SAMPLE_COLOR(sceneColor, uv, int2( 0, -1));
-			neighbor[2] = _SAMPLE_COLOR(sceneColor, uv, int2( 1, -1));
-			neighbor[3] = _SAMPLE_COLOR(sceneColor, uv, int2(-1,  0));
-			neighbor[4] = _SAMPLE_COLOR(sceneColor, uv, int2( 0,  0));
-			neighbor[5] = _SAMPLE_COLOR(sceneColor, uv, int2( 1,  0));
-			neighbor[6] = _SAMPLE_COLOR(sceneColor, uv, int2(-1,  1));
-			neighbor[7] = _SAMPLE_COLOR(sceneColor, uv, int2( 0,  1));
-			neighbor[8] = _SAMPLE_COLOR(sceneColor, uv, int2( 1,  1));
+			neighbor[0] = _SAMPLE_COLOR(sceneColor, uvColor, int2(-1, -1));
+			neighbor[1] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 0, -1));
+			neighbor[2] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 1, -1));
+			neighbor[3] = _SAMPLE_COLOR(sceneColor, uvColor, int2(-1,  0));
+			neighbor[4] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 0,  0));
+			neighbor[5] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 1,  0));
+			neighbor[6] = _SAMPLE_COLOR(sceneColor, uvColor, int2(-1,  1));
+			neighbor[7] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 0,  1));
+			neighbor[8] = _SAMPLE_COLOR(sceneColor, uvColor, int2( 1,  1));
 			
 			float3 filtered = 0;
 			[unroll]

+ 6 - 2
Data/Raw/Engine/Shaders/Blit.bsl

@@ -3,7 +3,10 @@ technique Blit
 	depth
 	{
 		read = false;
+		
+		#ifndef DEPTH
 		write = false;
+		#endif
 	};
 
 	code
@@ -39,7 +42,7 @@ technique Blit
 		#else // Assuming depth
 		Texture2DMS<float> gSource;
 		
-		float fsmain(VStoFS input) : SV_Target0
+		float fsmain(VStoFS input, out float depth : SV_Depth) : SV_Target0
 		#endif
 		{
 			int2 iUV = trunc(input.uv0);
@@ -59,7 +62,8 @@ technique Blit
 				for(int i = 1; i < MSAA_COUNT; i++)
 					minVal = min(minVal, gSource.Load(iUV, i));
 					
-				return minVal;
+				depth = minVal;
+				return 0.0f;
 			#endif
 		}
 		

+ 2 - 2
Data/Raw/Engine/Shaders/PPSSRResolve.bsl

@@ -46,13 +46,13 @@ technique PPSSRResolve
 					gSceneDepth, 
 					gSceneColor, gLinearSampler, gSceneColorTexelSize, 
 					gPrevColor, gLinearSampler, gSceneColorTexelSize,
-					gManualExposure, input.position.xy, input.screenPos, 0);
+					gManualExposure, input.position.xy, input.uv0, input.screenPos, 0);
 			#else
 				col.rgb = temporalResolve(
 					gSceneDepth, gPointSampler, gSceneDepthTexelSize,
 					gSceneColor, gLinearSampler, gSceneColorTexelSize, 
 					gPrevColor, gLinearSampler, gSceneColorTexelSize,
-					gManualExposure, input.uv0, input.screenPos, 0);
+					gManualExposure, input.uv0, input.uv0, input.screenPos, 0);
 			#endif
 			
 			col.a = gSceneColor.Sample(gLinearSampler, input.uv0).a;

+ 9 - 4
Source/BansheeEngine/Renderer/BsRendererUtility.cpp

@@ -350,6 +350,7 @@ namespace bs { namespace ct
 		ShaderVariation::Param("MSAA_COUNT", 1),
 		ShaderVariation::Param("COLOR", true)
 	});
+
 	ShaderVariation BlitMat::VAR_2MSAA_Color = ShaderVariation({
 		ShaderVariation::Param("MSAA_COUNT", 2),
 		ShaderVariation::Param("COLOR", true)
@@ -367,22 +368,26 @@ namespace bs { namespace ct
 
 	ShaderVariation BlitMat::VAR_1MSAA_Depth = ShaderVariation({
 		ShaderVariation::Param("MSAA_COUNT", 1),
-		ShaderVariation::Param("COLOR", false)
+		ShaderVariation::Param("COLOR", false),
+		ShaderVariation::Param("DEPTH", true)
 	});
 
 	ShaderVariation BlitMat::VAR_2MSAA_Depth = ShaderVariation({
 		ShaderVariation::Param("MSAA_COUNT", 2),
-		ShaderVariation::Param("COLOR", false)
+		ShaderVariation::Param("COLOR", false),
+		ShaderVariation::Param("DEPTH", true)
 	});
 
 	ShaderVariation BlitMat::VAR_4MSAA_Depth = ShaderVariation({
 		ShaderVariation::Param("MSAA_COUNT", 4),
-		ShaderVariation::Param("COLOR", false)
+		ShaderVariation::Param("COLOR", false),
+		ShaderVariation::Param("DEPTH", true)
 	});
 
 	ShaderVariation BlitMat::VAR_8MSAA_Depth = ShaderVariation({
 		ShaderVariation::Param("MSAA_COUNT", 8),
-		ShaderVariation::Param("COLOR", false)
+		ShaderVariation::Param("COLOR", false),
+		ShaderVariation::Param("DEPTH", true)
 	});
 
 	BlitMat::BlitMat()

+ 1 - 1
Source/RenderBeast/BsPostProcessing.cpp

@@ -1375,7 +1375,7 @@ namespace bs { namespace ct
 
 	void SSRStencilMat::_initVariations(ShaderVariations& variations)
 	{
-		variations.add(VAR_NoMSAA);
+		variations.add(VAR_MSAA);
 		variations.add(VAR_NoMSAA);
 	}
 

+ 2 - 1
Source/RenderBeast/BsRenderCompositor.cpp

@@ -1432,7 +1432,8 @@ namespace bs { namespace ct
 			UINT32 width = viewProps.viewRect.width;
 			UINT32 height = viewProps.viewRect.height;
 
-			output = resPool.get(POOLED_RENDER_TEXTURE_DESC::create2D(PF_D32_S8X24, width, height, TU_RENDERTARGET, 1, false)); 
+			output = resPool.get(POOLED_RENDER_TEXTURE_DESC::create2D(PF_D32_S8X24, width, height, 
+				TU_DEPTHSTENCIL, 1, false)); 
 
 			RenderAPI& rapi = RenderAPI::instance();
 			rapi.setRenderTarget(output->renderTexture);