Quantcast
Channel: Questions in topic: "compute shader"
Viewing all articles
Browse latest Browse all 287

Compute Shader Outputting Black

$
0
0
Hey All. Just trying to get my head around compute shaders, and just wanted to set an input texture as the output texture. Whenever I do this, I simply get a black output from the processed texture (code below) that is being rendered to a RawImage UI Element. Am I indexing the input image wrong maybe? Any help would be much appreciated. Compute shader: // Each #kernel tells which function to compile; you can have many kernels #pragma kernel CSMain // Input Texture Texture2D imageInput; // Create a RenderTexture with enableRandomWrite flag and set it // with cs.SetTexture RWTexture2D Result; [numthreads(1,1,1)] void CSMain (uint3 id : SV_DispatchThreadID) { // TODO: insert actual code here! Result[id.xy] = imageInput[id.xy]; } C# Script: public class TestCamera : MonoBehaviour { public RenderTexture testTexture; public RenderTexture processedTexture; public RawImage testUI; public ComputeShader computeShader; public GameObject boat; // Start is called before the first frame update void Start() { testTexture = GetComponent().targetTexture; // Set Up Render Texture processedTexture = new RenderTexture(256, 256, 24); processedTexture.enableRandomWrite = true; processedTexture.Create(); // Dispatch Compute Shader int shaderKernal = computeShader.FindKernel("CSMain"); computeShader.SetTexture(shaderKernal, "Result", processedTexture); computeShader.SetTexture(shaderKernal, "imageInput", testTexture); computeShader.Dispatch(shaderKernal, testTexture.width, testTexture.height, 1); } // Update is called once per frame void Update() { testUI.texture = processedTexture; transform.position = new Vector3(boat.transform.position.x, transform.position.y, boat.transform.position.z); } }

Viewing all articles
Browse latest Browse all 287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>