I just upgraded my project to HDRP and cannot extract high-precision data from my render texture that uses a shader to produce a heightmap mask.
I can replicate the issue using this simple shader:
This is the code I’m using in both URP and HDRP:
RenderTexture renderTexture = new RenderTexture(textureSize, textureSize, 0, RenderTextureFormat.RFloat)
{
enableRandomWrite = true,
filterMode = FilterMode.Point,
wrapMode = TextureWrapMode.Clamp
};
RenderTexture.active = renderTexture;
renderTexture.Create();
cameraRegion.targetTexture = renderTexture;
// Force the camera to render.
cameraRegion.Render();
// Read the RenderTexture into a Texture2D.
textureMain = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RFloat, false);
textureMain.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
// Flip the textureSource vertically to match the Unity editor view.
FlipTextureVertically(textureMain);
FlipTextureHorizontally(textureMain);
textureMain.Apply();
// Collect raw data.
textureLocalData = textureMain.GetRawTextureData<float>();
When I hover the mouse and inspect data inside the textureLocalData, I get unique values with URP, but with HDRP I have several values repeated which is a hint texture data is not working with high precision values.
I feel this might be related to some setting on HDRP itself, but I’m not sure which one as I’ve changed so many. Does anyone have a clue of what may be causing it? It’s my 3rd day trying to figure it out; I need high accuracy to generate procedural terrains masks, without it I end up with the terrace effect on terrain.
Thanks!