zoukankan      html  css  js  c++  java
  • Unity3D ShaderLab 混合两张贴图(Blend)

    使用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来做为混合的界定.

    View Code
     1 Shader "ztc_Blend" 
    2 {
    3 Properties
    4 {
    5 _Color ("Main Color",Color) = (1,1,1,0.5)
    6 _MainTex ("FrontTex (RGB)", 2D) = "white" {}
    7 _BackTex ("BackTex (RGB)", 2D) = "white" {}
    8 }
    9 SubShader
    10 {
    11 Pass
    12 {
    13 Material
    14 {
    15 Diffuse[_Color]
    16 }
    17 Lighting On
    18
    19 SetTexture [_MainTex] //the default Texture
    20 {
    21 Combine texture
    22 }
    23 SetTexture [_BackTex] //use the combine lerp to mix two texture by the Main color's Alpha
    24 {
    25 constantColor [_Color]
    26 Combine previous lerp(constant) texture
    27 }
    28
    29 }
    30 }
    31 FallBack "Diffuse"
    32 }


    结果:


  • 相关阅读:
    HDU6301 SET集合的应用 贪心
    线段树与树状数组的对比应用
    树状数组
    JDBC链接MySQL数据库
    HDU4686Arc of Dream 矩阵快速幂
    HDU1757矩阵快速幂
    B1013. 数素数 (20)
    B1023. 组个最小数 (20)
    [教材]B1020. 月饼 (25)
    [教材]A1025. PAT Ranking (25)
  • 原文地址:https://www.cnblogs.com/easyfrog/p/2320708.html
Copyright © 2011-2022 走看看