查看: 1918|回复: 0
打印 上一主题 下一主题

shader简单练习 混合两张贴图

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-2-23 15:18:03 |只看该作者 |倒序浏览
使用unity3d 中的 ShaderLab 实现两张不同贴图之前的混合 类似于3dsmax 中的Blend材质.
1.在Properties 中定义三个变量.我们需要使用的..1. _Color 主要是用它的 Alpha 来进行两张图的混合 ,2.两张需要进行操作的贴图
2.在混合时主要是使用 SetTexture 中的 Combine scr1 lerp(constant) src2. 这里要注意.在一个SetTextrue 中我们只能对一个texture来操作. 所以在混合前我们需要先用一个SetTexture 将第一张图贴上去.
 然后再用 Combine previous lerp(constant) texture .将第二张与之前的(previous)来混合,lerp(constant) 就是以_Color的Alpha来做为混合的界定.
Shader "ztc_Blend"
{
     Properties
     {
         _Color ("Main Color",Color) = (1,1,1,0.5)
         _MainTex ("FrontTex (RGB)", 2D) = "white" {}
         _BackTex ("BackTex (RGB)", 2D) = "white" {}
     }
     SubShader
     {
         Pass
         {
             Material
             {
                 Diffuse[_Color]
             }
             Lighting On
            
             SetTexture [_MainTex] //the default Texture
             {
                 Combine texture
             }
             SetTexture [_BackTex] //use the combine lerp to mix two texture by the Main color's Alpha
             {
                 constantColor [_Color]
                 Combine previous lerp(constant) texture
             }
            
         }
     }
     FallBack "Diffuse"
}


转自:http://www.cnblogs.com/easyfrog/archive/2012/01/12/2320708.html
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-2-24 02:41 , Processed in 0.092624 second(s), 31 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部