Procházet zdrojové kódy

WIP: macOS port
- MSAA now properly triggers on pixels that require it (coverage is calculated)
- Indirect lighting SH coefficients are now evaluated properly (workaround due to a macOS driver bug)

Marko Pintera před 7 roky
rodič
revize
99efde59d5

+ 19 - 9
Data/Raw/Engine/Shaders/IrradianceComputeSHFrag.bsl

@@ -19,9 +19,10 @@ technique IrradianceComputeSHFrag
 		{
 			uint gCubeFace;
 			uint gFaceSize;
-			uint gCoeffIdx;
-		}			
-				
+			uint gCoeffEntryIdx;
+			uint gCoeffComponentIdx;
+		}
+	
 		float4 fsmain(VStoFS input) : SV_Target0
 		{
 			// Move to [-1,1] range
@@ -36,15 +37,24 @@ technique IrradianceComputeSHFrag
 			float invFaceSize = 1.0f / gFaceSize;
 			float weight = texelSolidAngle(uv.x, uv.y, invFaceSize);
 			
-			SHVector shBasis = SHBasis(dir);
+			SHVector b = SHBasis(dir);
+
+			// Copy to array of float4’s because of a driver bug on macOS that causes
+			// non-const indexing of an array of floats to return incorrect values
+			float4 v[3];
+			v[0] = float4(b.v[0], b.v[1], b.v[2], b.v[3]);
+			v[1] = float4(b.v[4], b.v[5], b.v[6], b.v[7]);
+			v[2] = float4(b.v[8], 0.0f, 0.0f, 0.0f);
+
 			float3 radiance = gInputTex.SampleLevel(gInputSamp, dir, 0).rgb;
-												
+			float shCoeff = v[gCoeffEntryIdx][gCoeffComponentIdx];			
+		
 			float4 output;
-			output.r = shBasis.v[gCoeffIdx] * radiance.r * weight;
-			output.g = shBasis.v[gCoeffIdx] * radiance.g * weight;
-			output.b = shBasis.v[gCoeffIdx] * radiance.b * weight;
+			output.r = shCoeff * radiance.r * weight;
+			output.g = shCoeff * radiance.g * weight;
+			output.b = shCoeff * radiance.b * weight;
 			output.a = weight;
-			
+
 			return output;
 		}
 	};

+ 2 - 1
Source/RenderBeast/BsRenderBeastIBLUtility.cpp

@@ -186,7 +186,8 @@ namespace bs { namespace ct
 
 		gIrradianceComputeSHFragParamDef.gCubeFace.set(mParamBuffer, face);
 		gIrradianceComputeSHFragParamDef.gFaceSize.set(mParamBuffer, source->getProperties().getWidth());
-		gIrradianceComputeSHFragParamDef.gCoeffIdx.set(mParamBuffer, coefficientIdx);
+		gIrradianceComputeSHFragParamDef.gCoeffEntryIdx.set(mParamBuffer, coefficientIdx / 4);
+		gIrradianceComputeSHFragParamDef.gCoeffComponentIdx.set(mParamBuffer, coefficientIdx % 4);
 
 		// Render
 		RenderAPI& rapi = RenderAPI::instance();

+ 2 - 1
Source/RenderBeast/BsRenderBeastIBLUtility.h

@@ -211,7 +211,8 @@ namespace bs { namespace ct
 	BS_PARAM_BLOCK_BEGIN(IrradianceComputeSHFragParamDef)
 		BS_PARAM_BLOCK_ENTRY(int, gCubeFace)
 		BS_PARAM_BLOCK_ENTRY(int, gFaceSize)
-		BS_PARAM_BLOCK_ENTRY(int, gCoeffIdx)
+		BS_PARAM_BLOCK_ENTRY(int, gCoeffEntryIdx)
+		BS_PARAM_BLOCK_ENTRY(int, gCoeffComponentIdx)
 	BS_PARAM_BLOCK_END
 
 	extern IrradianceComputeSHFragParamDef gIrradianceComputeSHFragParamDef;

+ 6 - 0
Source/RenderBeast/BsRenderCompositor.cpp

@@ -781,6 +781,9 @@ namespace bs { namespace ct
 				deps.push_back(RCNodeUnflattenLightAccum::getNodeId());
 		}
 
+		if(view.getProperties().numSamples > 1)
+			deps.push_back(RCNodeMSAACoverage::getNodeId());
+
 		return deps;
 	}
 
@@ -943,6 +946,9 @@ namespace bs { namespace ct
 
 		deps.push_back(RCNodeStandardDeferredLighting::getNodeId());
 
+		if(view.getProperties().numSamples > 1)
+			deps.push_back(RCNodeMSAACoverage::getNodeId());
+
 		return deps;
 	}
 	void RCNodeUnflattenLightAccum::render(const RenderCompositorNodeInputs& inputs)