unity 不受光照影响物体什么情况下不受全局雾影响

求大神解惑,场景中有些物体没有受到雾效果的影响,怎么解决呢?【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:70,154贴子:
求大神解惑,场景中有些物体没有受到雾效果的影响,怎么解决呢?收藏
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或貌似说偏了,假设预制里面,有个脚本,中可以设置一个全局的变量。那么会出现这种情况。-Unity3D-论坛-U3D在线
Unity3D在线
当前位置: ->
-> 貌似说偏了,假设预制里面,有个脚本,中可以设置一个全局的变量。那么会出现这种情况。
Unity3D 论坛 > 貌似说偏了,假设预制里面,有个脚本,中可以设置一个全局的变量。那么会出现这种情况。围观:751 | 回复:22
免责声明:本站所有内容来源于互联网,如果本站部分内容侵犯您的权益,请您告知,站长会立即处理
Copyright Unity3D在线 All Rights Reserved.Theme by U3dOL 备案:京ICP备号-4 |SiteMap |网站地图 |百度统计| 联系我们Unity 体积雾 Shader
精华热门加亮
全局雾很简单,在unity里只需要一个选项即可,可是它不能控制局部地区的雾化效果。所以有”Volume Fog”这种shader,网上搜了很久,只有一个比较满意:,可是要卖50刀(站长看看有没有意愿团一个?~~)算了,自己动手,再次硬着头皮上了,为此我还狠心买了《GPU Gems》全套,既然目前我都在研究游戏里的特效实现,不光是粒子系统,shader也是重要的组成部分,所以我决定以后也会在Xffect里多包含一些实用的shader,比如这次分享的Volume Fog。还有很早前就包含的“Heat Distortion”(热浪?)shader,这个是非常实用的,因为很多特效都有局部画面扭曲效果。下面放2张截图,目前的体积雾只支持球体。在fog外面看到的效果:726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/Mon_9_f575b82e0d12d53.jpg');" />在fog里面看到的效果:726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/Mon_9_f89c7ad414ee9c6.jpg');" />我的游戏项目里用到的效果:726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/Mon_9_023f45b97dc5aac.jpg');" />726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/Mon_9_7a43ec5e02b1939.jpg');" />=================================================================好了,放上shader代码,需要注意的是,该shader需要开启DepthTextureMode,如果是deffered lightning则不需要手动开启,Forward lightning需要手动开启:“Camera.main.depthTextureMode = DepthTextureMode.D”另外,需要外部传送FogParam参数,FogParam.xyz代表Sphere center, FogParam.z 代表sphere radius,所以该shader不能独立使用,需要配合简单的脚本,脚本我就不放上了,不过我会在Xffect 1.2.3版本里加入完整的例子,包括免费版。///threads/142245-Xffect-Editor-Pro-powerful-tool-to-create-amazing-effects!
Shader &Xffect/volume_fog& {
Properties {
_FogColor (&Fog Color&, Color) = (1,1,1,1)
Category {
Tags { &Queue&=&Transparent+99& &IgnoreProjector&=&True& &RenderType&=&Transparent& }
Blend SrcAlpha OneMinusSrcAlpha
Cull Off Lighting Off ZWrite Off
ZTest Always
SubShader {
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include &UnityCG.cginc&
float CalcVolumeFogIntensity(float3 sphereCenter, float sphereRadius, float3 cameraPosition, float3 viewDirection, float backDepth, float maxDistance, float density)
float3 local = cameraPosition - sphereC
= dot(viewDirection, viewDirection);
= 2 * dot(viewDirection, local);
= dot(local, local) - sphereRadius * sphereR
= fB * fB - 4 * fA * fC;
if ( fD & 0.0f )
float recpTwoA = 0.5 / fA;
if (fD == 0.0f)
dist = backD
float DSqrt = sqrt(fD);
dist = (-fB - DSqrt) * recpTwoA;
dist = min(dist, maxDistance);
backDepth = min(backDepth, maxDistance);
float sample =
float fog = 0;
float step_distance = ( backDepth - dist ) / 10;
for ( int seg = 0; seg & 10; seg++ )
float3 position = cameraPosition + viewDirection *
fog += 1 - saturate( length( sphereCenter - position ) / sphereRadius );
sample += step_
fog /= 10;
= saturate( fog * density );
fixed4 _FogC
sampler2D _CameraDepthT
uniform float4 FogP
struct v2f {
float4 pos : SV_POSITION;
float3 view : TEXCOORD0;
float4 projPos : TEXCOORD1;
v2f vert (appdata_base v)
float4 wPos = mul (_Object2World, v.vertex);
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.view = wPos.xyz - _WorldSpaceCameraP
o.projPos = ComputeScreenPos (o.pos);
// move projected z to near plane if point is behind near plane
float inFrontOf = ( o.pos.z / o.pos.w ) & 0;
o.pos.z *= inFrontOf;
half4 frag (v2f i) : COLOR
half4 color = half4(1,1,1,1);
float depth = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
float backDist = length(i.view);
float3 viewDir = normalize(i.view);
float fog = CalcVolumeFogIntensity(FogParam.xyz, FogParam.w, _WorldSpaceCameraPos, viewDir, backDist, depth,_FogColor.a);
color.rgb = _FogColor.
Fallback &VertexLit&
要评论请先&或者&
& 我对楼主的崇拜犹如滔滔江水连绵不断。 && &楼主又做独立游戏,又开发特效插件,还会shaderLab,真是大牛啊。&& &你开发的游戏DEMO我下载来玩了(救公主那个)。虽然游戏还不完整,但是还挺不错。让我想起了小学的时候玩的一款游戏叫“炎龙骑士团”。挺喜欢那种策略类的~希望你的独立开发道路能越走越宽。&& &XFFECT插件我也购买了,但是在U3D3.4版本下面运行不了,说代码编译没通过。请问楼主QQ是多少啊?PS:你的头像好可爱啊~~出自哪里啊? &
感谢分享基本上也在辛苦的研究各种Shader效果,这方面资料确实比较少,自己总结
滔滔江水~~~~~~~~~~
: 我对楼主的崇拜犹如滔滔江水连绵不断。
楼主又做独立游戏,又开发特效插件,还会shaderLab,真是大牛啊。
你开发的游戏DEMO我下载来玩了(救公主那 .. ( 17:50) 。。。谢谢。。目前Xffect是我唯一的收入来源,所以更新也比较勤了,相对而言游戏的开发进度放慢很多了。嘿嘿,我开发的战棋策略类游戏结合了RPG冒险模式,所以还是有创新的,只是做出成品可能得猴年马月了。因为我是用3.5版本做出来的,所以Xffect只支持3.5以上版本。国内团购插件这点应该特别注意。。(我刚发现站长在团购区居然还没有标注每个插件所需要的unity最低版本!。。)其他事情可先与我邮件联系。另外,头像出自RO里某个怪物卡片。。
不知道lz的这些shader在ios上能不能使用?
膜拜下……
犀利啊,捧个场
这个可以收,先收藏了,谢谢分享~~~
游戏好有伊苏的风格!日系feel大赞!

我要回帖

更多关于 unity3d 全局脚本 的文章

 

随机推荐