I’m trying to implement a Render Feature that needs to jitter the camera projection. Currently, in the old renderer, I get the matrix and edit it in OnPreCull, I then reset the projection at the end of the OnRenderImage function.
What is the equivalent in URP?
Bump. I still cant figure out how to do an equivalent to jittering the projection matrix for PP effects
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
JitterProjection(renderingData.cameraData.camera);
context.SetupCameraProperties(renderingData.cameraData.camera);
var cb = CommandBufferPool.Get("TAA");
Commands(cb);
context.ExecuteCommandBuffer(cb);
CommandBufferPool.Release(cb);
}
void JitterProjection(Camera cam)
{
cam.ResetWorldToCameraMatrix(); // < ----- Unity 2017 Up
cam.ResetProjectionMatrix(); // < ----- Unity 2017 Up
cam.nonJitteredProjectionMatrix = cam.projectionMatrix;
var matrix = cam.projectionMatrix;
var num = _xJit[frameCounter] * TemporalJitterScale;
var num2 = _yJit[frameCounter] * TemporalJitterScale;
matrix.m02 += ( ( num * 2f ) - 1f ) / cam.pixelRect.width;
matrix.m12 += ( ( num2 * 2f ) - 1f ) / cam.pixelRect.height;
frameCounter++;
frameCounter %= 16;
cam.projectionMatrix = matrix;
}
The above code is how I am trying to set the projection but it is causing the entire screen to jitter, making me think its effecting more than just this pass. When I look at the frame debugger the jittering starts as soon as the first opaque, I think I need to figure out how to call context.SetupCameraProperties in a way that only applies as soon as the pass actually draws rather than the start of the frame.
@Tim-C @richardkettlewell
Sorry for the tags but I really can’t figure out how to affect the projection for a single pass at all. Do I need to create my own scriptable renderer and create my own event? Would that even work, is the part of the renderer executing these passes in c#?
Maybe I can set the renderTarget in my command buffer, and then set a jittered viewport, that could work maybe?
Turns out I made a massive oversight, TAA requires motion vectors representing the motion caused by the jitter so that it can remove the jitter effect. This is fine, but the kMotion package I use for motion vectors calculates the difference between current and last frames projection so that is does not draw, this means that the TAA effect fails to cancel the shake and causes the issues I’ve been seeing.
In order to replace jitter in precull just use RenderPipelineManager.beginCameraRendering as the precull and RenderPipelineManager.endCameraRendering as the end of frame cleanup