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
全局雾用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
相关文章推荐
- 使用 EffectCustomTool 为 Xna 创建自定义 Shader 特效
- VisualStudio2008环境下,使用WebPart实现自定义页面布局
- VC++6.0环境下,使用传引用方式调用自定义的swap函数来达到两数交换的目的
- linux用户覆盖全局(自定义)变量环境
- Cocosd-x随记--在Xcode环境下,Cocos2d-x使用自定义字体
- linux用户覆盖全局(自定义)变量环境
- VisualStudio2008环境下,使用WebPart实现自定义页面布局
- Bigcommerce: 给模板添加一个自定义的产品属性,使用$GLOBALS全局变量调用
- 使用sencha touch cmd 4.0 创建项目、打包(加入全局变量、公用类、自定义扩展、资源文件)
- 如何在VS2013+QT5.3环境下使用自定义信号与槽函数
- Android 自定义View修炼-Android实现圆形、圆角和椭圆自定义图片View(使用BitmapShader图形渲染方法)
- 安卓之全局变量在自定义类里的使用
- unity中使用自定义shader进行光照贴图烘培无法出现透明度的坑爹问题
- 使用PopupWindow实现全局自定义menu
- xna中使用自定义的shader来绘制model
- Cocos2d-x项目移植到WP8系列之九:使用自定义shader
- 使用 EffectCustomTool 为 Xna 创建自定义 Shader 特效(二)
- 第一步 使用sencha touch cmd 4.0 创建项目、打包(加入全局变量、公用类、自定义扩展、资源文件)
- 如何在基于MFC的环境中使用自定义消息函数?
- 空帐号的问题(vmware环境中,使用sysprep自定义系统后,登录的时候发现administrator帐号被禁用了)