فهرست منبع

Feature: Reflection probe rendering working and hooked up with SSR

BearishSun 8 سال پیش
والد
کامیت
751439aecc

+ 1 - 1
Data/Raw/Engine/Includes/ImageBasedLighting.bslinc

@@ -117,7 +117,7 @@ mixin ImageBasedLighting
 			// Calculate contribution
 			//// Shrink the box so fade out happens within box extents
 			float3 reducedExtents = extents - float3(transitionDistance, transitionDistance, transitionDistance);
-			float distToBox = getDistBoxToPoint(originLS * reducedExtents, reducedExtents);
+			float distToBox = getDistBoxToPoint(originLS * extents, reducedExtents);
 			
 			float normalizedDistance = distToBox / transitionDistance;
 			

+ 3 - 3
Data/Raw/Engine/Includes/TemporalResolve.bslinc

@@ -112,16 +112,16 @@ mixin TemporalResolve
 	
 		////////////////////////// HELPER MACROS /////////////////////////
 		#if MSAA
-			#define _TEX2D(n) Texture2DMS n
+			#define _TEX2D(n) Texture2DMS<float> n
 			#if MSAA_COLOR
-				#define _TEXCOLOR(n) Texture2DMS n
+				#define _TEXCOLOR(n) Texture2DMS<float4> n
 			#else
 				#define _TEXCOLOR(n) Texture2D n, SamplerState n##SampState, float2 n##TexelSize
 			#endif
 			
 			#define _PTEX2D(n) n
 			#define _SAMPLE(n, uv) n.Load((int2)uv, sampleIdx)
-			#define _SAMPLEOFF(n, uv, offset) n.Load((int2)(uv) + offset)
+			#define _SAMPLEOFF(n, uv, offset) n.Load((int2)(uv) + offset, sampleIdx)
 			
 			#if MSAA_COLOR
 				#define _SAMPLECOL(n, uv, offset) _SAMPLEOFF(n, uv, offset)

+ 8 - 4
Data/Raw/Engine/Shaders/PPSSRResolve.bsl

@@ -27,7 +27,7 @@ technique PPSSRResolve
 		}
 		
 		#if MSAA
-			Texture2DMS gSceneDepth;
+			Texture2DMS<float> gSceneDepth;
 		#else
 			Texture2D gSceneDepth;
 		#endif	
@@ -38,21 +38,25 @@ technique PPSSRResolve
 		SamplerState gPointSampler;
 		SamplerState gLinearSampler;		
 		
-		float3 fsmain(VStoFS input) : SV_Target0
+		float4 fsmain(VStoFS input) : SV_Target0
 		{
+			float4 col;
 			#if MSAA
-				return temporalResolve(
+				col.rgb = temporalResolve(
 					gSceneDepth, 
 					gSceneColor, gLinearSampler, gSceneColorTexelSize, 
 					gPrevColor, gLinearSampler, gSceneColorTexelSize,
 					gManualExposure, input.position.xy, input.screenPos, 0);
 			#else
-				return temporalResolve(
+				col.rgb = temporalResolve(
 					gSceneDepth, gPointSampler, gSceneDepthTexelSize,
 					gSceneColor, gLinearSampler, gSceneColorTexelSize, 
 					gPrevColor, gLinearSampler, gSceneColorTexelSize,
 					gManualExposure, input.uv0, input.screenPos, 0);
 			#endif
+			
+			col.a = gSceneColor.Sample(gLinearSampler, input.uv0).a;
+			return col;
 		}	
 	};
 };

+ 9 - 4
Data/Raw/Engine/Shaders/TiledDeferredImageBasedLighting.bsl

@@ -76,7 +76,10 @@ technique TiledDeferredImageBasedLighting
 			
 			// Determine minimum and maximum depth values for a tile			
 			InterlockedMin(sTileMinZ, sampleMinZ);
-			InterlockedMax(sTileMaxZ, sampleMaxZ);
+			
+			// Skip samples on the far plane (e.g. skybox) as they ruin the precision
+			if(sampleMaxZ < 1.0f)
+				InterlockedMax(sTileMaxZ, sampleMaxZ);
 			
 			GroupMemoryBarrierWithGroupSync();
 			
@@ -121,8 +124,10 @@ technique TiledDeferredImageBasedLighting
 			for(uint i = 0; i < 5; ++i)
 				corner[i].xy /= corner[i].w;
 		
-			float3 viewMin = float3(corner[0].xy, viewZMin);
-			float3 viewMax = float3(corner[0].xy, viewZMax);
+			// Flip min/max because min = closest to view plane and max = furthest from view plane
+			// but since Z is negative, closest is in fact the maximum and furtest is the minimum
+			float3 viewMin = float3(corner[0].xy, viewZMax);
+			float3 viewMax = float3(corner[0].xy, viewZMin);
 			
 			[unroll]
 			for(uint i = 1; i < 4; ++i)
@@ -164,7 +169,7 @@ technique TiledDeferredImageBasedLighting
 			#endif				
 			
 			float ao = gAmbientOcclusionTex.Load(int3(pixelPos.xy, 0));
-			float4 ssr = 0;//gSSRTex.Load(int3(pixelPos.xy, 0));
+			float4 ssr = gSSRTex.Load(int3(pixelPos.xy, 0));
 			float3 imageBasedSpecular = getImageBasedSpecular(worldPosition, V, specR, surfaceData, ao, ssr, probeOffset, numProbes);
 
 			float4 totalLighting = existingColor;

+ 2 - 2
Source/BansheeCore/Renderer/BsReflectionProbe.cpp

@@ -13,12 +13,12 @@ namespace bs
 {
 	ReflectionProbeBase::ReflectionProbeBase()
 		: mPosition(BsZero), mRotation(BsIdentity), mScale(1.0f, 1.0f, 1.0f), mType(ReflectionProbeType::Box), mRadius(1.0f)
-		, mExtents(1.0f, 1.0f, 1.0f), mTransitionDistance(1.0f), mIsActive(true), mBounds(Vector3::ZERO, 1.0f)
+		, mExtents(1.0f, 1.0f, 1.0f), mTransitionDistance(0.5f), mIsActive(true), mBounds(Vector3::ZERO, 1.0f)
 	{ }
 
 	ReflectionProbeBase::ReflectionProbeBase(ReflectionProbeType type, float radius, const Vector3& extents)
 		: mPosition(BsZero), mRotation(BsIdentity), mScale(1.0f, 1.0f, 1.0f), mType(type), mRadius(radius)
-		, mExtents(extents), mTransitionDistance(1.0f), mIsActive(true), mBounds(Vector3::ZERO, 1.0f)
+		, mExtents(extents), mTransitionDistance(0.5f), mIsActive(true), mBounds(Vector3::ZERO, 1.0f)
 	{ }
 
 	void ReflectionProbeBase::updateBounds()