Parcourir la source

DOF now works with MSAA

BearishSun il y a 8 ans
Parent
commit
a5ac5b5584

+ 7 - 7
Data/Raw/Engine/Shaders/PPGaussianBlur.bsl

@@ -27,22 +27,22 @@ technique PPGaussianBlur
 			{
 				{
 					float2 uv = input.uv0 + gSampleOffsets[idx * 2 + 0].xy;
-					output += gInputTex.Sample(gInputSamp, uv) * gSampleWeights[idx].x;
+					output += gInputTex.SampleLevel(gInputSamp, uv, 0) * gSampleWeights[idx].x;
 				}
 				
 				{
 					float2 uv = input.uv0 + gSampleOffsets[idx * 2 + 0].zw;
-					output += gInputTex.Sample(gInputSamp, uv) * gSampleWeights[idx].y;
+					output += gInputTex.SampleLevel(gInputSamp, uv, 0) * gSampleWeights[idx].y;
 				}
 				
 				{
 					float2 uv = input.uv0 + gSampleOffsets[idx * 2 + 1].xy;
-					output += gInputTex.Sample(gInputSamp, uv) * gSampleWeights[idx].z;
+					output += gInputTex.SampleLevel(gInputSamp, uv, 0) * gSampleWeights[idx].z;
 				}
 				
 				{
 					float2 uv = input.uv0 + gSampleOffsets[idx * 2 + 1].zw;
-					output += gInputTex.Sample(gInputSamp, uv) * gSampleWeights[idx].w;
+					output += gInputTex.SampleLevel(gInputSamp, uv, 0) * gSampleWeights[idx].w;
 				}
 			}
 			
@@ -51,19 +51,19 @@ technique PPGaussianBlur
 			if(extraSamples >= 1)
 			{
 				float2 uv = input.uv0 + gSampleOffsets[idx * 2 + 0].xy;
-				output += gInputTex.Sample(gInputSamp, uv) * gSampleWeights[idx].x;
+				output += gInputTex.SampleLevel(gInputSamp, uv, 0) * gSampleWeights[idx].x;
 				
 				[branch]
 				if(extraSamples >= 2)
 				{
 					float2 uv = input.uv0 + gSampleOffsets[idx * 2 + 0].zw;
-					output += gInputTex.Sample(gInputSamp, uv) * gSampleWeights[idx].y;
+					output += gInputTex.SampleLevel(gInputSamp, uv, 0) * gSampleWeights[idx].y;
 					
 					[branch]
 					if(extraSamples >= 3)
 					{
 						float2 uv = input.uv0 + gSampleOffsets[idx * 2 + 1].xy;
-						output += gInputTex.Sample(gInputSamp, uv) * gSampleWeights[idx].z;
+						output += gInputTex.SampleLevel(gInputSamp, uv, 0) * gSampleWeights[idx].z;
 					}
 				}				
 			}

+ 1 - 1
Data/Raw/Engine/Shaders/PPGaussianDOFCombine.bsl

@@ -19,7 +19,7 @@ technique PPGaussianDOFCombine
 		float3 fsmain(VStoFS input) : SV_Target0
 		{
 			float4 focusedColor = gFocusedTex.Sample(gColorSamp, input.uv0);
-			float depth = -convertFromDeviceZ(gDepthTex.Sample(gDepthSamp, input.uv0));
+			float depth = -convertFromDeviceZ(gDepthTex.SampleLevel(gDepthSamp, input.uv0, 0));
 			
 			float4 nearColor = 0;
 			float4 farColor = 0;

+ 0 - 4
Data/Raw/Engine/Shaders/PPGaussianDOFSeparate.bsl

@@ -11,12 +11,8 @@ technique PPGaussianDOFSeparate
 		SamplerState gColorSamp;
 		Texture2D gColorTex;
 		
-		#if MSAA
-		Texture2DMS<float> gDepthTex;
-		#else
 		SamplerState gDepthSamp;
 		Texture2D gDepthTex;
-		#endif
 		
 		void addSample(float2 uv, float2 offset, float depth, inout float4 nearColor, inout float4 farColor)
 		{

+ 6 - 2
Source/RenderBeast/Source/BsPostProcessing.cpp

@@ -1164,8 +1164,12 @@ namespace bs { namespace ct
 		{
 			SPtr<RenderTarget> dofTarget = viewProps.target;
 
-			mGaussianDOF.execute(renderTargets->getResolvedSceneColor(true), renderTargets->getSceneDepth(), dofTarget,
-				*viewInfo, settings.depthOfField);
+			// Use the HiZ buffer instead of main scene depth since DOF shaders don't support MSAA, and HiZ is guaranteed to
+			// be resolved.
+			SPtr<Texture> sceneDepth = renderTargets->getHiZ();
+
+			mGaussianDOF.execute(renderTargets->getResolvedSceneColor(true), sceneDepth, dofTarget, *viewInfo, 
+				settings.depthOfField);
 		}
 
 		if(performDOF)