Example #1
0
    public override void NodeGUI()
    {
        GUILayout.BeginVertical();

        // Signal input knob and value label
        GUILayout.BeginHorizontal();
        signalKnob.DisplayLayout();
        GUILayout.Label(string.Format("value: {0:0.0000}", signalKnob.GetValue <float>()));
        GUILayout.EndHorizontal();

        GUILayout.FlexibleSpace();

        GUILayout.BeginHorizontal();

        //Top/mid/bottom labels
        GUILayout.FlexibleSpace();
        GUILayout.BeginVertical();
        GUILayout.Label(string.Format("{0:0.00}", windowMaxY));
        GUILayout.FlexibleSpace();
        GUILayout.Label(string.Format("{0:0.00}", (windowMaxY + windowMinY) / 2));
        GUILayout.FlexibleSpace();
        GUILayout.Label(string.Format("{0:0.00}", windowMinY));
        GUILayout.EndVertical();

        GUILayout.Box(graphTexture, GUILayout.MaxWidth(256), GUILayout.MaxHeight(256));
        GUILayout.EndHorizontal();
        GUILayout.Space(4);
        GUILayout.EndVertical();
        outputTexKnob.SetPosition(DefaultSize.x - 20);
        if (GUI.changed)
        {
            NodeEditor.curNodeCanvas.OnNodeChange(this);
        }
    }
Example #2
0
    public override void NodeGUI()
    {
        GUILayout.BeginVertical();

        emissionRateKnob.DisplayLayout();
        if (!emissionRateKnob.connected())
        {
            emissionRate = RTEditorGUI.Slider(emissionRate, 0, 1000);
        }
        else
        {
            emissionRate = emissionRateKnob.GetValue <float>();
        }

        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Box(outputTex, GUILayout.MaxWidth(64), GUILayout.MaxHeight(64));
        GUILayout.EndHorizontal();
        GUILayout.Space(4);

        GUILayout.EndVertical();

        outputTexKnob.SetPosition(180);

        if (GUI.changed)
        {
            NodeEditor.curNodeCanvas.OnNodeChange(this);
        }
    }
Example #3
0
 public override void NodeGUI()
 {
     inputTexKnob.SetPosition(20);
     GUILayout.BeginVertical();
     controlSignalKnob.DisplayLayout();
     if (!controlSignalKnob.connected())
     {
         controlSignal = RTEditorGUI.Slider(controlSignal, 0, 1);
     }
     else
     {
         controlSignal = controlSignalKnob.GetValue <float>();
     }
     GUILayout.FlexibleSpace();
     GUILayout.BeginHorizontal();
     GUILayout.FlexibleSpace();
     GUILayout.Box(outputTex, GUILayout.MaxWidth(64), GUILayout.MaxHeight(64));
     GUILayout.EndHorizontal();
     GUILayout.Space(4);
     GUILayout.EndVertical();
     outputTexKnob.SetPosition(180);
     if (GUI.changed)
     {
         NodeEditor.curNodeCanvas.OnNodeChange(this);
     }
 }
Example #4
0
    public override bool Calculate()
    {
        signalValue = inputSignalKnob.GetValue <float>();
        switch (triggerMode.SelectedOption())
        {
        case "leadingEdge":
            output = (signalValue > threshold) && !wasOverThreshold;
            break;

        case "trailingEdge":
            output = (signalValue < threshold) && wasOverThreshold;
            break;

        case "high":
            output = signalValue > threshold;
            break;

        case "low":
            output = signalValue < threshold;
            break;

        default:
            output = false;
            break;
        }
        wasOverThreshold = signalValue > threshold;
        outputEventKnob.SetValue(output);
        return(true);
    }
Example #5
0
    public override bool Calculate()
    {
        var newPeriod = periodInputKnob.connected() ? periodInputKnob.GetValue <float>() : period;
        var newPhase  = phaseInputKnob.connected() ? phaseInputKnob.GetValue <float>() : phase;

        if (newPeriod != period ||
            newPhase != phase)
        {
            if (newPeriod != period)
            {
                //Find a phase such that the oscillator won't instantaneously jump in amplitude
                //If phase and freq change on the same Calculate()... we pick freq.
                float t = Time.time;
                newPhase = 2 * Mathf.PI * t - (newPeriod / period) * (2 * Mathf.PI * t - phase);
            }
            period = newPeriod;
            phase  = newPhase;
        }
        synthShader.SetInt("width", outputSize.x);
        synthShader.SetInt("height", outputSize.y);
        synthShader.SetFloat("period", period);
        synthShader.SetFloat("phase", phase);
        synthShader.SetFloat("time", Time.time);
        synthShader.SetTexture(kernelId, "OutputTex", outputTex);
        var threadGroupX = Mathf.CeilToInt(outputSize.x / 16.0f);
        var threadGroupY = Mathf.CeilToInt(outputSize.y / 16.0f);

        synthShader.Dispatch(kernelId, threadGroupX, threadGroupY, 1);

        // Assign output channels
        textureOutputKnob.SetValue(outputTex);

        return(true);
    }
Example #6
0
    public override bool Calculate()
    {
        Texture tex = inputTexKnob.GetValue <Texture>();

        if (!inputTexKnob.connected() || tex == null)
        { // Reset outputs if no texture is available
            outputSize = Vector2Int.zero;
            if (outputTex != null)
            {
                outputTex.Release();
                spoutController.RefreshSender();
            }
            return(true);
        }

        var inputSize = new Vector2Int(tex.width, tex.height);

        if (inputSize != outputSize)
        {
            outputSize = inputSize;
            InitializeRenderTexture();
        }

        if (inputTexKnob.connected() && tex != null)
        {
            Graphics.Blit(tex, outputTex);
        }
        return(true);
    }
Example #7
0
    public override bool Calculate()
    {
        tinselOne.phase     = Time.time / 10;
        tinselOne.amplitude = tinselAmplitude;
        tinselOne.thickness = tinselThickness;
        tinselOne.offset    = tinselOffset;
        tinselOne.period    = tinselOne.amplitude * 1.25f;

        turbScale = turbScaleKnob.connected() ? turbScaleKnob.GetValue <float>() : turbScale;
        if (turbScale != oldScale)
        {
            oldScale = turbScale;
            GenerateNoiseTex();
            patternShader.SetTexture(patternKernel, "noiseTex", noiseTex);
        }
        turbFactor = turbIntensityKnob.connected() ? turbIntensityKnob.GetValue <float>() : turbFactor;

        patternShader.SetInt("width", outputTex.width);
        patternShader.SetInt("height", outputTex.height);
        patternShader.SetTexture(patternKernel, "OutputTex", outputTex);
        uint tx, ty, tz;

        //patternShader.GetKernelThreadGroupSizes(patternKernel, out tx, out ty, out tz);
        //patternShader.Dispatch(patternKernel, Mathf.CeilToInt(outputTex.width / tx), Mathf.CeilToInt(outputTex.height / ty), 1);
        DrawTree();
        textureOutputKnob.SetValue(treeTex);
        return(true);
    }
Example #8
0
    public override bool Calculate()
    {
        patternShader.SetInts("outputSize", outputSize.x, outputSize.y);
        patternShader.SetInt("maxIterations", maxIterations);
        patternShader.SetInt("order", order);
        patternShader.SetFloat("bias", bias);
        patternShader.SetFloat("zoom", zoom);
        patternShader.SetFloat("radius", radius);
        if (offsetKnob.connected())
        {
            offset = offsetKnob.GetValue <Vector2>();
        }
        else
        {
            offset = new Vector2(1, 1);
        }
        patternShader.SetFloats("offset", offset.x, offset.y);
        patternShader.SetVector("convergeColor", Color.red);
        patternShader.SetVector("divergeColor", Color.black);
        patternShader.SetTexture(patternKernel, "outputTex", outputTex);
        uint tx, ty, tz;

        patternShader.GetKernelThreadGroupSizes(patternKernel, out tx, out ty, out tz);
        var threadGroupX = Mathf.CeilToInt(((float)outputSize.x) / tx);
        var threadGroupY = Mathf.CeilToInt(((float)outputSize.y) / ty);

        patternShader.Dispatch(patternKernel, threadGroupX, threadGroupY, 1);
        outputTexKnob.SetValue(outputTex);
        return(true);
    }
Example #9
0
 public override bool Calculate()
 {
     if (timeMultiplierKnob.connected())
     {
         timeMultiplier = timeMultiplierKnob.GetValue <float>();
     }
     if (applyForceKnob.GetValue <bool>())
     {
         ApplyVelocity();
     }
     if (running && Time.time - lastStep > 1 / 60f)
     {
         if (continuousDye)
         {
             AddDye();
         }
         if (clicked)
         {
             timestep = Time.deltaTime;
         }
         else
         {
             timestep = Time.time - lastStep;
         }
         lastStep = Time.time;
         SimulateFluid();
     }
     if (clicked)
     {
         clicked = false;
     }
     textureOutputKnob.SetValue <Texture>(dyeField);
     return(true);
 }
        public override bool Calculate()
        {
            _output = null;

            if (!inputKnob.connected())
            {
                return(true);
            }
            var input = inputKnob.GetValue <Texture>();

            if (input && !string.IsNullOrEmpty(savePath))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(savePath));
                Debug.Log("Saving to '" + savePath + "'!");
                Texture2D outputTexture = input as Texture2D;

                if (outputTexture == null && input is RenderTexture)
                {
                }

                if (outputTexture == null)
                {
                    Debug.LogWarning($"Failed to generate output for {savePath}, unrecognised texture type. Should be one of: Texture2D or RenderTexture.");
                    return(false);
                }

                File.WriteAllBytes(savePath, outputTexture.EncodeToPNG());

#if UNITY_EDITOR
                UnityEditor.AssetDatabase.Refresh();
#endif
                _output = outputTexture;
            }
            return(true);
        }
Example #11
0
        public override bool Calculate()
        {
            var input = inputKnob.GetValue <Texture>();

            if (!input || !outputKnob.connected())
            {
                return(true);
            }
            var output = CreateOutputTexture(input);

            if (_material == null)
            {
                _material = new Material(GetShader());
            }
            ConfigureMaterial(_material);
            Graphics.Blit(input, output, _material);

            var prevActive = RenderTexture.active;

            RenderTexture.active = output;
            var outputTexture = new Texture2D(output.width, output.height);

            outputTexture.ReadPixels(new Rect(0, 0, output.width, output.height), 0, 0);
            outputTexture.Apply();
            RenderTexture.active = prevActive;

            outputKnob.SetValue <Texture>(outputTexture);
            return(true);
        }
Example #12
0
        public override bool Calculate()
        {
            if (input1Knob.connected())
            {
                Input1Val = input1Knob.GetValue <float> ();
            }
            if (input2Knob.connected())
            {
                Input2Val = input2Knob.GetValue <float> ();
            }

            switch (type)
            {
            case CalcType.Add:
                outputKnob.SetValue <float> (Input1Val + Input2Val);
                break;

            case CalcType.Substract:
                outputKnob.SetValue <float> (Input1Val - Input2Val);
                break;

            case CalcType.Multiply:
                outputKnob.SetValue <float> (Input1Val * Input2Val);
                break;

            case CalcType.Divide:
                outputKnob.SetValue <float> (Input1Val / Input2Val);
                break;
            }

            return(true);
        }
Example #13
0
    public override bool Calculate()
    {
        var dummySpectrum = new float[32];

        for (int i = 0; i < 32; i++)
        {
            dummySpectrum[i] = 0.5f;
        }

        spectrumData = spectrumDataKnob.GetValue <float[]>();
        if (spectrumData != null)
        {
            patternShader.SetInt("width", outputSize.x);
            patternShader.SetInt("height", outputSize.y);
            patternShader.SetInt("spectrumSize", spectrumData.Length);
            patternShader.SetFloats("spectrumData", spectrumData);
            patternShader.SetTexture(patternKernel, "outputTex", outputTex);
            uint tx, ty, tz;
            patternShader.GetKernelThreadGroupSizes(patternKernel, out tx, out ty, out tz);
            var threadGroupX = Mathf.CeilToInt(((float)outputSize.x) / tx);
            var threadGroupY = Mathf.CeilToInt(((float)outputSize.y) / ty);
            patternShader.Dispatch(patternKernel, threadGroupX, threadGroupY, 1);
            outputTexKnob.SetValue(outputTex);
        }
        return(true);
    }
Example #14
0
    public override bool Calculate()
    {
        a  = aKnob.connected() ? aKnob.GetValue <float>(): a;
        b  = bKnob.connected() ? bKnob.GetValue <float>() : b;
        m1 = m1Knob.connected() ? m1Knob.GetValue <float>() : m1;
        m2 = m2Knob.connected() ? m2Knob.GetValue <float>() : m2;
        n1 = n1Knob.connected() ? n1Knob.GetValue <float>() : n1;
        n2 = n2Knob.connected() ? n2Knob.GetValue <float>() : n2;
        n3 = n3Knob.connected() ? n3Knob.GetValue <float>() : n3;


        patternShader.SetFloat("a", a);
        patternShader.SetFloat("b", b);
        patternShader.SetFloat("m1", m1);
        patternShader.SetFloat("m2", m2);
        patternShader.SetFloat("n1", n1);
        patternShader.SetFloat("n2", n2);
        patternShader.SetFloat("n3", n3);

        patternShader.SetInt("width", outputSize.x);
        patternShader.SetInt("height", outputSize.y);

        patternShader.SetTexture(patternKernel, "outputTex", outputTex);
        uint tx, ty, tz;

        patternShader.GetKernelThreadGroupSizes(patternKernel, out tx, out ty, out tz);
        var threadGroupX = Mathf.CeilToInt(((float)outputSize.x) / tx);
        var threadGroupY = Mathf.CeilToInt(((float)outputSize.y) / ty);

        patternShader.Dispatch(patternKernel, threadGroupX, threadGroupY, 1);
        outputTexKnob.SetValue(outputTex);
        return(true);
    }
Example #15
0
    public override void NodeGUI()
    {
        gameStateKnob.SetPosition(20);

        GUILayout.BeginVertical();
        if (gameStateKnob.connected())
        {
            if (GUILayout.Button("Apply state"))
            {
                Graphics.Blit(gameStateKnob.GetValue <Texture>(), inputState);
            }
        }
        string label = running ? "Stop" : "Run";

        if (GUILayout.Button(label))
        {
            running = !running;
        }

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Box(outputState, GUILayout.MaxWidth(64), GUILayout.MaxHeight(64));
        GUILayout.EndHorizontal();

        GUILayout.Space(4);
        GUILayout.EndVertical();

        outputTexKnob.SetPosition(DefaultSize.x - 20);
        if (GUI.changed)
        {
            NodeEditor.curNodeCanvas.OnNodeChange(this);
        }
    }
Example #16
0
    public override bool Calculate()
    {
        VoxelBlock <T> block = input.GetValue <VoxelBlock <T> >();

        if (block == null || block.Layers == null)
        {
            return(false);
        }

        CalculationSetup(block);
        bool success = true;

        for (int i = 0; i < block.Layers.Count(); i++)
        {
            if (!CalculateLayer(block.Layers[i], i - block.Overlap))
            {
                success = false;
                break;
            }
        }
        CalculationTeardown();

        output.SetValue(block);

        return(success);
    }
Example #17
0
    public override bool Calculate()
    {
        Texture tex = textureInputKnob.GetValue <Texture>();

        if (!textureInputKnob.connected() || tex == null)
        { // Reset outputs if no texture is available
            textureOutputKnob.ResetValue();
            outputSize = Vector2Int.zero;
            return(true);
        }

        if (outputSize.x == 0 || outputSize.y == 0 || reflections != previousReflections)
        {
            outputSize          = new Vector2Int(tex.width, tex.height * reflections);
            previousReflections = reflections;
            InitializeRenderTexture();
            Debug.Log("tex.height");
            Debug.Log(tex.height);
        }

        //Execute compute shader
        KaleidoscopeShader.SetInt("width", tex.width);
        KaleidoscopeShader.SetInt("height", tex.height);
        KaleidoscopeShader.SetTexture(kernelId, "InputTex", tex);
        KaleidoscopeShader.SetTexture(kernelId, "OutputTex", outputTex);
        var threadGroupX = Mathf.CeilToInt(outputTex.width / 16.0f);
        var threadGroupY = Mathf.CeilToInt(outputTex.height / 16.0f);

        KaleidoscopeShader.Dispatch(kernelId, threadGroupX, threadGroupY, 1);

        // Assign output channels
        textureOutputKnob.SetValue(outputTex);

        return(true);
    }
Example #18
0
        public override bool Calculate()
        {
            float value = 0;
            float t     = Time.time;

            amplitude = amplInputKnob.connected()  ? amplInputKnob.GetValue <float>()   : amplitude;
            period    = periodInputKnob.connected()   ? periodInputKnob.GetValue <float>() : period;
            phase     = phaseInputKnob.connected()    ? phaseInputKnob.GetValue <float>()  : phase;

            offset = 0;
            if (paramStyle.SelectedOption() == "min max")
            {
                amplitude = (max - min) / 2;
                offset    = min + amplitude;
            }

            var newParams = (period, amplitude, phase);
            var oldParams = (lastPeriod, lastAmplitude, lastPhase);

            if (newParams != oldParams)
            {
                if (period != lastPeriod)
                {
                    phase = (t - period / lastPeriod * (t - lastPhase)) % period;
                }
            }

            value = signalGenerators[signalType.SelectedOption()](t, period, amplitude, phase, 0);
            outputKnob.SetValue(value + offset);
            lastPeriod    = period;
            lastPhase     = phase;
            lastAmplitude = amplitude;
            return(true);
        }
Example #19
0
        public override bool Calculate()
        {
            Channel RChannel = channelRKnob.connected() ? channelRKnob.GetValue <Channel>() : null;
            Channel GChannel = channelGKnob.connected() ? channelGKnob.GetValue <Channel>() : null;
            Channel BChannel = channelBKnob.connected() ? channelBKnob.GetValue <Channel>() : null;
            Channel AChannel = channelAKnob.connected() ? channelAKnob.GetValue <Channel>() : null;

            if (RChannel == null && GChannel == null && BChannel == null)
            {
                bundledKnob.ResetValue();
                return(true);
            }

            int width  = Mathf.Max(new int[] { RChannel != null ? RChannel.width : 0, GChannel != null ? GChannel.width : 0, BChannel != null ? BChannel.width : 0, AChannel != null ? AChannel.width : 0 });
            int height = Mathf.Max(new int[] { RChannel != null ? RChannel.height : 0, GChannel != null ? GChannel.height : 0, BChannel != null ? BChannel.height : 0, AChannel != null ? AChannel.height : 0 });

            Texture2D bundled = new Texture2D(width, height, AChannel != null ? TextureFormat.RGBA32 : TextureFormat.RGB24, false);

            bundled.name = "Bundled Tex";

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    bundled.SetPixel(x, y, new Color(RChannel != null ? RChannel.GetValue(x, y, width, height) : 0,
                                                     GChannel != null ? GChannel.GetValue(x, y, width, height) : 0,
                                                     BChannel != null ? BChannel.GetValue(x, y, width, height) : 0,
                                                     AChannel != null ? AChannel.GetValue(x, y, width, height) : 1));
                }
            }

            bundled.Apply();
            bundledKnob.SetValue(bundled);
            return(true);
        }
Example #20
0
    public override bool Calculate()
    {
        Texture tex = textureInputKnob.GetValue <Texture>();

        if (!textureInputKnob.connected() || tex == null)
        { // Reset outputs if no texture is available
            textureOutputKnob.ResetValue();
            outputSize = Vector2Int.zero;
            return(true);
        }

        var inputSize = new Vector2Int(tex.width, tex.height);

        if (inputSize != outputSize)
        {
            outputSize = inputSize;
            InitializeRenderTexture();
        }

        //Execute compute shader
        PolarizeShader.SetInt("width", tex.width);
        PolarizeShader.SetInt("height", tex.height);
        PolarizeShader.SetTexture(kernelId, "OutputTex", outputTex);
        PolarizeShader.SetTexture(kernelId, "InputTex", tex);
        var threadGroupX = Mathf.CeilToInt(tex.width / 16.0f);
        var threadGroupY = Mathf.CeilToInt(tex.height / 16.0f);

        PolarizeShader.Dispatch(kernelId, threadGroupX, threadGroupY, 1);

        // Assign output channels
        textureOutputKnob.SetValue(outputTex);

        return(true);
    }
Example #21
0
 public override bool Calculate()
 {
     if (Time.time - lastCalced > (1 / targetFPS))
     {
         Texture tex = inputTexKnob.GetValue <Texture>();
         if (!inputTexKnob.connected() || tex == null)
         { // Reset outputs if no texture is available
             if (buffer != null)
             {
                 buffer.Release();
             }
             outputSize = Vector2Int.zero;
             return(true);
         }
         var inputSize = new Vector2Int(tex.width, tex.height);
         if (inputSize != outputSize)
         {
             outputSize = inputSize;
             InitializeRenderTexture();
         }
         Graphics.Blit(tex, buffer);
         Texture2D tex2d = buffer.ToTexture2D();
         FillFromTexture(tex2d);
         SendDMX();
         Destroy(tex2d);
         lastCalced = Time.time;
     }
     return(true);
 }
Example #22
0
    public override void NodeGUI()
    {
        inputTexKnob.SetPosition(20);
        GUILayout.BeginVertical();
        startHueKnob.DisplayLayout();
        if (!startHueKnob.connected())
        {
            startHue = RTEditorGUI.Slider(startHue, 0, 1);
        }
        else
        {
            startHue = startHueKnob.GetValue <float>();
        }
        endHueKnob.DisplayLayout();
        if (!endHueKnob.connected())
        {
            endHue = RTEditorGUI.Slider(endHue, 0, 1);
        }
        else
        {
            endHue = endHueKnob.GetValue <float>();
        }
        offsetKnob.DisplayLayout();
        if (!offsetKnob.connected())
        {
            offset = RTEditorGUI.Slider(offset, 0, 1);
        }
        else
        {
            offset = offsetKnob.GetValue <float>();
        }
        center = RTEditorGUI.Toggle(center, new GUIContent("Center", "Gradient from center"));

        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Box(outputTex, GUILayout.MaxWidth(64), GUILayout.MaxHeight(64));
        GUILayout.EndHorizontal();
        GUILayout.Space(4);
        GUILayout.EndVertical();
        outputTexKnob.SetPosition(180);
        if (GUI.changed)
        {
            NodeEditor.curNodeCanvas.OnNodeChange(this);
        }
    }
Example #23
0
 protected override bool CalculateVoxel(Voxel voxel, int x, int y, int z)
 {
     if (thresholdConnection.connected())
     {
         threshold = thresholdConnection.GetValue <float>();
     }
     voxel.Data = voxel.Data > threshold ? 1.0f : 0.0f;
     return(true);
 }
Example #24
0
        public override bool Calculate()
        {
            outputTop.SetValue <float> (inputTop.GetValue <float> ());
            outputBottom.SetValue <float> (inputBottom.GetValue <float> ());
            outputRight.SetValue <float> (inputRight.GetValue <float> ());
            outputLeft.SetValue <float> (inputLeft.GetValue <float> ());

            return(true);
        }
Example #25
0
 private void AddDye()
 {
     fluidSimShader.SetFloat("dyeMultiplier", dyeInputLevel);
     Graphics.Blit(dyeInputKnob.GetValue <Texture>(), scaledBuffer);
     fluidSimShader.SetTexture(dyeKernel, "uField", dyeField);
     fluidSimShader.SetTexture(dyeKernel, "vField", scaledBuffer);
     ExecuteFullTexShader(dyeKernel);
     Graphics.Blit(resultField, dyeField);
 }
Example #26
0
        protected bool EventKnobOrButton(string label, ValueConnectionKnob knob)
        {
            GUILayout.BeginHorizontal();
            knob.DisplayLayout();
            bool val = knob.connected() ? GUILayout.Button(label) || knob.GetValue <bool>() : GUILayout.Button(label);

            GUILayout.EndHorizontal();
            return(val);
        }
Example #27
0
    public override bool Calculate()
    {
        if (!block1Connection.connected() || !block2Connection.connected())
        {
            return(false);
        }
        VoxelBlock <Voxel> block1 = block1Connection.GetValue <VoxelBlock <Voxel> >();
        VoxelBlock <Voxel> block2 = block2Connection.GetValue <VoxelBlock <Voxel> >();

        int overlap = block1.Overlap;
        int width   = block1.Width;
        int height  = block1.Height;
        int length  = block1.Length;

        for (int y = 0; y < height + 2 * overlap; y++)
        {
            VoxelLayer <Voxel> l1 = block1.Layers[y];
            VoxelLayer <Voxel> l2 = block2.Layers[y];
            for (int x = 0; x < width + 2 * overlap; x++)
            {
                for (int z = 0; z < length + 2 * overlap; z++)
                {
                    var v1 = l1.Layer[x, z];
                    var v2 = l2.Layer[x, z];
                    switch (mode)
                    {
                    case CombiningMode.Average:
                        v1.Data = (v1.Data + v2.Data) / 2;
                        break;

                    case CombiningMode.Add:
                        v1.Data = v1.Data + v2.Data;
                        break;

                    case CombiningMode.Subtract:
                        v1.Data = v1.Data - v2.Data;
                        break;

                    case CombiningMode.Divide:
                        if (v2.Data != 0)
                        {
                            v1.Data = v1.Data / v2.Data;
                        }
                        break;

                    case CombiningMode.Multiply:
                        v1.Data = v1.Data * v2.Data;
                        break;
                    }
                }
            }
        }
        outputConnection.SetValue(block1);

        return(true);
    }
Example #28
0
    public override bool Calculate()
    {
        Texture tex = textureInputKnob.GetValue <Texture>();

        if (!textureInputKnob.connected() || tex == null)
        { // Reset outputs if no texture is available
            textureOutputKnob.ResetValue();
            outputSize = Vector2Int.zero;
            if (outputTex != null)
            {
                outputTex.Release();
            }
            return(true);
        }

        // Guard against multiple Calculate()'s per frame
        if (Time.time - lastStep > Time.deltaTime)
        {
            lastStep = Time.time;
        }
        else
        {
            textureOutputKnob.SetValue(outputTex);
            return(true);
        }

        var inputSize = new Vector2Int(tex.width, tex.height);

        if (inputSize != outputSize)
        {
            outputSize = inputSize;
            InitializeRenderTexture();
        }
        in1 = in1Knob.connected() ? in1Knob.GetValue <float>() : in1;
        in2 = in2Knob.connected() ? in2Knob.GetValue <float>() : in2;

        SetOffsetAndKnobParams();
        BoundOffset();

        int panKernel = ChooseKernel();

        panShader.SetInt("width", tex.width);
        panShader.SetInt("height", tex.height);
        panShader.SetFloats("offset", offset.x, offset.y);
        panShader.SetTexture(panKernel, "OutputTex", outputTex);
        panShader.SetTexture(panKernel, "InputTex", tex);
        var threadGroupX = Mathf.CeilToInt(tex.width / 16.0f);
        var threadGroupY = Mathf.CeilToInt(tex.height / 16.0f);

        panShader.Dispatch(panKernel, threadGroupX, threadGroupY, 1);

        // Assign output channels
        textureOutputKnob.SetValue(outputTex);

        return(true);
    }
Example #29
0
        public static int GetSeed(ValueConnectionKnob knob, int localValue)
        {
            Debug.Assert(typeof(int).IsAssignableFrom(knob.valueType), "Tried to read seed from a non-int source knob.");
            if (knob.connected())
            {
                return(knob.GetValue <int>());
            }

            return(localValue);
        }
Example #30
0
        protected override void ConfigureMaterial(Material material)
        {
            var combineTex = combineInputKnob.GetValue <Texture>();

            if (combineTex)
            {
                material.SetTexture("_CombineTex", combineTex);
            }
            material.SetFloat("_CombineMode", (float)_combineMode);
        }