Hello!
I continue with my crusade learning graphics in general and RGD, this time I am trying to implement a custom screen pass to do anamorphic bokehs in my DOF, (yes the diaphragm DOF is cool in the cinematic cameras, but I want anamorphic stuff).
For now all good, I am experimenting first with a single pass and I had very good results, I am able to deform the bokeh in X and Y directions:
Now the problem I am having is the performance and I am wondering what am I doing sooo bad, here is a screen:
As you can see from the ProfileGPU my pass is talking waaaay too much ms to be compute. If I disable all the logic in my compute shader, it is still taking 0.11 ms at that resolution, sampling the texture is way ultra heavy, why?, I compared the cinematic DOF and it takes 0.22 ms.
So obviously my initial idea here, is use half resolutions for my textures samples, but I am not yet sure what is the methodology, I have been reading the source from the diaphragm DOF, so I will try to implement a setup pass first. Anyway that does not explain why is taking 0.11 ms just by calling the empty compute shader. here is the code I am using to setup my pass:
FRDGTextureRef GatherDOF::AddGatherDOFPasses(
FRDGBuilder& GraphBuilder,
const FSceneTextureParameters& SceneTextures,
const FViewInfo& View,
const FRDGTextureRef& SceneColor,
const FRDGTextureRef& ViewFamilyTexture,
const FRDGTextureRef& SeparateTranslucency,
const FRDGTextureRef& SeparateModulation,
const FRDGTextureRef& CustomDepth)
{
FRDGTextureRef NewSceneColor;
{
{
FRDGTextureDesc Desc = SceneColor->Desc;
Desc.NumSamples = 1;
Desc.TargetableFlags |= TexCreate_UAV;
NewSceneColor = GraphBuilder.CreateTexture(Desc, TEXT("GatherDOFRecombine"));
}
// Setup the shader parameter used in all shaders.
FGatherDOFCommonShaderParameters CommonParameters;
CommonParameters.ViewUniformBuffer = View.ViewUniformBuffer;
FIntRect PassViewRect = View.ViewRect;
FGatherDOF::FParameters* PassParameters = GraphBuilder.AllocParameters<FGatherDOF::FParameters>();
PassParameters->CommonParameters = CommonParameters;
PassParameters->Radius = GGatherDOFParameters.Radius;
PassParameters->AnamorphicX = GGatherDOFParameters.AnamorphicX;
PassParameters->AnamorphicY = GGatherDOFParameters.AnamorphicY;
PassParameters->EdgeCount = GGatherDOFParameters.EdgeCount;
PassParameters->Rotation = GGatherDOFParameters.Rotation;
PassParameters->FocalDistance = GGatherDOFParameters.FocalDistance;
PassParameters->FocalRegion = GGatherDOFParameters.FocalRegion;
PassParameters->FocalLength = GGatherDOFParameters.FocalLength;
PassParameters->Aperture = GGatherDOFParameters.Apeture;
PassParameters->ViewportSize = FVector4(PassViewRect.Width(), PassViewRect.Height(), 1.0f / PassViewRect.Width(), 1.0f / PassViewRect.Height());
PassParameters->SceneColorTexture = SceneColor;
PassParameters->SceneDepthTexture = SceneTextures.SceneDepthBuffer;
PassParameters->SceneColorOutput = GraphBuilder.CreateUAV(NewSceneColor);
TShaderMapRef<FGatherDOF> ComputeShader(View.ShaderMap);
FComputeShaderUtils::AddPass(
GraphBuilder,
RDG_EVENT_NAME("Gather DOF"),
ComputeShader,
PassParameters,
FComputeShaderUtils::GetGroupCount(View.ViewRect.Size(), kDefaultGroupSize));
}
return NewSceneColor;
}
Even tho’ I have been learning directX and the UE’s API for a while now, I have a ton of topics that I still don’t understand, here I am assuming my texture UAV is generated only once, since the diaphragm function is doing the same. I still don’t understand properly what is the tile pass, so if is there a ultra instinct powerful guy hidden in the shadows, who can explain a little bit about the passes used there, I will be extremely grateful with such person.
For those who are interested I am using this post as reference: http://www.adriancourreges.com/blog/…-post-effects/ might worth to mention that everything in there is old and deprecated since is not RGD.
Also I did a push request to epic games, where I did a small change to the post process files to be able to register custom global shaders from plugins as post process. So no one will need to modify the engine source if need to create a post process only with code. Let’s see if they accept it, here is the push request for those interested: https://github.com/EpicGames/UnrealEngine/pull/7168
Again if you feel in terrible need to speak about compute shaders, do not hesitate
Cheers!