Hi, (Unity 2021.2.16f1 & HDRP 12.1.6)
I am trying to convert the following built-in code to HDRP.
The idea is to display the camera render on a mesh to distort the render.
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
_material.SetTexture("_MainTex", source);
_material.SetPass(0);
RenderTexture previousTex = RenderTexture.active;
RenderTexture.active = _RT;
GL.PushMatrix();
GL.LoadPixelMatrix(0.0f, 1.0f, 0.0f, 1.0f);
Graphics.DrawMeshNow(_gridMesh, _gridMeshGO.transform.localToWorldMatrix);
GL.PopMatrix();
RenderTexture.active = previousTex;
}
So far I have:
- Created a Custom Pass
- Created a Custom Renderers Pass shader
Then I have two issues:
1/ In the Execute method of the Custom Pass I have:
_material.SetTexture("_ColorMap", ctx.cameraColorBuffer);
Which makes me need to modify the template shader so that the _ColorMap is a 2DArray:
_ColorMap("ColorMap", 2DArray) = "white" {}
TEXTURE2D(_ColorMap);
I only get a white texture, as if the colormap is not assigned.
I tried to use TEXTURE2D_X instead which seems to be the correct function to be able to sample 2DArrays,
but it is not defined in Custom Renderers Pass shaders, only in Full screen shader (which I don’t think is what I want to use).
I tried to include CustomPassCommon.hlsl but then I get errors like : redefinition of ‘_CustomPassInjectionPoint’
How can I fix this ?
2/ Currently I am using
ctx.cmd.DrawMesh(_script._gridMesh, _script._gridMeshGO.transform.localToWorldMatrix, _Material);
to draw my mesh, but of course it is rendered using the current perspective camera.
In the built-in pipeline I used GL.LoadPixelMatrix(0.0f, 1.0f, 0.0f, 1.0f);
To get around this I tried created an ortho camera and use CustomPassUtils.RenderFromCamera
The rendering works correctly but now I see that the effect of an ortho projection is not the same as the LoadPixelMatrix
How can I replicate this in HDRP ?
Thanks in advance!