From da5d9c79d4469b51206257f29681a8ec4a3bb681 Mon Sep 17 00:00:00 2001 From: doJester13 Date: Sun, 7 Mar 2021 00:38:18 +0100 Subject: [PATCH] textures initialization moved to paint manager --- Assets/Scripts/PaintManager.cs | 17 ++++++++++++++++- Assets/Scripts/Paintable.cs | 8 +------- 2 files changed, 17 insertions(+), 8 deletions(-) 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(){