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

去掉环境光照和全局雾,添加自己的环境光又利用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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值