GPUGraph.GraphParamCollection.SetParams C# (CSharp) Method

SetParams() public method

Sets the given material to use these parameters, with their default values.
public SetParams ( Material m ) : void
m UnityEngine.Material
return void
        public void SetParams(Material m)
        {
            foreach (FloatParamInfo dat in FloatParams)
            {
                if (!m.HasProperty(dat.Name))
                {
                    Debug.LogWarning("Couldn't find property '" + dat.Name +
                                        "'; Unity may have optimized it out");
                }
                else
                {
                    m.SetFloat(dat.Name,
                               (dat.IsSlider ?
                                    Mathf.Lerp(dat.SliderMin, dat.SliderMax, dat.DefaultValue) :
                                    dat.DefaultValue));
                }
            }
            foreach (Texture2DParamInfo dat in Tex2DParams)
            {
                if (!m.HasProperty(dat.Name))
                {
                    Debug.LogWarning("Couldn't find property '" + dat.Name +
                                        "'; Unity may have optimized it out");
                }
                else
                {
                    m.SetTexture(dat.Name, dat.DefaultVal);
                }
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Generates a texture containing the given graph's noise output.
        /// If this is being called very often, create a permanent render target and material and
        ///     use the other version of this method instead for much better performance.
        /// If an error occurred, outputs to the Unity debug console and returns "null".
        /// </summary>
        /// <param name="outputComponents">
        /// The texture output.
        /// For example, pass "rgb" or "xyz" to output the noise into the red, green, and blue channels
        ///     but not the alpha channel.
        /// </param>
        /// <param name="defaultColor">
        /// The color (generally 0-1) of the color components which aren't set by the noise.
        /// </param>
        public static Texture2D GenerateToTexture(Graph g, GraphParamCollection c, int width, int height,
                                                  string outputComponents, float defaultColor,
                                                  TextureFormat format = TextureFormat.RGBAFloat)
        {
            //Generate a shader from the graph and have Unity compile it.
            string shaderPath = Path.Combine(Application.dataPath, "gpuNoiseShaderTemp.shader");
            Shader shader     = SaveShader(g, shaderPath, "TempGPUNoiseShader", outputComponents, defaultColor);

            if (shader == null)
            {
                return(null);
            }

            //Render the shader's output into a render texture and copy the data to a Texture2D.
            RenderTexture target = new RenderTexture(width, height, 16, RenderTextureFormat.ARGBFloat);

            target.Create();
            Texture2D resultTex = new Texture2D(width, height, format, false, true);

            //Create the material and set its parameters.
            Material mat = new Material(shader);

            c.SetParams(mat);

            GraphUtils.GenerateToTexture(target, mat, resultTex);

            //Clean up.
            target.Release();
            if (!AssetDatabase.DeleteAsset(StringUtils.GetRelativePath(shaderPath, "Assets")))
            {
                Debug.LogError("Unable to delete temp file: " + shaderPath);
            }

            return(resultTex);
        }
All Usage Examples Of GPUGraph.GraphParamCollection::SetParams