使用alpha参数创建透明效果

作者:追风剑情 发布于:2015-8-27 23:10 分类:Shader

一、准备一张黑白图片512x512像素

huidu.png

一、创建LambertAlpha.shader和LambertAlpha.mat

Shader "Custom/LambertAlpha" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_TransVal ("Transparency Value", Range(0, 1)) = 0.5
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert alpha

		sampler2D _MainTex;
		float _TransVal;

		struct Input {
			float2 uv_MainTex;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			half4 c = tex2D (_MainTex, IN.uv_MainTex);
			o.Albedo = c.rgb;
			o.Alpha = c.r * _TransVal;//Alpha = 红色通道值r * 转换值
		}
		ENDCG
	} 
	FallBack "Diffuse"
}


二、向场景中添加Sphere、Plane,如图:

h1.png

效果

hhhhhhhhhh.png

标签: Shader

Powered by emlog  蜀ICP备18021003号   sitemap

川公网安备 51019002001593号