Shader学习过程7——SurfaceShader

SurfaceOutput:

Input:

Lighting:光照

shadow:阴影

              只是对顶点和片段着色器的一种包装。

Shader "Custom/SurfaceShader" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_Glossiness ("Smoothness", Range(0,1)) = 0.5
		_Metallic ("Metallic", Range(0,1)) = 0.0
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		//pragma是编译指令 他的各式就是#号开头
		//surface:代表我们用surface的方式来写shader
		//surf :函数名 就是下面的 void surf 。。。。
		//Standard:光照模型,实际上也是一个函数
		#pragma surface surf Standard fullforwardshadows

		// Use shader model 3.0 target, to get nicer looking lighting
		#pragma target 3.0

		sampler2D _MainTex;

		struct Input {
			float2 uv_MainTex;//纹理采样  必须以uv开头 或者uv2 开头   代表第一套uv或者第二套uv
		};

		half _Glossiness;
		half _Metallic;
		fixed4 _Color;

		UNITY_INSTANCING_CBUFFER_START(Props)
			// put more per-instance properties here
		UNITY_INSTANCING_CBUFFER_END
		//无返回值 两个参数 input 从外面输入   inout 既是输入 也是输出 
		void surf (Input IN, inout SurfaceOutputStandard o) {
			// Albedo comes from a texture tinted by color
			fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
			o.Albedo = c.rgb;//漫反射的颜色值
			// Metallic and smoothness come from slider variables
			o.Metallic = _Metallic; //金属度
			o.Smoothness = _Glossiness;//金属光滑度 其实就是高光区域大小的控制
			o.Alpha = c.a;
		}
		ENDCG
	}
	FallBack "Diffuse"
}

猜你喜欢

转载自blog.csdn.net/baicaishisan/article/details/80563794
今日推荐