Beispiel #1
0
        public void SetOutputSizeEnumTest()
        {
            Substance.Game.Substance subs  = SubstanceExtensionsTestData.Instance.TestSubstance;
            SubstanceGraph           graph = subs.graphs[0];

            int cachedSize = graph.GetInputVector2Int(SubstanceGraphExtensions.OutputSizeParameter)[0];
            SubstanceOutputSize newSize = cachedSize == 9 ? SubstanceOutputSize._1024 : SubstanceOutputSize._512;

            Debug.Log(graph.GetGeneratedTextures()[0].width);

            graph.SetOutputSize(newSize);

            //NativeFunctions.cppProcessOutputQueue();
            graph.QueueForRender();
            Substance.Game.Substance.RenderSubstancesSync();

            int width = graph.GetGeneratedTextures()[0].width;


            Debug.Log(graph.GetGeneratedTextures()[0].width);

            Assert.AreEqual(width, (newSize == SubstanceOutputSize._1024 ? 1024 : 512));

            graph.SetOutputSize(cachedSize);

            //NativeFunctions.cppProcessOutputQueue();
            graph.QueueForRender();
            Substance.Game.Substance.RenderSubstancesSync();
        }
Beispiel #2
0
        protected override void DrawTargetField(Rect position, SerializedProperty property, SerializedProperty assetProperty)
        {
            SubstanceGraph graph = assetProperty.objectReferenceValue as SubstanceGraph;

            string[]     outputNames = graph.outputNames.Split(',');
            GUIContent[] labels      = new GUIContent[outputNames.Length];

            for (int i = 0; i < labels.Length; i++)
            {
                labels[i] = new GUIContent(outputNames[i]);
            }

            int index = 0;

            for (int i = 0; i < outputNames.Length; i++)
            {
                if (property.stringValue == outputNames[i])
                {
                    index = i;
                    break;
                }
            }

            EditorGUI.BeginChangeCheck();
            index = EditorGUI.Popup(position, index, labels);
            if (EditorGUI.EndChangeCheck())
            {
                property.stringValue = outputNames[index];
            }
        }
Beispiel #3
0
        /// <summary>
        /// Find the <see cref="SubstanceGraph"/> associated with a given material.
        /// </summary>
        private void Start()
        {
            SubstanceGraph graph = SubstanceGraph.Find(mat);

            if (graph != null)
            {
            }
        }
Beispiel #4
0
        /// <summary>
        /// Randomizes and returns the random seed value for a <see cref="SubstanceGraph"/> asset.
        /// </summary>
        /// <param name="graph">The graph to randomize the seed value for.</param>
        public static int RandomizeSeed(this SubstanceGraph graph)
        {
            int newSeed = Random.Range(int.MinValue, int.MaxValue);

            graph.SetInputInt(RandomSeedParameter, newSeed);

            return(newSeed);
        }
    //creates an instance of a CubemapGenerator prefab if needed, sets the inputs, then tell the new generator to generate
    public Cubemap generateCubemap(SubstanceGraph mat, CubemapGenerator.Sizes size)
    {
        if (!spawnedInstance)
        {
            spawnedInstance = Instantiate(cubmapGeneratorPrefab);
        }

        spawnedInstance.size          = size;
        spawnedInstance.inputMaterial = mat;

        return(spawnedInstance.generate());
    }
        protected override void DrawTargetField(Rect position, SerializedProperty property, SerializedProperty assetProperty)
        {
            SubstanceGraph     graph        = assetProperty.objectReferenceValue as SubstanceGraph;
            SerializedProperty typeProperty = property.GetSiblingProperty("type");

            int inputCount = NativeFunctions.cppGetNumInputs(graph.nativeHandle);

            NativeTypes.Input[] inputs = NativeTypes.GetNativeInputs(graph, inputCount);
            GUIContent[]        labels = new GUIContent[inputCount];

            for (int i = 0; i < inputCount; i++)
            {
                labels[i] = new GUIContent(string.Format("{0}{1} ({2} - {3})", (string.IsNullOrEmpty(inputs[i].group) ? "" : inputs[i].group + "/"), inputs[i].label, inputs[i].name, (SubstanceInputType)inputs[i].substanceInputType), inputs[i].name);
            }

            int index = -1;

            for (int i = 0; i < inputCount; i++)
            {
                if (property.stringValue == inputs[i].name)
                {
                    index = i;
                    break;
                }
            }

            if (index < 0 && inputCount > 0)
            {
                index = 0;
                property.stringValue  = inputs[index].name;
                typeProperty.intValue = inputs[index].substanceInputType;
            }

            EditorGUI.BeginChangeCheck();
            index = EditorGUI.Popup(position, index, labels);
            if (EditorGUI.EndChangeCheck())
            {
                property.stringValue  = inputs[index].name;
                typeProperty.intValue = inputs[index].substanceInputType;
            }
        }
Beispiel #7
0
        public void SetOutputSizeTest()
        {
            Substance.Game.Substance subs  = SubstanceExtensionsTestData.Instance.TestSubstance;
            SubstanceGraph           graph = subs.graphs[0];

            int cachedSize = graph.GetInputVector2Int(SubstanceGraphExtensions.OutputSizeParameter)[0];
            int newSize    = cachedSize == 9 ? 10 : 9;

            graph.SetOutputSize(newSize);
            graph.QueueForRender();

            Substance.Game.Substance.RenderSubstancesSync();

            int width = graph.GetGeneratedTextures()[0].width;

            Debug.Log(string.Format("{0} | {1} | {2} - {3}", width, (newSize == 10 ? 1024 : 512), cachedSize, newSize));

            Assert.AreEqual(width, (newSize == 10 ? 1024 : 512));

            graph.SetOutputSize(cachedSize);
            graph.QueueForRender();

            Substance.Game.Substance.RenderSubstancesSync();
        }
Beispiel #8
0
        /// <summary>
        /// Returns the output size of a graph, in proper pixel width and height. ie (1024, 1024)
        /// </summary>
        /// <param name="graph">The graph to get the output size of.</param>
        public static Vector2Int GetOutputSize(this SubstanceGraph graph)
        {
            int[] ints = graph.GetInputVector2Int(OutputSizeParameter);
            int   x    = 1024;
            int   y    = 1024;

            switch (ints[0])
            {
            case 5:
                x = 32;
                break;

            case 6:
                x = 64;
                break;

            case 7:
                x = 128;
                break;

            case 8:
                x = 256;
                break;

            case 9:
                x = 512;
                break;

            case 10:
                x = 1024;
                break;

            case 11:
                x = 2046;
                break;

            case 12:
                x = 4096;
                break;
            }

            switch (ints[1])
            {
            case 5:
                y = 32;
                break;

            case 6:
                y = 64;
                break;

            case 7:
                y = 128;
                break;

            case 8:
                y = 256;
                break;

            case 9:
                y = 512;
                break;

            case 10:
                y = 1024;
                break;

            case 11:
                y = 2046;
                break;

            case 12:
                y = 4096;
                break;
            }

            return(new Vector2Int(x, y));
        }
Beispiel #9
0
        /// <summary>
        /// Set the random seed value for a <see cref="SubstanceGraph"/> asset. Returns the new seed value.
        /// </summary>
        /// <param name="graph">The <see cref="SubstanceGraph"/> to set the random seed value for.</param>
        /// <param name="seed">Value to set the random seed to.</param>
        public static int SetRandomSeed(this SubstanceGraph graph, int seed)
        {
            graph.SetInputInt(RandomSeedParameter, seed);

            return(seed);
        }
Beispiel #10
0
        /// <summary>
        /// Sets and returns the output size of a <see cref="SubstanceGraph"/>.
        /// </summary>
        /// <param name="graph">The graph to set the output size for.</param>
        /// <param name="x">Width of the output size. (10 = 1024)</param>
        /// <param name="y">Height of the output size. (10 = 1024)</param>
        public static Vector2Int SetOutputSize(this SubstanceGraph graph, int x, int y)
        {
            graph.SetInputVector2Int(OutputSizeParameter, x, y);

            return(new Vector2Int(x, y));
        }
Beispiel #11
0
 /// <summary>
 /// Sets and returns the output size of a <see cref="SubstanceGraph"/>.
 /// </summary>
 /// <param name="graph">The graph to set the output size for.</param>
 /// <param name="x">Width of the output size. (10 = 1024)</param>
 /// <param name="y">Height of the output size. (10 = 1024)</param>
 public static Vector2Int SetOutputSize(this SubstanceGraph graph, SubstanceOutputSize x, SubstanceOutputSize y)
 {
     return(graph.SetOutputSize((int)x, (int)y));
 }
Beispiel #12
0
 /// <summary>
 /// Sets and returns the output size of a <see cref="SubstanceGraph"/>.
 /// </summary>
 /// <param name="graph">The graph to set the output size for.</param>
 /// <param name="size">The size to set the output size value to. (10 = 1024 x 1024)</param>
 public static Vector2Int SetOutputSize(this SubstanceGraph graph, int size)
 {
     return(graph.SetOutputSize(size, size));
 }
Beispiel #13
0
 /// <summary>
 /// Sets and returns the output size of a <see cref="SubstanceGraph"/>.
 /// </summary>
 /// <param name="graph">The graph to set the output size for.</param>
 /// <param name="size">The size to set the output size value to. (10 = 1024 x 1024)</param>
 public static Vector2Int SetOutputSize(this SubstanceGraph graph, SubstanceOutputSize size)
 {
     return(graph.SetOutputSize((int)size));
 }
Beispiel #14
0
        /// <summary>
        /// Returns the output size of a graph, in internal substance int values. ie (10, 10)
        /// </summary>
        /// <param name="graph">The graph to get the output size of.</param>
        public static Vector2Int GetOutputSizeInt(this SubstanceGraph graph)
        {
            int[] ints = graph.GetInputVector2Int(OutputSizeParameter);

            return(new Vector2Int(ints[0], ints[1]));
        }
Beispiel #15
0
    void GetMat()
    {
        Material mat = this.GetComponent <Renderer>().sharedMaterial;

        substance = SubstanceGraph.Find(mat);
    }