Render Texture seems to go blank when sent to Compute Shader?
I have a render texture (that's being blitted to from a webcamtexture, if thats helpful), that works fine when I blit it in turn onto the screen - but when I send it to the compute shader, write whats on it onto a different texture, and blit that new texture to the screen it's entirely black.
Relevant CPU code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Camera_Handler))]
public class Gol_Handler_Camera : MonoBehaviour
{
public ComputeShader compute;
public int _width;
public int _height;
int width_groups;
int height_groups;
RenderTexture _Input;
RenderTexture _Output;
RenderTexture _Screen;
RenderTexture _Video;
RenderTexture _Video_Save;
void OnRenderImage(RenderTexture src, RenderTexture dest) {
Graphics.Blit(_Screen, dest);
}
void Start() {
_Video = GetComponent<Camera_Handler>().Camera_Render();
_Video_Save = GetComponent<Camera_Handler>().Camera_Render();
_width = _Video.width;
_height = _Video.height;
_Screen = new RenderTexture(_width, _height, 0);
_Screen.enableRandomWrite = true;
_Screen.filterMode = FilterMode.Point;
_Screen.wrapMode = TextureWrapMode.Clamp;
_Screen.Create();
compute.SetInt(width_id, _width);
compute.SetInt(height_id, _height);
compute.SetInt(buffer_length_id, _buffer_length);
compute.SetTexture(4, input_id, _Input);
compute.SetTexture(4, output_id, _Output);
compute.SetTexture(4, screen_id, _Screen);
compute.SetTexture(4, video_id, _Video);
compute.SetTexture(4, video_save_id, _Video_Save);
compute.SetBuffer(4, buffer_id, _Buffer);
width_groups = Mathf.CeilToInt((float)_width/8f);
height_groups = Mathf.CeilToInt((float)_height/8f);
}
void Update() {
compute.SetTexture(4, video_id, _Video);
compute.Dispatch(4, width_groups, height_groups, 1);
}
}
Relevant GPU code:
#pragma kernel Initialise
uint _width;
uint _height;
RWTexture2D<float4> _Video;
RWTexture2D<float4> _Video_Save;
RWTexture2D<float4> _Input;
RWTexture2D<float4> _Output;
RWTexture2D<float4> _Screen;
StructuredBuffer<uint2> _Buffer;
uint _buffer_length;
...
#pragma kernel GOL
...
#pragma kernel Display
...
#pragma kernel Reset
...
#pragma kernel Video_Input
[numthreads(8,8,1)]
void Video_Input (uint3 id : SV_DispatchThreadID)
{
_Screen[id.xy] = _Video[id.xy];
}
If I change the OnRenderImage blit from blitting _Screen to blitting _Video it works fine, so clearly the _Video render texture contains data prior to being sent over to the shader - but once it's there it seems to behave like it's completely blank. I ideally want to be able to alter and use the data from the _Video texture once its in the compute shader, not just send it back to the screen, but I can't even seem to do that at the moment.
Any help would be really appreciated.