diff options
Diffstat (limited to 'Scripts/LinearPipeline.cs')
| -rw-r--r-- | Scripts/LinearPipeline.cs | 127 |
1 files changed, 31 insertions, 96 deletions
diff --git a/Scripts/LinearPipeline.cs b/Scripts/LinearPipeline.cs index ae1c65d..6087702 100644 --- a/Scripts/LinearPipeline.cs +++ b/Scripts/LinearPipeline.cs @@ -1,21 +1,3 @@ -/* - Udon# Linear Pipeline Controller - - This script manages a linear chain of image effects. It takes a source texture - and processes it through a sequence of materials, storing the result of each - step in a corresponding RenderTexture. - - Setup: - 1. Create an empty GameObject in your scene. - 2. Add an UdonBehaviour component to it. - 3. Create this Udon# script in your project and assign it to the UdonBehaviour. - 4. Create all the Materials and RenderTextures you need for your pipeline. - 5. In the Inspector, assign the Source Input, Materials, and Output RenderTextures. - - The size of the Effect Materials and Pipeline Outputs arrays MUST be the same. - - The order of materials and textures in the arrays determines the pipeline order. - 6. Choose your desired execution mode (Run On Start, Run Continuously). -*/ - using UdonSharp; using UnityEngine; using VRC.SDKBase; @@ -23,88 +5,41 @@ using VRC.SDKBase; [UdonBehaviourSyncMode(BehaviourSyncMode.None)] public class LinearPipeline : UdonSharpBehaviour { - [Header("Pipeline Assets")] - [Tooltip("The initial texture to start the pipeline with.")] - public Texture sourceInput; - - [Tooltip("The materials to apply in sequence. The order matters.")] - public Material[] effectMaterials; - - [Tooltip("The RenderTextures to store the output of each step. MUST be the same size as the materials array.")] - public RenderTexture[] pipelineOutputs; - - [Header("Execution Mode")] - [Tooltip("If true, the pipeline will run once when the world loads.")] - public bool runOnStart = true; - - [Tooltip("If true, the pipeline will run every frame. Use with caution, can be performance-intensive.")] - public bool runContinuously = false; - - void Start() + [Header("Pipeline Assets")] + public string pipelineGeneratedPath = "Assets/yum_food/gpu_fft/Pipeline_Generated"; + public Texture initialState; + public Material[] materials; + public RenderTexture[] renderTextures; + + private bool isValid; + + void Start() + { + ValidatePipeline(); + } + + private void ValidatePipeline() + { + isValid = materials != null && + renderTextures != null && + materials.Length > 0 && + materials.Length == renderTextures.Length; + + if (!isValid) { - if (runOnStart) - { - _RunPipeline(); - } + Debug.LogError($"[LinearPipeline] Invalid configuration on {gameObject.name}"); } + } - void Update() - { - if (runContinuously) - { - _RunPipeline(); - } - } + public void RunPipeline() + { + if (!isValid || initialState == null) return; - /// <summary> - /// This public method can be called by other Udon scripts or UI events to run the pipeline. - /// </summary> - public void _RunPipeline() - { - // --- Pre-flight Checks --- - if (sourceInput == null) - { - Debug.LogError("[LinearPipeline] Source Input is not assigned!", this); - return; - } + VRCGraphics.Blit(initialState, renderTextures[0], materials[0], -1); - if (effectMaterials == null || effectMaterials.Length == 0) - { - Debug.LogError("[LinearPipeline] No Effect Materials have been assigned!", this); - return; - } - - if (pipelineOutputs == null || pipelineOutputs.Length == 0) - { - Debug.LogError("[LinearPipeline] No Pipeline Outputs have been assigned!", this); - return; - } - - if (effectMaterials.Length != pipelineOutputs.Length) - { - Debug.LogError("[LinearPipeline] The number of materials does not match the number of output textures!", this); - return; - } - - // --- Run Pipeline --- - - // 1. First Blit: From the main source to the first texture in our chain. - VRCGraphics.Blit(sourceInput, pipelineOutputs[0], effectMaterials[0], -1); - - // 2. Loop through the rest of the chain. - for (int i = 1; i < effectMaterials.Length; i++) - { - // The source for this step is the output from the previous step. - Texture sourceForThisStep = pipelineOutputs[i - 1]; - - // The destination is the current output texture. - RenderTexture destForThisStep = pipelineOutputs[i]; - - // The material for this step. - Material materialForThisStep = effectMaterials[i]; - - VRCGraphics.Blit(sourceForThisStep, destForThisStep, materialForThisStep, -1); - } + for (int i = 1; i < materials.Length; i++) + { + VRCGraphics.Blit(renderTextures[i-1], renderTextures[i], materials[i], -1); } + } } - |
