Shader22_Cube立方体纹理采样

 变成立方体贴图

 

Shader "Sbin/CubeMap" {
	Properties 
	{
		_Cube ("CubeMap",cube) = "white" {}
	}
	SubShader 
	{
		pass
		{
			CGPROGRAM

			#pragma vertex vert
			#pragma fragment frag	 	
			#include "unitycg.cginc"	
			
			samplerCUBE _Cube;
			
			struct v2f 
			{
				float4 pos:POSITION;
				float3 R:TEXCOORD0;
			};
			
		
			v2f vert(appdata_base v)
			{
				v2f o;
				o.pos=mul(UNITY_MATRIX_MVP,v.Vertex);
				//视向量在世界空间中
				float3 V=-WorldSpaceViewDir(v.Vertex);
				float3 N=mul(v.normal,(float3X3)_World2Object);
				N=normalize(N);
				o.R=reflect(V,N);//反射光线
				return o;				 
			}

			fixed4 frag(v2f IN):COLOR
			{	
				fixed4 color=texCUBE(_Cube,IN.R);
				return color;
			}	

			ENDCG
		}
		
	} 
	FallBack "Diffuse"
}

 

Shader "Sbin/CarPaintSurface" 
{
	Properties 
	{
		_MainColor("MainColor",color)=(1,1,1,1)
		_SecondColor("SecondColor",color)=(1,1,1,1)
		_Center("Center",Range(-0.51,0.51))=0
		_R("R",Range(0,0.5))=0.2
		_Glossiness ("Smoothness", Range(0,1)) = 0.5
		_Metallic ("Metallic", Range(0,1)) = 0.0

		_Cube("Cubemap",cube)=""{}
	}
	SubShader 
	{
		Tags { "RenderType"="Opaque" }
		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		//制定使用的表面着色器,表面着色器的函数surf,基于物理模型的光照模型standard,
		#pragma surface surf Standard vertex:vert

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

		samplerCUBE _Cube;

		float4 _MainColor;
		float4 _SecondColor;
		float _R;
		half _Glossiness;
		half _Metallic;


		struct Input 
		{
			//float2 uv_MainTex;
			float x;
			float3 worldRefl;
		};

		void vert(inout appdata_full v,out Input o)
		{
			//o.uv_MainTex=v.TEXCOORD.xy;
			//视向量
			float3 V=-WorldSpaceViewDir(v.Vertex);
			float3 N=mul(v.normal,(float3X3)_World2Object);
			N=normalize(N);
			o.worldRefl=reflect(V,N);//反射光线
			o.x=v.Vertex.x;
		}

		

		void surf (Input IN, inout SurfaceOutputStandard o) {
			// Albedo comes from a texture tinted by color
			fixed4 c = texCUBE (_Cube, IN.worldRefl);
			o.Albedo = c.rgb;//漫反射颜色赋值
			// Metallic and smoothness come from slider variables
			o.Metallic = _Metallic;//金属化的级别
			o.Smoothness = _Glossiness;//平滑度
			o.Alpha = c.a;

			float d=IN.x-_Center;
			d=d/abs(d);
			float f=saturate(d/_R);
			d*=f;
			d=d/2+0.5;//范围在0到1之间
			o.Albedo*= lerp(_MainColor,_SecondColor,d)*2;//差值运算
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值