固定管线
基础框架
首先得到一个这样的基础框架
Shader "Custom/NewSurfaceShader"
{
SubShader
{
}
}
加颜色
然后加个颜色试试
Shader "Custom/NewSurfaceShader"
{
SubShader{
pass{
color(1,1,1,1)
}
}
}
外部改颜色
需要注意,如果想将外部的颜色直接赋值给shader的color,要使用【】
而不是()
Shader "Custom/NewSurfaceShader"
{
Properties{
_Color("MainColor",color)=(1,1,1,1)
}
SubShader{
pass{
color[_Color]
}
}
}
此时虽然可以改颜色,但是看起来只是个简单的二维球形
漫反射diffuse
给材质加上漫反射光
Shader "Custom/NewSurfaceShader"
{
Properties{
_Color("MainColor",color)=(1,1,1,1)
}
SubShader{
pass{
material{
diffuse[_Color]
}
}
}
}
此时发现无论改什么颜色,球体都是纯白色
再加上这样一句代码
material{
diffuse[_Color]
}
Lighting on
此时所看到的颜色就是物体自身的颜色
环境光ambient
给材质加上环境光
pass{
material{
diffuse[_Color]
ambient[_Ambient]
}
Lighting on
}
}
镜面反射高光specular
如果不加SeparateSpecular
没有任何反应,加上SeparateSpecular
代表添加独立镜面反射高光
pass{
material{
diffuse[_Color]
ambient[_Ambient]
specular[_Specular]
}
Lighting on
SeparateSpecular on
}
可以看到,大面积的反射高光明显不是我们想要的
光泽度shininess
设置光泽度后
pass{
material{
diffuse[_Color]
ambient[_Ambient]
specular[_Specular]
shininess[_Shininess]
}
Lighting on
SeparateSpecular on
}
自发光emission
pass{
material{
diffuse[_Color]
ambient[_Ambient]
specular[_Specular]
shininess[_Shininess]
emission[_Emission]
}
Lighting on
SeparateSpecular on
}
贴图settexture
Shader "Custom/NewSurfaceShader"
{
Properties{
_Color("MainColor",color)=(1,1,1,1)
_Ambient("ambient",color)=(0.3,0.3,0.3,0.3)
_Specular("specular",color)=(1,1,1,1)
_Shininess("shininess",Range(0,8))=4
_Emission("emission",color)=(1,1,1,1)
_MainTex("MainTex",2D)=""
}
SubShader{
pass{
material{
diffuse[_Color]
ambient[_Ambient]
specular[_Specular]
shininess[_Shininess]
emission[_Emission]
}
Lighting on
SeparateSpecular on
settexture[_MainTex]
{
Combine texture
}
}
}
}
combine(合并)
后面直接跟空格
该纹理使用时没用到之前设置的光照数值,是因为combine
只连接了纹理贴图,没有连接光照
settexture[_MainTex]
{
Combine texture*primary
}
因为texture
和primary
都是0-1的数值,所以最后的显示颜色灰暗一些
settexture[_MainTex]
{
Combine texture*primary double
}
加上double会改善
多纹理混合
一个settexture
只能加载一个纹理,所以多纹理混合可以多写几个settexture
settexture[_MainTex]
{
Combine texture*primary double
}
settexture[_SecondTex]
{
Combine texture*primary double
}
但是可以看到没有任何反应,问题出在primary
上,它是代表顶点着色后光照的颜色,不包括贴图,所以这里应该使用previous
settexture[_SecondTex]
{
Combine texture*previous double
}