【问题标题】:Using Point lights in Unity3D Android在 Unity3D Android 中使用点光源
【发布时间】:2014-08-19 00:15:40
【问题描述】:

我正在尝试为我的游戏使用点光源动画。它在带有 Diffuse、Bumped Specular 和 VertexLit 着色器的编辑器中运行良好。但是它不适用于默认提供的任何移动着色器。

有没有办法在 Android 中使用点光源?或者是否有任何着色器可以在手机上工作并且也支持点光源?

【问题讨论】:

    标签: android unity3d lighting


    【解决方案1】:

    终于找到了答案——UnityAnswer 上的this post 帮助了我。我在这里重新发布自定义着色器 -

    // Specular, Normal Maps with Main Texture
    // Fragment based
    Shader "SpecTest/SpecTest5" 
    {
        Properties 
        {
            _Shininess ("Shininess", Range (0, 1.5)) = 0.078125
            _Color ("Main Color", Color) = (1,1,1,1)
            _SpecColor ("Specular Color", Color) = (0, 0, 0, 0)
            _MainTex ("Texture", 2D) = "white" {}
            _BumpMap ("Bump Map", 2D) = "bump" {}
            _NormalStrength ("Normal Strength", Range (0, 1.5)) = 1
        } // eo Properties
        SubShader 
        {
            // pass for 4 vertex lights, ambient light & first pixel light
            Tags { "RenderType"="Opaque" }
            LOD 200
    
            CGPROGRAM
            #pragma surface surf MobileBlinnPhong
    
            fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
            {
                fixed diff = saturate(dot (s.Normal, lightDir));
                fixed nh = saturate(dot (s.Normal, halfDir)); //Instead of injecting the normalized light+view, we just inject view, which is provided as halfasview in the initial surface shader CG parameters
    
                fixed spec = pow (nh, s.Specular*128) * s.Gloss;
    
                fixed4 c;
                c.rgb = (s.Albedo * _LightColor0.rgb * diff + _SpecColor.rgb * spec) * (atten*2);
                c.a = 0.0;
                return c;
            }
    
            struct Input {
                float2 uv_MainTex;
                float2 uv_BumpMap;
            };
    
            // User-specified properties
            uniform sampler2D _MainTex;
            uniform sampler2D _BumpMap;
            uniform float _Shininess;
            uniform float _NormalStrength;
            uniform fixed4 _Color;      
    
            float3 expand(float3 v) { return (v - 0.5) * 2; } // eo expand 
    
            void surf (Input IN, inout SurfaceOutput o) {
                half4 tex = tex2D (_MainTex, IN.uv_MainTex) * _Color;
                   o.Albedo = tex.rgb;
                   o.Gloss = tex.a;
                   o.Alpha = tex.a;
                   o.Specular = _Shininess;
    
                // fetch and expand range-compressed normal
                float3 normalTex = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
                float3 normal = normalTex * _NormalStrength;
                o.Normal = normal;
            } // eo surf
    
            ENDCG
        } 
            //Fallback "Specular"
      } // eo Shader
    

    记得增加力量。显然它在帧速率上的成本太高了。我只是一个动画需要它,所以我用它。

    【讨论】:

    • @pglynn 我不能再等 8 小时 :-(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    相关资源
    最近更新 更多