コード例 #1
0
ファイル: OutputNode.cs プロジェクト: facybenbook/Mixture
        public void RemoveTextureOutput(OutputTextureSettings settings)
        {
            outputTextureSettings.Remove(settings);

#if UNITY_EDITOR
            // When the graph is realtime, we don't have the save all button, so we call is automatically
            if (graph.type == MixtureGraphType.Realtime)
            {
                graph.UpdateRealtimeAssetsOnDisk();
            }
#endif
        }
コード例 #2
0
ファイル: OutputNode.cs プロジェクト: facybenbook/Mixture
        bool UpdateFinalCopyMaterial(OutputTextureSettings targetOutput)
        {
            if (targetOutput.finalCopyMaterial == null)
            {
                targetOutput.finalCopyMaterial = CreateFinalCopyMaterial();
                if (!graph.IsObjectInGraph(targetOutput.finalCopyMaterial))
                {
                    graph.AddObjectToGraph(targetOutput.finalCopyMaterial);
                }
            }

            // Manually reset all texture inputs
            ResetMaterialPropertyToDefault(targetOutput.finalCopyMaterial, "_Source_2D");
            ResetMaterialPropertyToDefault(targetOutput.finalCopyMaterial, "_Source_3D");
            ResetMaterialPropertyToDefault(targetOutput.finalCopyMaterial, "_Source_Cube");

            var input = targetOutput.inputTexture;

            if (input != null)
            {
                if (input.dimension != (TextureDimension)rtSettings.dimension)
                {
                    Debug.LogError("Error: Expected texture type input for the OutputNode is " + graph.mainOutputTexture.dimension + " but " + input?.dimension + " was provided");
                    return(false);
                }

                MixtureUtils.SetupDimensionKeyword(targetOutput.finalCopyMaterial, input.dimension);

                if (input.dimension == TextureDimension.Tex2D)
                {
                    targetOutput.finalCopyMaterial.SetTexture("_Source_2D", input);
                }
                else if (input.dimension == TextureDimension.Tex3D)
                {
                    targetOutput.finalCopyMaterial.SetTexture("_Source_3D", input);
                }
                else
                {
                    targetOutput.finalCopyMaterial.SetTexture("_Source_Cube", input);
                }

                targetOutput.finalCopyMaterial.SetInt("_IsSRGB", targetOutput.sRGB ? 1 : 0);
            }

            if (targetOutput.finalCopyRT != null)
            {
                targetOutput.finalCopyRT.material = targetOutput.finalCopyMaterial;
            }

            return(true);
        }
コード例 #3
0
ファイル: OutputNode.cs プロジェクト: TrentSterling/Mixture
        // TODO: output texture setting presets when adding a new output

        public OutputTextureSettings AddTextureOutput(OutputTextureSettings.Preset preset)
        {
            var output = new OutputTextureSettings
            {
                inputTexture      = null,
                name              = $"Input {outputTextureSettings?.Count + 1}",
                finalCopyMaterial = CreateFinalCopyMaterial(),
            };

            if (graph.isRealtime)
            {
                output.finalCopyRT = graph.mainOutputTexture as CustomRenderTexture;
            }
            else
            {
                UpdateTempRenderTexture(ref output.finalCopyRT, output.hasMipMaps, output.customMipMapShader == null);
                graph.onOutputTextureUpdated += () => {
                    UpdateTempRenderTexture(ref output.finalCopyRT, output.hasMipMaps, output.customMipMapShader == null);
                };
            }

            // output.finalCopyRT can be null here if the graph haven't been imported yet
            if (output.finalCopyRT != null)
            {
                output.finalCopyRT.material = output.finalCopyMaterial;
            }

            // Try to guess the correct setup for the user
#if UNITY_EDITOR
            var names = outputTextureSettings.Select(o => o.name).ToArray();
            output.SetupPreset(preset, (name) => UnityEditor.ObjectNames.GetUniqueName(names, name));
#endif

            // Output 0 is always Main Texture
            if (outputTextureSettings.Count == 0)
            {
                output.name   = "Main Texture";
                output.isMain = true;
            }

            outputTextureSettings.Add(output);

#if UNITY_EDITOR
            if (graph.isRealtime)
            {
                graph.UpdateRealtimeAssetsOnDisk();
            }
#endif

            return(output);
        }
コード例 #4
0
        public OutputTextureView(MixtureGraphView graphView, OutputNodeView nodeView, OutputTextureSettings targetSettings)
        {
            this.nodeView       = nodeView;
            node                = nodeView.nodeTarget as OutputNode;
            this.targetSettings = targetSettings;
            this.graphView      = graphView;

            root = Resources.Load <VisualTreeAsset>("UI Blocks/OutputTexture").CloneTree();
            Add(root);

            LoadOutputElements();
            InitializeView();
            RefreshSettings();
        }
コード例 #5
0
ファイル: OutputNode.cs プロジェクト: TrentSterling/Mixture
        void GenerateCustomMipMaps(CommandBuffer cmd, OutputTextureSettings targetOutput)
        {
#if UNITY_EDITOR
            if (targetOutput.mipmapTempRT == null || targetOutput.finalCopyRT == null)
            {
                return;
            }

            cmd.BeginSample(generateMipMapSampler);

            if (targetOutput.mipMapPropertyBlock == null)
            {
                targetOutput.mipMapPropertyBlock = new MaterialPropertyBlock();
            }

            int slice = 0;
            // TODO: support 3D textures and Cubemaps
            // for (int slice = 0; slice < targetOutput.finalCopyRT.volumeDepth; slice++)
            {
                for (int i = 0; i < targetOutput.finalCopyRT.mipmapCount - 1; i++)
                {
                    int mipLevel = i + 1;
                    targetOutput.mipmapTempRT.name = "Tmp mipmap";
                    cmd.SetRenderTarget(targetOutput.mipmapTempRT, mipLevel, CubemapFace.Unknown, 0);

                    Vector4 textureSize = new Vector4(targetOutput.finalCopyRT.width, targetOutput.finalCopyRT.height, targetOutput.finalCopyRT.volumeDepth, 0);
                    textureSize /= 1 << (mipLevel);
                    Vector4 textureSizeRcp = new Vector4(1.0f / textureSize.x, 1.0f / textureSize.y, 1.0f / textureSize.z, 0);

                    targetOutput.mipMapPropertyBlock.SetTexture("_InputTexture_2D", targetOutput.finalCopyRT);
                    targetOutput.mipMapPropertyBlock.SetTexture("_InputTexture_3D", targetOutput.finalCopyRT);
                    targetOutput.mipMapPropertyBlock.SetFloat("_CurrentMipLevel", mipLevel - 1);
                    targetOutput.mipMapPropertyBlock.SetFloat("_MaxMipLevel", targetOutput.finalCopyRT.mipmapCount);
                    targetOutput.mipMapPropertyBlock.SetVector("_InputTextureSize", textureSize);
                    targetOutput.mipMapPropertyBlock.SetVector("_InputTextureSizeRcp", textureSizeRcp);
                    targetOutput.mipMapPropertyBlock.SetFloat("_CurrentSlice", slice / (float)targetOutput.finalCopyRT.width);

                    MixtureUtils.SetupDimensionKeyword(targetOutput.customMipMapMaterial, targetOutput.finalCopyRT.dimension);
                    cmd.DrawProcedural(Matrix4x4.identity, targetOutput.customMipMapMaterial, 0, MeshTopology.Triangles, 3, 1, targetOutput.mipMapPropertyBlock);

                    cmd.CopyTexture(targetOutput.mipmapTempRT, slice, mipLevel, targetOutput.finalCopyRT, slice, mipLevel);
                }
            }

            cmd.EndSample(generateMipMapSampler);
#endif
        }