-
-
Save dorodo95/0fbf0d684e48f5429894b95804a35098 to your computer and use it in GitHub Desktop.
Compute Shader Issue (.cs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CCA2DCustom : MonoBehaviour | |
{ | |
//Rendering stuff | |
private RenderTexture inRT; | |
private RenderTexture outRT; | |
public ComputeShader ccaShader; | |
public Material outMat; | |
public int res = 128; | |
//IDs | |
private int startKernelID; | |
private int stepKernelID; | |
private void ConfigureTexture() | |
{ | |
inRT = new RenderTexture(res, res, 0); | |
inRT.enableRandomWrite = true; | |
inRT.filterMode = FilterMode.Point; | |
inRT.wrapMode = TextureWrapMode.Repeat; | |
inRT.format = RenderTextureFormat.ARGB32; | |
inRT.Create(); | |
outRT = new RenderTexture(res, res, 0); | |
outRT.enableRandomWrite = true; | |
outRT.filterMode = FilterMode.Point; | |
outRT.wrapMode = TextureWrapMode.Repeat; | |
outRT.format = RenderTextureFormat.ARGB32; | |
outRT.Create(); | |
} | |
private void Start() | |
{ | |
ConfigureTexture(); | |
startKernelID = ccaShader.FindKernel("StartKernel"); | |
stepKernelID = ccaShader.FindKernel("StepKernel"); | |
ccaShader.SetTexture(startKernelID, "_inTex", inRT); | |
ccaShader.SetTexture(stepKernelID, "_inTex", inRT); | |
ccaShader.SetTexture(stepKernelID, "_outTex", outRT); | |
outMat.SetTexture("_UnlitColorMap", outRT); | |
ccaShader.Dispatch(startKernelID, res/8, res/8, 1); | |
} | |
private void Update() | |
{ | |
ccaShader.Dispatch(stepKernelID, res / 8, res / 8, 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment