// https://docs.unity3d.com/2018.3/Documentation/Manual/SL-SurfaceShaders.html
Shader "Sbin/sf1"
{
Properties
{
// 主纹理
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "queue"="transparent"}
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Lambert fullforwardshadows alpha addshadow
//这里使用的 alpha 选项做透明,同时需要在tags中指定渲染队列为transparent
// 此时如果不使用 fallback 而是使用 addshadow 选项,将不能得到阴影效果,
// 因为有可能透过这个物体会有其他的物体的光线穿透到这个物体的阴影范围内,这样不符合透明物体的样貌
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
struct Input
{
float2 uv_MainTex;
};
sampler2D _MainTex;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutput o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
// FallBack "Diffuse"
// 当 surface shader 编译过后没有没有得到阴影投射器的通道时
// 可以使用 fallback 指定一个具有阴影的通道,来使用这个通道的阴影投射器
}
网友评论