I'm having trouble understanding how to write into a RenderTexture with an integer format (e.g. [RGInt][1]). The following code leads to a completely black texture but by my understanding, it should be yellow:
**C# Script:** using UnityEngine; public class IntTextureTest : MonoBehaviour { public RenderTexture renderTexture; public ComputeShader computeShader; void Start() { renderTexture = new RenderTexture(1024, 1024, 0, RenderTextureFormat.RGInt); renderTexture.enableRandomWrite = true; renderTexture.Create(); computeShader.SetTexture(0, "Result", renderTexture); computeShader.Dispatch(0, renderTexture.width / 8, renderTexture.height / 8, 1); } }
**ComputeShader:** #pragma kernel CSMain RWTexture2D Result;
[numthreads(8, 8, 1)]
void CSMain(uint3 id : SV_DispatchThreadID) {
Result[id.xy] = int2(0x7fffffff, 0x7fffffff);
}
I have verified that the texture format is supported using [SystemInfo.SupportsRenderTextureFormat][2] and I tried the same example with a float texture, which worked fine. [1]: https://docs.unity3d.com/ScriptReference/RenderTextureFormat.RGInt.html [2]: https://docs.unity3d.com/ScriptReference/SystemInfo.SupportsRenderTextureFormat.html
**C# Script:** using UnityEngine; public class IntTextureTest : MonoBehaviour { public RenderTexture renderTexture; public ComputeShader computeShader; void Start() { renderTexture = new RenderTexture(1024, 1024, 0, RenderTextureFormat.RGInt); renderTexture.enableRandomWrite = true; renderTexture.Create(); computeShader.SetTexture(0, "Result", renderTexture); computeShader.Dispatch(0, renderTexture.width / 8, renderTexture.height / 8, 1); } }
**ComputeShader:** #pragma kernel CSMain RWTexture2D
I have verified that the texture format is supported using [SystemInfo.SupportsRenderTextureFormat][2] and I tried the same example with a float texture, which worked fine. [1]: https://docs.unity3d.com/ScriptReference/RenderTextureFormat.RGInt.html [2]: https://docs.unity3d.com/ScriptReference/SystemInfo.SupportsRenderTextureFormat.html