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); }
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); }
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); }
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); }
public override bool Calculate() { var input = inputKnob.GetValue <ModuleBase>(); if (input == null) { outputKnob.ResetValue(); return(true); } outputKnob.SetValue(CreateModule(input)); return(true); }
public override bool Calculate() { var inputModules = inputKnobs.Cast <ValueConnectionKnob>().Where(knob => !knob.IsValueNull) .Select(knob => knob.GetValue <ModuleBase>()).ToArray(); if (inputModules.Length < MinimumInputs) { outputKnob.ResetValue(); return(true); } outputKnob.SetValue(CreateModule(inputModules)); return(true); }
public override bool Calculate() { Texture tex = textureInputKnob.GetValue <Texture>(); if (!textureInputKnob.connected() || tex == null) { // Reset outputs if no texture is available if (outputTex != null) { outputTex.Release(); } textureOutputKnob.ResetValue(); outputSize = Vector2Int.zero; return(true); } var inputSize = new Vector2Int(tex.width, tex.height); if (inputSize != outputSize) { outputSize = inputSize; InitializeRenderTexture(); } if (hueKnob.connected()) { hue = hueKnob.GetValue <float>(); } if (satKnob.connected()) { saturation = satKnob.GetValue <float>(); } if (valKnob.connected()) { value = valKnob.GetValue <float>(); } HSV = new Vector4(hue, saturation, value); //Execute HSV compute shader here HSVShader.SetVector("HSV", HSV); HSVShader.SetTexture(kernelId, "OutputTex", outputTex); HSVShader.SetTexture(kernelId, "InputTex", tex); var threadGroupX = Mathf.CeilToInt(tex.width / 16.0f); var threadGroupY = Mathf.CeilToInt(tex.height / 16.0f); HSVShader.Dispatch(kernelId, threadGroupX, threadGroupY, 1); // Assign output channels textureOutputKnob.SetValue(outputTex); return(true); }
public override bool Calculate() { if (!inputVectorKnob.connected()) { xOutputKnob.ResetValue(); yOutputKnob.ResetValue(); return(true); } var inVector = inputVectorKnob.GetValue <Vector2>(); xValue = inVector.x; yValue = inVector.y; xOutputKnob.SetValue(xValue); yOutputKnob.SetValue(yValue); return(true); }
public override bool Calculate() { width = widthInputKnob.connected() ? widthInputKnob.GetValue <float>() : width; height = heightInputKnob.connected() ? heightInputKnob.GetValue <float>() : height; Texture inputTex = textureInputKnob.GetValue <Texture>(); if (!textureInputKnob.connected() || inputTex == null) { // Reset outputs if no texture is available textureOutputKnob.ResetValue(); outputSize = Vector2Int.zero; return(true); } int kernelID = 0; if (edgeWrapMode.IsSelected("tile")) { kernelID = tileKernel; } else if (edgeWrapMode.IsSelected("mirror")) { kernelID = mirrorKernel; } else { kernelID = cropScaleKernel; } if (outputSize.x != (int)width || outputSize.y != (int)height) { outputSize = new Vector2Int((int)width, (int)height); InitializeRenderTexture(); } CropShader.SetTexture(kernelID, "InputTex", inputTex); CropShader.SetTexture(kernelID, "OutputTex", outputTex); CropShader.SetInt("iWidth", inputTex.width); CropShader.SetInt("iHeight", inputTex.height); CropShader.SetInt("oWidth", outputTex.width); CropShader.SetInt("oHeight", outputTex.height); CropShader.SetBool("applyScale", edgeWrapMode.IsSelected("scale")); var threadGroupX = Mathf.CeilToInt(outputTex.width / 16.0f); var threadGroupY = Mathf.CeilToInt(outputTex.height / 16.0f); CropShader.Dispatch(kernelID, threadGroupX, threadGroupY, 1); // Assign output channels textureOutputKnob.SetValue(outputTex); return(true); }
public override bool Calculate() { Texture inputTex = inputTexKnob.GetValue <Texture>(); if (!inputTexKnob.connected() || inputTex == null) { outputTexKnob.ResetValue(); outputSize = Vector2Int.zero; if (outputTex != null) { outputTex.Release(); } return(true); } var inputSize = new Vector2Int(inputTex.width, inputTex.height); if (inputSize != outputSize) { outputSize = inputSize; InitializeRenderTexture(); } controlSignal = controlSignalKnob.connected() ? controlSignalKnob.GetValue <float>(): controlSignal; patternShader.SetInt("width", outputSize.x); patternShader.SetInt("height", outputSize.y); patternShader.SetFloat("controlSignal", controlSignal); patternShader.SetTexture(patternKernel, "inputTex", inputTex); patternShader.SetTexture(patternKernel, "outputTex", outputTex); var modTex = modTexKnob.GetValue <Texture>(); if (modTex == null) { modTex = inputTex; } patternShader.SetTexture(patternKernel, "modTex", modTex); 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); }
public override bool Calculate() { Texture inputTex = inputTexKnob.GetValue <Texture>(); if (!inputTexKnob.connected() || inputTex == null) { outputTexKnob.ResetValue(); outputSize = Vector2Int.zero; if (outputTex != null) { outputTex.Release(); } return(true); } var inputSize = new Vector2Int(inputTex.width, inputTex.height); if (inputSize != outputSize) { outputSize = inputSize; InitializeRenderTexture(); } startHue = startHueKnob.connected() ? startHueKnob.GetValue <float>(): startHue; endHue = endHueKnob.connected() ? endHueKnob.GetValue <float>(): endHue; patternShader.SetInt("width", outputSize.x); patternShader.SetInt("height", outputSize.y); patternShader.SetFloat("startHue", startHue); patternShader.SetFloat("endHue", endHue); patternShader.SetBool("center", center); patternShader.SetFloat("offset", offset * Mathf.Sqrt(Mathf.Pow(outputSize.x, 2) + Mathf.Pow(outputSize.y, 2))); patternShader.SetTexture(patternKernel, "inputTex", inputTex); 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); }
public override bool Calculate() { Texture inputTex = inputTexKnob.GetValue <Texture>(); if (!inputTexKnob.connected() || inputTex == null) { outputTexKnob.ResetValue(); outputSize = Vector2Int.zero; if (outputTex != null) { outputTex.Release(); } return(true); } var inputSize = new Vector2Int(inputTex.width, inputTex.height); if (inputSize != outputSize) { outputSize = inputSize; InitializeRenderTexture(); } sensitivity = sensitivityKnob.connected() ? sensitivityKnob.GetValue <float>() : sensitivity; var color = Color.HSVToRGB(h, s, v); patternShader.SetFloat("sensitivity", sensitivity); patternShader.SetInt("width", outputSize.x); patternShader.SetInt("height", outputSize.y); patternShader.SetVector("keyColor", color); patternShader.SetTexture(patternKernel, "inputTex", inputTex); 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); }
public override bool Calculate() { Texture2D tex = textureInputKnob.GetValue <Texture2D>(); if (!textureInputKnob.connected() || tex == null) { // Reset outputs if no texture is available channelRKnob.ResetValue(); channelGKnob.ResetValue(); channelBKnob.ResetValue(); channelAKnob.ResetValue(); return(true); } // Create new channels float[,] channelR = new float[tex.width, tex.height]; float[,] channelG = new float[tex.width, tex.height]; float[,] channelB = new float[tex.width, tex.height]; float[,] channelA = new float[tex.width, tex.height]; for (int x = 0; x < tex.width; x++) { for (int y = 0; y < tex.height; y++) { // Fill channels Color col = tex.GetPixel(x, y); channelR[x, y] = col.r; channelG[x, y] = col.g; channelB[x, y] = col.b; channelA[x, y] = col.a; } } // Assign output channels channelRKnob.SetValue(new Channel(tex.name + "_R", channelR)); channelGKnob.SetValue(new Channel(tex.name + "_G", channelG)); channelBKnob.SetValue(new Channel(tex.name + "_B", channelB)); channelAKnob.SetValue(new Channel(tex.name + "_A", channelA)); return(true); }
public override bool Calculate() { Texture texL = texLKnob.GetValue <Texture>(); if (!texLKnob.connected() || texL == null) { outputTexKnob.ResetValue(); outputSize = Vector2Int.zero; if (outputTex != null) { outputTex.Release(); } return(true); } Texture texR = texRKnob.GetValue <Texture>(); if (!texRKnob.connected() || texR == null) { outputTexKnob.ResetValue(); outputSize = Vector2Int.zero; if (outputTex != null) { outputTex.Release(); } return(true); } var inputSize = new Vector2Int(texL.width, texL.height); if (inputSize != outputSize) { outputSize = inputSize; InitializeRenderTexture(); } patternShader.SetInt("width", outputSize.x); patternShader.SetInt("height", outputSize.y); int kernel = 0; switch (mergeModeSelection.Selected) { case "Simple": crossfader = crossfaderKnob.connected() ? crossfaderKnob.GetValue <float>() : crossfader; patternShader.SetFloat("crossfader", crossfader); kernel = fadeKernel; break; case "Layers": kernel = layerKernel; break; } patternShader.SetTexture(kernel, "texL", texL); patternShader.SetTexture(kernel, "texR", texR); patternShader.SetTexture(kernel, "outputTex", outputTex); uint tx, ty, tz; patternShader.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); var threadGroupX = Mathf.CeilToInt(((float)outputSize.x) / tx); var threadGroupY = Mathf.CeilToInt(((float)outputSize.y) / ty); patternShader.Dispatch(kernel, threadGroupX, threadGroupY, 1); outputTexKnob.SetValue(outputTex); return(true); }
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); } var inputSize = new Vector2Int(tex.width, tex.height); if (inputSize != outputSize) { outputSize = inputSize; InitializeRenderTexture(); } speed = speedInputKnob.connected() ? speedInputKnob.GetValue <float>() : speed; angle = angleInputKnob.connected() ? angleInputKnob.GetValue <float>() : angle; // Keep offset bounded by (2x) dimensions so that floating point coverage doesn't decrease // over long pans. use 2x so that mirrored textures don't jump on resetting the offset var r = speed * tex.width * Time.deltaTime; offset += new Vector2(r * Mathf.Cos(angle), r * Mathf.Sin(angle)); Vector2 mirrorSafeBounds = 2 * new Vector2(tex.width - 1, tex.height - 1); if (offset.x > mirrorSafeBounds.x) { offset.x -= mirrorSafeBounds.x; } else if (offset.x < -mirrorSafeBounds.x) { offset.x += mirrorSafeBounds.x; } if (offset.y > mirrorSafeBounds.y) { offset.y -= mirrorSafeBounds.y; } else if (offset.y < -mirrorSafeBounds.y) { offset.y += mirrorSafeBounds.y; } int panKernel = 0; if (smoothTransitions && mirror) { panKernel = bilinearMirrorKernel; } else if (smoothTransitions && !mirror) { panKernel = bilinearRepeatKernel; } else if (!smoothTransitions && mirror) { panKernel = pointMirrorKernel; } else if (!smoothTransitions && !mirror) { panKernel = pointRepeatKernel; } 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); }
public override bool Calculate() { if (targetPortCount > 1) { if ((autoplay && ((Time.time - lastCycleTime) > cycleTime)) || controlKnob.GetValue <bool>()) { Debug.Log("Cycling"); NextImage(); } else { if (Random.Range(0, 1) > .95f) { Debug.LogFormat("Elapsed: {0}, cycleTime: {1}", Time.time - lastCycleTime, cycleTime); } } if (autoplayKnob.GetValue <bool>()) { ToggleAutoplay(); } var activePort = (ValueConnectionKnob)dynamicConnectionPorts[activeTextureIndex]; Texture activeTex = activePort.GetValue <Texture>(); if (activeTex != null) { var inputSize = new Vector2Int(activeTex.width, activeTex.height); if (inputSize != outputSize) { outputSize = inputSize; InitializeRenderTexture(); } } if (fading) { var lastPort = (ValueConnectionKnob)dynamicConnectionPorts[lastTextureIndex]; Texture lastTex = lastPort.GetValue <Texture>(); patternShader.SetFloat("width", outputTex.width); patternShader.SetFloat("height", outputTex.height); patternShader.SetFloat("crossfader", (Time.time - lastCycleTime) / cycleFadeTime); patternShader.SetTexture(fadeKernel, "texL", lastTex); patternShader.SetTexture(fadeKernel, "texR", activeTex); patternShader.SetTexture(fadeKernel, "outputTex", outputTex); uint tx, ty, tz; patternShader.GetKernelThreadGroupSizes(fadeKernel, out tx, out ty, out tz); var threadGroupX = Mathf.CeilToInt(((float)outputSize.x) / tx); var threadGroupY = Mathf.CeilToInt(((float)outputSize.y) / ty); patternShader.Dispatch(fadeKernel, threadGroupX, threadGroupY, 1); if (Time.time - fadeBeginTime > cycleFadeTime) { fading = false; } } else { Graphics.Blit(activeTex, outputTex); } } else { if (outputSize != Vector2Int.zero) { outputTexKnob.ResetValue(); outputSize = Vector2Int.zero; if (outputTex != null) { outputTex.Release(); } return(true); } } patternShader.SetInt("width", outputSize.x); patternShader.SetInt("height", outputSize.y); //switch (mergeModeSelection.Selected) //{ // case "Simple": // crossfader = crossfaderKnob.connected() ? crossfaderKnob.GetValue<float>() : crossfader; // patternShader.SetFloat("crossfader", crossfader); // kernel = fadeKernel; // break; // case "Layers": // kernel = layerKernel; // break; //} //patternShader.SetTexture(kernel, "texL", texL); //patternShader.SetTexture(kernel, "texR", texR); //patternShader.SetTexture(kernel, "outputTex", outputTex); //uint tx,ty,tz; //patternShader.GetKernelThreadGroupSizes(kernel, out tx, out ty, out tz); //var threadGroupX = Mathf.CeilToInt(((float)outputSize.x) / tx); //var threadGroupY = Mathf.CeilToInt(((float)outputSize.y) / ty); //patternShader.Dispatch(kernel, threadGroupX, threadGroupY, 1); outputTexKnob.SetValue(outputTex); return(true); }