Unity3D的着色器介绍(四)——Fixed Function shaders实例

之前介绍了很多理论性的东西,接下来几篇就直接贴一些常见的shader实例源码,都是比较简单的例子,有兴趣的朋友可以看看。
首先是介绍一下最简单的Fixed Function shaders:

1、显示纯颜色物体
Shader “Example/FixedSolidColor” {
Properties {
_Color (“MainColor (RGB)”, Color) = (1,1,1,1)
}
SubShader {
pass
{
Lighting on
Material
{
Diffuse[_Color]
}
}
}
FallBack “Diffuse”
}
2、各种颜色通道
Shader “Example/FixedFullColor” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,0.5)
_SpecColor (“Spec Color”, Color) = (1,1,1,1)
_Emission (“Emmisive Color”, Color) = (0,0,0,0)
_Shininess (“Shininess”, Range (0.01, 1)) = 0.7
}
SubShader {
Pass {
Lighting On
SeparateSpecular On
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
}
}
}
3、显示一张贴图
Shader “Example/FixedOnePic” {
Properties {
_Color(“MainColor(RGB)”,Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader {
Pass
{
Lighting on
Color (1,1,0,1)
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex] {
Combine texture * primary DOUBLE
}
}
}
FallBack “Diffuse”
}
4、多张贴图叠加
Shader “Example/FixedMulPic” {
Properties {
_Color(“MainColor(RGB)”,Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
_MainTex2 (“Base2 (RGB)”, 2D) = “white” {}
_MainTex3 (“Base3 (RGB)”, 2D) = “white” {}
}
SubShader {
Pass
{
Lighting on
Color (1,1,0,1)
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex] {
Combine texture * primary DOUBLE
}
SetTexture [_MainTex2] {
Combine texture * previous DOUBLE
}
SetTexture [_MainTex3] {
Combine texture * previous DOUBLE
}
}
}
FallBack “Diffuse”
}
5、透明通道贴图+双面显示
Shader “Example/FixedAlphaCull” {
Properties {
_Color(“MainColor(RGB)”,Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader {
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
Cull off
Lighting on
Color (1,1,0,1)
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex] {
Combine texture * primary DOUBLE
}
}
}
FallBack “Diffuse”
}
6、假反射贴图特效
Shader “Example/FixedReflect” {
Properties {
_Color(“MainColor(RGB)”,Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {TexGen CubeReflect}
}
SubShader {
Pass
{
Lighting on
Color (1,1,0,1)
Material
{
Diffuse [_Color]
}
SetTexture [_MainTex] {
Combine texture * primary DOUBLE
}
}
}
FallBack “Diffuse”
}
可以尝试把CubeReflect替换成ObjectLinear、EyeLinear、SphereMap、CubeNormal,各有不同的效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值