Created
February 4, 2024 11:38
-
-
Save NathoSteveo/3a0741e07e913cddb35c6b509d546006 to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
using UnityEngine.Events; | |
[ExecuteInEditMode] | |
public class SDFTextureGenerator : MonoBehaviour | |
{ | |
[Header("[ TEXTURE TO SDF ]")] | |
[SerializeField] Texture _SOURCE_TEXTURE = null; | |
[SerializeField] Texture _RESULT_TEXTURE = null; | |
float _sourceValueThreshold = 0.5f; | |
SDFTexture.DownSampling _downSampling = SDFTexture.DownSampling.None; | |
SDFTexture.Precision _precision = SDFTexture.Precision._32; | |
bool _addBorders = false; | |
bool _showSource = false; | |
UnityEvent<RenderTexture> _sdfTextureEvent = new UnityEvent<RenderTexture>(); | |
SDFTexture _generator; | |
void OnEnable() | |
{ | |
_generator?.Release(); | |
_generator = new SDFTexture(); | |
} | |
void OnDisable() | |
{ | |
_generator?.Release(); | |
} | |
void Reset() | |
{ | |
_generator?.Release(); | |
} | |
void Update() | |
{ | |
_generator.Update(_SOURCE_TEXTURE, _sourceValueThreshold, _downSampling, _precision, _addBorders, _showSource); | |
_sdfTextureEvent.Invoke(_generator.sdfTexture); | |
Graphics.Blit(_generator.sdfTexture, (RenderTexture)_RESULT_TEXTURE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment