I am trying to bake a shader results to a texture and save that to a file based on Ronja`s tutorial:
private void RenderTextureFromMaterial(string baseColorTextureName, Material m_material, int pass = -1)
{
RenderTexture m_renderTexture = RenderTexture.GetTemporary(Resolution.x, Resolution.y);
Texture2D m_texture = new Texture2D(Resolution.x, Resolution.y);
Graphics.Blit(null, m_renderTexture, m_material, pass);
//transfer image from rendertexture to texture
RenderTexture.active = m_renderTexture;
m_texture.ReadPixels(new Rect(Vector2.zero, Resolution), 0, 0);
SaveTextureToFile(baseColorTextureName, m_texture);
RenderTexture.active = null;
RenderTexture.ReleaseTemporary(m_renderTexture);
DestroyImmediate(m_texture);
DestroyImmediate(m_material);
}
This code works fine in URP:
But in HDRP I get this image:
And when I use Pass 7 (GBuffer) of the material, I get this result in HDRP:
Even when I use CommandBuffer.Blit() I can not get the results like in URP:
CommandBuffer cb = new CommandBuffer();
cb.Blit(m_texture, m_renderTexture, m_material, i);
Graphics.ExecuteCommandBuffer(cb);
The top-right version of the generated image is not the correct one too, its a zoomed version of the correct texture of the material.
how can I get the correct result in HDRP? Is there anything I am missing?