zoukankan      html  css  js  c++  java
  • 优化实现Mobile/Bumped Diffuse

    在上一篇帖子的基础上增加一张法线贴图即可:

    Shader "James/Scene/Bumped_Diffuse"
    {
        Properties
        {
            _MainTex ("Base (RGB)", 2D) = "white" {}
            _BumpTex("Normal Map", 2D) = "bump" {}
            _MainLightColor("主光颜色", Color) = (1,1,1,1)
            _MainLightDir("主光方向", Vector) = (1,1,0,0)
            _MainLightBrightness ("主光强度", Range(0, 10)) = 1
        }
        
        SubShader
        {
            Tags { "RenderType"="Opaque" "Queue"="Geometry" }
            LOD 200
            
            Pass
            {
                Tags { "LightMode"="ForwardBase" }
                Lighting Off
                
                CGPROGRAM
                #pragma fragmentoption ARB_precision_hint_fastest
                
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_fog
                
                #include "UnityCG.cginc"
    
                float4 _MainLightColor;
                float4 _MainLightDir;
                float _MainLightBrightness;
    
                uniform sampler2D _MainTex, _BumpTex;
                uniform half4 _MainTex_ST, _BumpTex_ST;
    
                struct vertexIN_base
                {
                    float4 vertex : POSITION;
                    float3 normal : NORMAL;
                    float4 tangent : TANGENT;
                    float2 texcoord : TEXCOORD0;
                };
                
                struct v2f_base
                {
                    float4 pos : SV_POSITION;
                    half2  uv : TEXCOORD0;
                    half4 tangentWorld : TEXCOORD1;
                    half4 normalWorld : TEXCOORD2;
                    half4 binormalWorld : TEXCOORD3;
                    UNITY_FOG_COORDS(5)
                };
    
                v2f_base vert(vertexIN_base v)
                {
                    v2f_base o;
                    o.pos = UnityObjectToClipPos(v.vertex);
                    o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    
                    o.tangentWorld.xyz = normalize(mul(unity_ObjectToWorld, half4(v.tangent.xyz, 0.0)).xyz);
                    o.normalWorld.xyz = normalize(mul(unity_ObjectToWorld, half4(v.normal, 0.0)).xyz);
                    o.binormalWorld.xyz = cross(o.normalWorld.xyz, o.tangentWorld.xyz) * v.tangent.w;
    
                    UNITY_TRANSFER_FOG(o,o.pos);
                    return o; 
                }
                
                fixed4 frag(v2f_base i) : COLOR
                {
                    float3 bump = UnpackNormal(tex2D(_BumpTex,TRANSFORM_TEX(i.uv, _BumpTex)));
                    half3x3 local2WorldTranspose = half3x3(i.tangentWorld.xyz, i.binormalWorld.xyz, i.normalWorld.xyz);
                    half3 worldNormal = normalize(mul(bump, local2WorldTranspose));
    
                    float diffuse = max(0, dot(normalize(worldNormal), normalize(_MainLightDir)));
    
                    fixed4 mainColor = tex2D(_MainTex, i.uv);
                    fixed4 clr = mainColor * _MainLightColor * diffuse * _MainLightBrightness;
    
                    UNITY_APPLY_FOG(i.fogCoord,clr);
    
                    return clr;
                }
                ENDCG
            }
        }
        FallBack Off
    }
  • 相关阅读:
    升级windows 11小工具
    windows 10更新升级方法
    您需要了解的有关 Oracle 数据库修补的所有信息
    Step by Step Apply Rolling PSU Patch In Oracle Database 12c RAC Environment
    Upgrade Oracle Database Manually from 12.2.0.1 to 19c
    如何应用版本更新 12.2.0.1.210420(补丁 32507738 – 2021 年 4 月 RU)
    xtrabackup 安装、备份和恢复
    Centos_Lvm expand capacity without restarting CentOS
    Centos_Lvm_Create pv vg lv and mount
    通过全备+relaylog同步恢复被drop的库或表
  • 原文地址:https://www.cnblogs.com/sifenkesi/p/9922889.html
Copyright © 2011-2022 走看看