Quellcode durchsuchen

MSAA support fully working on DirectX, OpenGL and Vulkan

BearishSun vor 8 Jahren
Ursprung
Commit
f4dd2fc1b2

+ 5 - 3
Data/Raw/Engine/Shaders/TiledDeferredLighting.bsl

@@ -644,7 +644,8 @@ Technique
 				{
 				{
 					#if MSAA_COUNT > 1
 					#if MSAA_COUNT > 1
 					vec4 lighting = getLighting(clipSpacePos.xy, surfaceData[0]);
 					vec4 lighting = getLighting(clipSpacePos.xy, surfaceData[0]);
-					imageStore(gOutput, pixelPos, 0, lighting);
+					vec4 existingValue = imageLoad(gOutput, pixelPos, 0);
+					imageStore(gOutput, pixelPos, 0, vec4(existingValue.rgb + lighting.rgb, lighting.a));
 
 
 					bool doPerSampleShading = needsPerSampleShading(surfaceData);
 					bool doPerSampleShading = needsPerSampleShading(surfaceData);
 					if(doPerSampleShading)
 					if(doPerSampleShading)
@@ -652,13 +653,14 @@ Technique
 						for(int i = 1; i < MSAA_COUNT; ++i)
 						for(int i = 1; i < MSAA_COUNT; ++i)
 						{
 						{
 							lighting = getLighting(clipSpacePos.xy, surfaceData[i]);
 							lighting = getLighting(clipSpacePos.xy, surfaceData[i]);
-							imageStore(gOutput, pixelPos, i, lighting);
+							existingValue = imageLoad(gOutput, pixelPos, i);
+							imageStore(gOutput, pixelPos, i, vec4(existingValue.rgb + lighting.rgb, lighting.a));
 						}
 						}
 					}
 					}
 					else // Splat same information to all samples
 					else // Splat same information to all samples
 					{
 					{
 						for(int i = 1; i < MSAA_COUNT; ++i)
 						for(int i = 1; i < MSAA_COUNT; ++i)
-							imageStore(gOutput, pixelPos, i, lighting);
+							imageStore(gOutput, pixelPos, i, vec4(existingValue.rgb + lighting.rgb, lighting.a));
 					}
 					}
 					
 					
 					#else
 					#else

+ 9 - 1
Source/BansheeD3D11RenderAPI/Source/BsD3D11Texture.cpp

@@ -430,7 +430,15 @@ namespace bs { namespace ct
             desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
             desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
 
 
 		if ((usage & TU_LOADSTORE) != 0)
 		if ((usage & TU_LOADSTORE) != 0)
-			desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS;
+		{
+			if(desc.SampleDesc.Count <= 1)
+				desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS;
+			else
+			{
+				LOGWRN("Unable to create a load-store texture with multiple samples. This is not supported on DirectX 11. "
+					   "Ignoring load-store usage flag.");
+			}
+		}
 
 
 		// Create the texture
 		// Create the texture
 		D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPI::instancePtr());
 		D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPI::instancePtr());

+ 16 - 9
Source/BansheeGLRenderAPI/Source/BsGLRenderAPI.cpp

@@ -484,19 +484,26 @@ namespace bs { namespace ct
 						if (!activateGLTextureUnit(unit))
 						if (!activateGLTextureUnit(unit))
 							continue;
 							continue;
 
 
-						const SamplerProperties& stateProps = samplerState->getProperties();
+						bool isMultisample = mTextureInfos[unit].type == GL_TEXTURE_2D_MULTISAMPLE ||
+							mTextureInfos[unit].type == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
 
 
-						setTextureFiltering(unit, FT_MIN, stateProps.getTextureFiltering(FT_MIN));
-						setTextureFiltering(unit, FT_MAG, stateProps.getTextureFiltering(FT_MAG));
-						setTextureFiltering(unit, FT_MIP, stateProps.getTextureFiltering(FT_MIP));
+						// No sampler options for multisampled textures
+						if (!isMultisample)
+						{
+							const SamplerProperties& stateProps = samplerState->getProperties();
+
+							setTextureFiltering(unit, FT_MIN, stateProps.getTextureFiltering(FT_MIN));
+							setTextureFiltering(unit, FT_MAG, stateProps.getTextureFiltering(FT_MAG));
+							setTextureFiltering(unit, FT_MIP, stateProps.getTextureFiltering(FT_MIP));
 
 
-						setTextureAnisotropy(unit, stateProps.getTextureAnisotropy());
-						setTextureMipmapBias(unit, stateProps.getTextureMipmapBias());
+							setTextureAnisotropy(unit, stateProps.getTextureAnisotropy());
+							setTextureMipmapBias(unit, stateProps.getTextureMipmapBias());
 
 
-						const UVWAddressingMode& uvw = stateProps.getTextureAddressingMode();
-						setTextureAddressingMode(unit, uvw);
+							const UVWAddressingMode& uvw = stateProps.getTextureAddressingMode();
+							setTextureAddressingMode(unit, uvw);
 
 
-						setTextureBorderColor(unit, stateProps.getBorderColor());
+							setTextureBorderColor(unit, stateProps.getBorderColor());
+						}
 					}
 					}
 
 
 					for(auto& entry : paramDesc->buffers)
 					for(auto& entry : paramDesc->buffers)

+ 5 - 3
Source/RenderBeast/Source/BsLightRendering.cpp

@@ -129,7 +129,8 @@ namespace bs { namespace ct
 
 
 		mParamsSet->setParamBlockBuffer("PerCamera", perCamera, true);
 		mParamsSet->setParamBlockBuffer("PerCamera", perCamera, true);
 
 
-		if (mSampleCount > 1)
+		const RenderAPIInfo& rapiInfo = RenderAPI::instance().getAPIInfo();
+		if (mSampleCount > 1 && !rapiInfo.isFlagSet(RenderAPIFeatureFlag::MSAAImageStores))
 		{
 		{
 			SPtr<GpuBuffer> sceneColorBuffer = gbuffer->getFlattenedSceneColorBuffer();
 			SPtr<GpuBuffer> sceneColorBuffer = gbuffer->getFlattenedSceneColorBuffer();
 			mOutputBufferParam.set(sceneColorBuffer);
 			mOutputBufferParam.set(sceneColorBuffer);
@@ -229,7 +230,8 @@ namespace bs { namespace ct
 
 
 		gRendererUtility().setPass(mMaterial, 0);
 		gRendererUtility().setPass(mMaterial, 0);
 		gRendererUtility().setPassParams(mParamsSet);
 		gRendererUtility().setPassParams(mParamsSet);
-		gRendererUtility().drawScreenQuad();
-	}
 
 
+		Rect2 area(0.0f, 0.0f, (float)props.getWidth(), (float)props.getHeight());
+		gRendererUtility().drawScreenQuad(area);
+	}
 }}
 }}

+ 1 - 1
Source/RenderBeast/Source/BsRenderBeast.cpp

@@ -963,7 +963,7 @@ namespace bs { namespace ct
 			}
 			}
 
 
 			// Post-processing code also takes care of writting to the final output target
 			// Post-processing code also takes care of writting to the final output target
-			PostProcessing::instance().postProcess(viewInfo, renderTargets->getSceneColor(), frameDelta);
+			PostProcessing::instance().postProcess(viewInfo, renderTargets->getSceneColorNonMSAA(), frameDelta);
 		}
 		}
 		else
 		else
 		{
 		{