Pass 通道显示贴图的几种方法
下面是几种显示模型贴图的方法,在此使用的是固定管线方法
方法一
Shader "Custom/PassOne" {
Properties {
//定义一个贴图
_MainTex ("Base (RGB)", 2D) = "white" {}
//定义一个颜色
_Color ("Main Color", Color) = (1, 1, 1, 1)
_SpecColor ("Spec Color", Color) = (1, 1, 1, 1)
_Emission ("Emission Color", Color) = (1, 1, 1, 1)
_Shiness ("Shiness", Range(0, 1)) = 0.5
}
SubShader
{
Tags {"RenderType" = "Opaque" "IGNOREPROJECTOR" = "TRUE" "QUEUE" = "Transparent"}
LOD 200
Pass
{
//在此使用 Material 下面几个方法可以结合实际情况选择使用,
//如果一个都不使用那么模型将显示为黑色,没有任何光
Material
{
Diffuse [_Color] //漫反射颜色
Ambient [_Color] // 环境光
Shininess [_Shiness] // 曲面反射
Emission [_Emission] // 自发光
Specular [_SpecColor] //镜面反射
}
Lighting On
//给材质设置 贴图
SetTexture [_MainTex]
{
Combine texture * primary double
}
}
}
FallBack "Diffuse"
}
方法二
Shader "Custom/PassTwo" {
Properties {
//定义一个贴图
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Tags {"RenderType" = "Opaque" "IGNOREPROJECTOR" = "TRUE" "QUEUE" = "Transparent"}
LOD 200
Pass
{
//使用顶点色代替 Material 中的漫反射和环境光
//在此必须使用该方法,否则模型会变成黑色,即没有任何光
ColorMaterial AmbientAndDiffuse
Lighting On
//给材质设置 贴图
SetTexture [_MainTex]
{
Combine texture * primary double
}
}
}
FallBack "Diffuse"
}
方法三
Shader "Custom/PassThree" {
Properties {
//定义一个贴图
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Tags {"RenderType" = "Opaque" "IGNOREPROJECTOR" = "TRUE" "QUEUE" = "Transparent"}
LOD 200
Pass
{
// 通过绑定固定通道来使用定点色
BindChannels
{
Bind "Vertex", vertex // 绑定定点
Bind "Normal", normal
Bind "Color", color
Bind "Texcoord", texcoord0
Bind "Texcoord", texcoord1
}
//此处 不能设置为 Lighting On, 否则模型贴图显示不出来
//Lighting Off
//给材质设置 贴图
SetTexture [_MainTex]
{
Combine texture * primary double
}
}
}
FallBack "Diffuse"
}
实际使用效果如下
第一种方法
世界中可以没有光
第二种方法
世界中必须要有光,否则太暗
第三种方法
世界中可以没有光
上面三种均可显示,效果上不完全相同,由于用到的功能有限,所以功能有限,更过功能接下来的博客会一一赘述