首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Unity3D安卓系统中使用点灯

在Unity3D安卓系统中使用点灯
EN

Stack Overflow用户
提问于 2014-08-18 14:35:48
回答 1查看 2.1K关注 0票数 1

我正在尝试使用点光动画作为我的游戏。它运行良好的编辑器与漫射,碰撞光谱和VertexLit着色器。但是,默认情况下,它不适用于任何移动着色器。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-18 16:15:40

终于找到了答案-- 这个职位 on UnityAnswer帮助了我。我要在这里重贴自定义着色器-

代码语言:javascript
复制
// 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

不过,记得要增加力量。而且很明显,这在帧速率上太昂贵了。我只需要一个动画,所以我就用它了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25365910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档