Skip to content

Instantly share code, notes, and snippets.

@RoyLab
Created April 14, 2017 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoyLab/3ebdaa3d33172c69b2a423e4f860c911 to your computer and use it in GitHub Desktop.
Save RoyLab/3ebdaa3d33172c69b2a423e4f860c911 to your computer and use it in GitHub Desktop.
run compute shader in unity
RenderTexture RunShader()
{
int kernelHandle = shader.FindKernel("CSMain");
RenderTexture tex = new RenderTexture(256, 256, 24);
tex.enableRandomWrite = true;
tex.Create();
shader.SetTexture(kernelHandle, "Result", tex);
shader.Dispatch(kernelHandle, 32, 32, 1);
return tex;
}
private void renderWithMesh(RenderTexture source, RenderTexture destination)
{
var tmp = RenderTexture.GetTemporary(source.width, source.height, 0, source.format);
Graphics.SetRenderTarget(destination);
GL.Clear(false, true, new Color(0, 0, 0, 1));
debug.materialDebug.SetPass(0);
GL.wireframe = true;
GL.PushMatrix();
GL.LoadOrtho();
Graphics.DrawMeshNow(mesh_, Matrix4x4.identity);
GL.PopMatrix();
//Graphics.Blit(tmp, destination);
RenderTexture.ReleaseTemporary(tmp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment