找回密码
 立即注册
楼主: 偷腥的喵丶

[Shader] Shader材质上传到ios后效果跟编辑不一样。求帮助

[复制链接]
发表于 2015-10-23 18:22 | 显示全部楼层 |阅读模式
不知道是否PC品台跟ios的运算方式不一样,所以造成在电脑上编辑的材质上传到ipad后显示的效果不一样。然后发现应该是这个各向异性的高光不知道应该要怎样写才能在ios也能达到跟电脑的效果一样。下面是源码,请各位大大帮忙看看,帮忙解决解决。谢谢

Shader "Wshader/XGQML" {
    Properties {
        //添加属性;
        _MainTint("Diffuse Tint",Color)=(1,1,1,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _SpecularColor("Specular Color",Color)=(1,1,1,1)
        _SpecPower("Specular Power", Range(0.1,1))=0.5
        _Specular("Specular Amount",Range(0.1,1))=0.5
        _AnisoDir("Aniso Image",2D)=""{}
        _AnisoOffset("Aniso Offset",Range(-1,1))=0.5
        _MaskMap("Reflect (R) Glossiness (G)", 2D) = "white" {}
        _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
        _Cube ("Cubemap", CUBE) = "" {}
        _ReflAmount("Reflection Amount",Range(0,1)) =0.5
        _RimTex("Rim Tex" ,2D)="white"{}
        _RimColor("Rim Color" , Color)=(0.26,0.19,0.16,0.0)
        _RimPower("Rim Power",Range(0,20.0))=3.0
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf AnisoPhong
        #pragma target 3.0
        //设置变量;
        sampler2D _MainTex;
        sampler2D _AnisoDir;
        float4 _MainTint;
        float4 _SpecularColor;
        float _AnisoOffset;
        float _SpecPower;
        float _Specular;
        float4 _ReflectColor;
        samplerCUBE _Cube;
        float _ReflAmount;
        sampler2D _MaskMap;
        float4 _RimColor;
        float _RimPower;
        sampler2D _RimTex;


        struct Input {
            float2 uv_MainTex;
            float2 uv_AnisoDir;
            float2 uv_MaskMap;
            float3 worldRefl;
            float3 viewDir;
            float2 uv_RimTex;
        };
        //自定义输出结构体;
        struct SurfaceAnisoOutput
        {
            fixed3 Albedo;
            fixed3 Normal;
            fixed3 Emission;
            fixed3 AnisoDirection;
            half Specular;
            fixed Gloss;
            fixed Alpha;


        };
        //自定义光照模型;
        inline fixed4 LightingAnisoPhong(SurfaceAnisoOutput s,fixed3 lightDir,half3 viewDir, fixed atten){
            fixed3 halfVector = normalize(normalize(lightDir)+normalize(viewDir));
            float NdotL = saturate( dot(s.Normal,lightDir) );

            fixed HdotA = dot(normalize(s.Normal+s.AnisoDirection),halfVector);
            float aniso = max(0,sin(radians(HdotA+_AnisoOffset)*180));

            float spec = saturate(pow(aniso,s.Gloss*50)*s.Specular);

            fixed4 c;
            c.rgb = (s.Albedo * _LightColor0.rgb*NdotL)+(_LightColor0.rgb * _SpecularColor.rgb*spec)*(atten*2);
            c.a=1;
            return c;
        }

        void surf (Input IN, inout SurfaceAnisoOutput o) {

             half rim = saturate(dot(normalize(IN.viewDir),o.Normal));
             half4 r = tex2D (_RimTex, IN.uv_RimTex)*_RimColor;

             //half rim = 1.0-saturate(dot(normalize(IN.viewDir),o.Normal));
        //o.Emission =_RimColor.rgb*pow(rim,_RimPower);

            half4 c = tex2D (_MainTex, IN.uv_MainTex)*_MainTint;
            float3 anisoTex = UnpackNormal(tex2D(_AnisoDir,IN.uv_AnisoDir));
            o.AnisoDirection = anisoTex;
            o.Specular = _Specular;
            o.Gloss = _SpecPower;
            o.Albedo = c.rgb+r.rgb*30*pow(rim,_RimPower);
            o.Alpha = c.a;

            half4 d = tex2D(_MaskMap, IN.uv_MaskMap);
            _SpecPower = _SpecPower * _SpecPower * 0.111111 * d.g;

            o.Emission =texCUBE(_Cube,IN.worldRefl).rgb*_ReflectColor*_ReflAmount*d.rgb*2;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
 楼主| 发表于 2015-10-23 18:23 | 显示全部楼层
求大神帮忙看看应该要怎样改。感谢感谢啊
发表于 2017-2-23 18:24 | 显示全部楼层
很不错
发表于 2017-2-23 17:45 | 显示全部楼层
楼主是超人
发表于 2017-2-23 18:06 | 显示全部楼层
顶顶多好
发表于 2017-2-23 18:23 | 显示全部楼层
真心顶
发表于 2017-2-23 17:40 | 显示全部楼层
难得一见的好帖
发表于 2017-3-21 10:51 | 显示全部楼层
很不错
发表于 2017-3-21 10:39 | 显示全部楼层
楼主是超人
发表于 2017-3-21 10:18 | 显示全部楼层
好帖就是要顶
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-4 01:39 , Processed in 0.105166 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表