I’ve been trying to use RTX to get world position of each pixel in the rendered image, the code is based on a plugin sample from FluffyBunnyO.
I’ve encountered some accuracy issues because in the plugin sample the shader does not use the depth texture in order to calculate the ray origin and there for the ray origin is not accurate.
I’ve tried to pass on to the shader SceneDepthTexture by copying code from unreal engine but I’ve got a linkage error for function GetSceneTextureParameters.
I’ve checked the signatures of the function in Renderer.dll and I could not find any reason for this error.
Copy and paste the GetSceneTextureParameters function at the bottom of the file.
I’m using ViewExtension, but the basics should be the same as the tutorial above.
#include "SceneTextureParameters.h"
...
void FMyViewExtension::PrePostProcessPass_RenderThread(FRDGBuilder& GraphBuilder, const FSceneView& InView,
const FPostProcessingInputs& Inputs)
{
...
FSceneTextures SceneTextures = static_cast<const FViewInfo&>(InView).GetSceneTextures();
PassParameters->SceneTextures = GetSceneTextureParameters(GraphBuilder, SceneTextures);
...
//Add this function to the bottom of the file:
// Engine/Source/Runtime/Renderer/Private/SceneTextureParameters.cpp:37
FSceneTextureParameters GetSceneTextureParameters(FRDGBuilder& GraphBuilder, const FSceneTextures& SceneTextures)
{
const auto& SystemTextures = FRDGSystemTextures::Get(GraphBuilder);
FSceneTextureParameters Parameters;
// Should always have a depth buffer around allocated, since early z-pass is first.
Parameters.SceneDepthTexture = SceneTextures.Depth.Resolve;
Parameters.SceneStencilTexture = GraphBuilder.CreateSRV(FRDGTextureSRVDesc::CreateWithPixelFormat(Parameters.SceneDepthTexture, PF_X24_G8));
// Registers all the scene texture from the scene context. No fallback is provided to catch mistake at shader parameter validation time
// when a pass is trying to access a resource before any other pass actually created it.
Parameters.GBufferVelocityTexture = GetIfProduced(SceneTextures.Velocity);
Parameters.GBufferATexture = GetIfProduced(SceneTextures.GBufferA);
Parameters.GBufferBTexture = GetIfProduced(SceneTextures.GBufferB);
Parameters.GBufferCTexture = GetIfProduced(SceneTextures.GBufferC);
Parameters.GBufferDTexture = GetIfProduced(SceneTextures.GBufferD);
Parameters.GBufferETexture = GetIfProduced(SceneTextures.GBufferE);
Parameters.GBufferFTexture = GetIfProduced(SceneTextures.GBufferF, SystemTextures.MidGrey);
return Parameters;
}