您的位置:首页 > 其它

U3D Shader去掉全局雾和使用自定义环境光

2017-10-06 14:41 134 查看
去掉环境光照和全局雾,添加自己的环境光又利用surface的shader光照和阴影
全局雾用nofog去掉,noambient去掉,注掉UNITY_LIGHT_FUNCTION_APPLY_INDIRECT添加自己的环境光
inline fixed4 LightingU1BlinnPhong (SurfaceOutput s, fixed3 viewDir, UnityGI gi)
{
fixed4 c;

c = U1BlinnPhongLight (s, viewDir, gi.light); // main light only 1

//#ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT
//c.rgb += s.Albedo * gi.indirect.diffuse;
//#endif
c.rgb += s.Albedo * _AmbientColor;

c.a = s.Alpha;

return c;
}

利用阴影还要其他的函数,例如:
#ifndef U1_OBJ_STD_LIGHT_CGINC
#define U1_OBJ_STD_LIGHT_CGINC

// -------------------------- lamber blinn -----------------------------
inline fixed4 U1LambertLight (SurfaceOutput s, fixed3 lightColor, fixed3 lightDir)
{
fixed diff = max (0, dot (s.Normal, lightDir));

fixed4 c;
c.rgb = s.Albedo * lightColor * diff;
return c;
}

inline fixed4 U1BlinnPhongLight (SurfaceOutput s, fixed3 viewDir, UnityLight light)
{
fixed diff = max (0, dot (s.Normal, light.dir));
fixed4 c;
c.rgb = s.Albedo * light.color * diff; // diffuse

#if !defined(GSE_SHADER_LOW)
//float nh = max (0.1, dot (s.Normal, h));
fixed3 h = Unity_SafeNormalize (light.dir + viewDir);
float nh = max (0.0, dot (s.Normal, h));
float spec = min(pow (nh, s.Specular*128.0), (1 - s.Specular)*1.2); // max = 1.0 to avoid flick effect when object is small
//c.rgb *= 1 + s.Emission.r; // emission, no need to calculate here
c.rgb += light.color * _SpecColor.rgb * spec; // specular
#endif

c.a = s.Alpha;

return c;
}

inline fixed4 LightingU1BlinnPhong (SurfaceOutput s, fixed3 viewDir, UnityGI gi)
{
fixed4 c;

c = U1BlinnPhongLight (s, viewDir, gi.light); // main light only 1

//#ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT
//c.rgb += s.Albedo * gi.indirect.diffuse;
//#endif
c.rgb += s.Albedo * _AmbientColor;

c.a = s.Alpha;

return c;
}

inline void LightingU1BlinnPhong_GI (
SurfaceOutput s,
UnityGIInput data,
inout UnityGI gi)
{
gi = UnityGlobalIllumination (data, 1.0, s.Normal);
}

inline half4 LightingU1BlinnPhong_Deferred (SurfaceOutput s, half3 viewDir, UnityGI gi, out half4 outDiffuseOcclusion, out half4 outSpecSmoothness, out half4 outNormal)
{
outDiffuseOcclusion = half4(s.Albedo, 1);
outSpecSmoothness = half4(_SpecColor.rgb, s.Specular);
outNormal = half4(s.Normal * 0.5 + 0.5, 1);
half4 emission = half4(s.Emission, 1);

#ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT
emission.rgb += s.Albedo * gi.indirect.diffuse;
#endif

return emission;
}

inline fixed4 LightingU1BlinnPhong_PrePass (SurfaceOutput s, half4 light)
{
fixed spec = light.a * s.Gloss;

fixed4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * spec);
c.a = s.Alpha;
return c;
}

#endif
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐