diff --git a/Assets/Scripts/PaintManager.cs b/Assets/Scripts/PaintManager.cs index f0e4a65..ad58f32 100644 --- a/Assets/Scripts/PaintManager.cs +++ b/Assets/Scripts/PaintManager.cs @@ -19,13 +19,28 @@ public class PaintManager : Singleton{ CommandBuffer command; - void Start(){ + public override void Awake(){ + base.Awake(); + paintMaterial = new Material(texturePaint); extendMaterial = new Material(extendIslands); command = new CommandBuffer(); command.name = "CommmandBuffer - " + gameObject.name; } + public void initTextures(Paintable paintable){ + RenderTexture mask = paintable.getMask(); + RenderTexture extend = paintable.getExtend(); + RenderTexture support = paintable.getSupport(); + + command.SetRenderTarget(mask); + command.SetRenderTarget(extend); + command.SetRenderTarget(support); + + Graphics.ExecuteCommandBuffer(command); + command.Clear(); + } + public void paint(Paintable paintable, Vector3 pos, float radius = 1f, float hardness = .5f, float strength = .5f, Color? color = null){ RenderTexture mask = paintable.getMask(); diff --git a/Assets/Scripts/Paintable.cs b/Assets/Scripts/Paintable.cs index 7154fb5..5a9fe0f 100644 --- a/Assets/Scripts/Paintable.cs +++ b/Assets/Scripts/Paintable.cs @@ -1,5 +1,4 @@ using UnityEngine; -using UnityEngine.Rendering; public class Paintable : MonoBehaviour { const int TEXTURE_SIZE = 1024; @@ -29,12 +28,7 @@ public class Paintable : MonoBehaviour { rend = GetComponent(); rend.material.SetTexture(maskTextureID, extendIslandsRenderTexture); - CommandBuffer command = new CommandBuffer(); - command.name = "CommandBuffer - " + gameObject.name; - command.SetRenderTarget(maskRenderTexture); - command.SetRenderTarget(extendIslandsRenderTexture); - command.SetRenderTarget(supportTexture); - Graphics.ExecuteCommandBuffer(command); + PaintManager.instance.initTextures(this); } void OnDisable(){