#In HDRP a rendered texture has no alpha for some users

1 messages · Page 1 of 1 (latest)

queen heart
#

I have an HDRP project where I create texture icons for assets. I got it working fine on my computer, but the same project for another has the textures missing the alpha and I can't figure out why.

Render texture creation:

 var rtd = new RenderTextureDescriptor(size, size) {
                depthBufferBits = 24,
                msaaSamples = 4,
                useMipMap = false,
                sRGB = true,
                graphicsFormat = SystemInfo.GetGraphicsFormat(DefaultFormat.LDR)
};
_renderTexture = new RenderTexture(rtd);

Rendering

 Camera.SubmitRenderRequest(new RenderPipeline.StandardRequest() { destination = _renderTexture });

RenderTexture temporary = RenderTexture.GetTemporary(size, size, 0, GraphicsFormat.R8G8B8A8_UNorm);
RenderTexture active = RenderTexture.active;
Graphics.Blit(_renderTexture, temporary, PreviewEditorUtility.GUITextureBlit2SRGBMaterial);

RenderTexture.active = temporary;
Texture2D texture2D = new Texture2D(size, size, TextureFormat.RGBA32, false, false);
            texture2D.ReadPixels(new Rect(0.0f, 0.0f, size, size), 0, 0);
            texture2D.Apply();
            
RenderTexture.active = active;
            
RenderTexture.ReleaseTemporary(temporary);
glass crag
#

SystemInfo.GetGraphicsFormat(DefaultFormat.LDR) is probably returning a format without alpha in certain cases. I suggest htat you just force the format to something that has alpha like GraphicsFormat.R8G8B8A8_SRGB