فهرست منبع

WIP: Getting OpenGL up to date
- SSR up and running

BearishSun 8 سال پیش
والد
کامیت
65d682b776

+ 9 - 6
Data/Raw/Engine/Includes/RayMarch.bslinc

@@ -45,8 +45,8 @@ mixin RayMarch
 				
 				// Check if ray is behind an object, but not too much behind otherwise we'll have false positives.
 				// Instead we treat "compareTolerance" as an approximate thickness of the object. Proper
-				// thickness you be calculated by rendering depth buffer for backfaces.
-				float depthDiff = rayPos.z - sampleDepth;
+				// thickness should be calculated by rendering depth buffer for backfaces.
+ 				float depthDiff = rayPos.z - sampleDepth;
 				bool hit = abs(depthDiff - compareTolerance) < compareTolerance;
 				if(hit)
 				{
@@ -174,18 +174,21 @@ mixin RayMarch
 			float2 stepScale = 1.0f / abs(ndcStep.xy + epsilon) - ndcStart.xy/(ndcStep.xy + epsilon);
 			ndcStep *= min(stepScale.x, stepScale.y);
 		
+			float deviceZStart = NDCZToDeviceZ(ndcStart.z);
+			float deviceZEnd = NDCZToDeviceZ(ndcStart.z + ndcStep.z);
+		
 			#if HI_Z
 			float3 uvStart;
 			uvStart.xy = ndcStart.xy * params.NDCToHiZUV.xy + params.NDCToHiZUV.zw;
-			uvStart.z = NDCZToDeviceZ(ndcStart.z);
+			uvStart.z = deviceZStart;
 			
 			float3 uvStep;
 			uvStep.xy = ndcStep.xy * params.NDCToHiZUV.xy;
-			uvStep.z = NDCZToDeviceZ(ndcStep.z);
+			uvStep.z = deviceZEnd - deviceZStart;
 		
 			#else
-			float3 uvStart = float3(NDCToUV(ndcStart.xy), NDCZToDeviceZ(ndcStart.z));
-			float3 uvStep = float3(ndcStep.xy * gClipToUVScaleOffset.xy, NDCZToDeviceZ(ndcStep.z));
+			float3 uvStart = float3(NDCToUV(ndcStart.xy), deviceZStart);
+			float3 uvStep = float3(ndcStep.xy * gClipToUVScaleOffset.xy, deviceZEnd - deviceZStart);
 			#endif
 		
 			float stepIncrement = 1.0f / NUM_STEPS;

+ 2 - 1
Data/Raw/Engine/Shaders/PPSSRTrace.bsl

@@ -58,6 +58,7 @@ technique PPSSRTrace
 		SamplerState gSceneColorSamp;
 		
 		Texture2D gHiZ;
+		SamplerState gHiZSamp;
 		
 		float random (float2 st) 
 		{
@@ -149,7 +150,7 @@ technique PPSSRTrace
 					
 				rayMarchParams.rayDir = R;
 
-				float4 rayHit = rayMarch(gHiZ, gDepthBufferSamp, rayMarchParams);
+				float4 rayHit = rayMarch(gHiZ, gHiZSamp, rayMarchParams);
 				if(rayHit.w < 1.0f) // Hit
 				{
 					float4 color = gSceneColor.Sample(gSceneColorSamp, rayHit.xy);

+ 14 - 0
Source/RenderBeast/BsPostProcessing.cpp

@@ -1450,6 +1450,20 @@ namespace bs { namespace ct
 
 		if(gpuParams->hasParamBlock(GPT_FRAGMENT_PROGRAM, "Input"))
 			gpuParams->setParamBlockBuffer(GPT_FRAGMENT_PROGRAM, "Input", mParamBuffer);
+
+		SAMPLER_STATE_DESC desc;
+		desc.minFilter = FO_POINT;
+		desc.magFilter = FO_POINT;
+		desc.mipFilter = FO_POINT;
+		desc.addressMode.u = TAM_CLAMP;
+		desc.addressMode.v = TAM_CLAMP;
+		desc.addressMode.w = TAM_CLAMP;
+
+		SPtr<SamplerState> hiZSamplerState = SamplerState::create(desc);
+		if (gpuParams->hasSamplerState(GPT_FRAGMENT_PROGRAM, "gHiZSamp"))
+			gpuParams->setSamplerState(GPT_FRAGMENT_PROGRAM, "gHiZSamp", hiZSamplerState);
+		else if(gpuParams->hasSamplerState(GPT_FRAGMENT_PROGRAM, "gHiZ"))
+			gpuParams->setSamplerState(GPT_FRAGMENT_PROGRAM, "gHiZ", hiZSamplerState);
 	}
 
 	void SSRTraceMat::_initVariations(ShaderVariations& variations)

+ 1 - 1
Source/RenderBeast/BsRenderCompositor.cpp

@@ -1868,7 +1868,7 @@ namespace bs { namespace ct
 
 			SPtr<RenderTexture> traceRt = RenderTexture::create(traceRtDesc);
 
-			rapi.setRenderTarget(traceRt);
+			rapi.setRenderTarget(traceRt, FBT_DEPTH | FBT_STENCIL, RT_DEPTH_STENCIL);
 			rapi.clearRenderTarget(FBT_COLOR);
 
 			SSRTraceMat* traceMat = SSRTraceMat::getVariation(settings.quality, viewProps.numSamples > 1, true);