当前位置:网站首页>Unity shader (pass user data to shader)

Unity shader (pass user data to shader)

2022-07-07 09:25:00 heater404

Unity Shader( to Shader Passing user data )

Modify... By code Shader Properties in

I mentioned earlier that various types of attributes can be defined , Then you can make changes on the panel . But in fact, we can also modify it in the code .

	Properties
	{
        _Color("I am Color", Color) = (1,1,1,1)// In turn RGBA(0-1)
        _Int("I am Int", Int) = 1
	}
    public Material material;//Shader Where material
    void Start()
    {
    
        material.SetInt("_Int", 200);
        material.SetColor("_Color", new Color(0, 0, 0, 0));
    }

stay Pass Define the data type in and then assign a value

Shader "Unlit/NewUnlitShader"
{
	Properties
	{
        _Color("I am Color", Color) = (1,1,1,1)// In turn RGBA(0-1)
        _Int("I am Int", Int) = 1
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

            float b2;    
            RWStructuredBuffer<float> b5;

			ENDCG
		}
	}
}
public class NewBehaviourScript : MonoBehaviour
{
    
    public Material material;//Shader Where material
    ComputeBuffer b5Buffer;
    // Use this for initialization
    void Start()
    {
    
        material.SetInt("_Int", 200);
        material.SetColor("_Color", new Color(0, 0, 0, 0));


        material.SetFloat("float", 998);
        b5Buffer = new ComputeBuffer(24, 4);
        material.SetBuffer("b5", b5Buffer);
    }
}
原网站

版权声明
本文为[heater404]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130625200266.html