Advertisement
remo9211

Compute Shader Learn_L2_Part1 PassData.cs

May 21st, 2024
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PassData : MonoBehaviour
  5. {
  6.  
  7. public ComputeShader shader;
  8. public int texResolution = 1024;
  9.  
  10. Renderer rend;
  11. RenderTexture outputTexture;
  12.  
  13. int circlesHandle;
  14.  
  15. public Color clearColor = new Color();
  16. public Color circleColor = new Color();
  17.  
  18. // Use this for initialization
  19. void Start()
  20. {
  21. outputTexture = new RenderTexture(texResolution, texResolution, 0);
  22. outputTexture.enableRandomWrite = true;
  23. outputTexture.Create();
  24.  
  25. rend = GetComponent<Renderer>();
  26. rend.enabled = true;
  27.  
  28. InitShader();
  29. }
  30.  
  31. private void InitShader()
  32. {
  33. circlesHandle = shader.FindKernel("Circles");
  34.  
  35. shader.SetInt( "texResolution", texResolution);
  36. shader.SetTexture( circlesHandle, "Result", outputTexture);
  37.  
  38. rend.material.SetTexture("_MainTex", outputTexture);
  39. }
  40.  
  41. private void DispatchKernel(int count)
  42. {
  43. shader.Dispatch(circlesHandle, count, 1, 1);
  44. }
  45.  
  46. void Update()
  47. {
  48. DispatchKernel(1);
  49. }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement