unity3d shader学习(1)

文章内容主要参考冯乐乐的博客,原链接:点击打开链接

shader介绍的前3条链接

只是我把内容写成代码,然后了注释,比较简洁,附代码:



//shader的路径,它会出现在你选择某个Material的shader时的下拉列表里,并且可以随时更改;
Shader "Custom/BasicDiffuse" {

//大括号内的内容会出现在inspect面板,注意这里不要;号
	Properties {
		//变量名,在inspect里面显示名字,数据类型,默认值
		_EmissiveColor("Emissive Color",Color)=(1,1,1,1)
		_AmbientColor("Ambient Color",Color)=(1,1,1,1)
		_MySliderValue("This is a slider",Range(0,10))=2.5
		_MainTexture("Base(RGB)",2D)="white"{}
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		#pragma surface surf Standard fullforwardshadows

		// Use shader model 3.0 target, to get nicer looking lighting
		#pragma target 3.0
		//当我们在Properties块中声明一个新的变量时,就提供了在Inspector界面中改变它的值的方式。
		//这将自动建立一个连接,两者将操作同一个数据。
		//数据类型,变量名,这里注意变量名,要跟Properties里面声明的相同
		float4 _EmissiveColor;
		float4 _AmbientColor;
		float _MySliderValue;

		struct Input {
			float2 uv_MainTex;
		};

		half _Glossiness;
		half _Metallic;
		fixed4 _Color;
		//在这个函数里面计算值
		void surf (Input IN, inout SurfaceOutputStandard o) {
			float4 c;
			c=pow((_EmissiveColor+_AmbientColor),_MySliderValue);
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	}
	//当这个shader在当前环境中运行失败后,会默认调用Unity自带的Diffuse Shader
	FallBack "Diffuse"
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值