https://github.com/keijiro/KinoFog

lighting box 2.7.2

halfspace fog 相机位于一个位置 这个位置可以在fog volumn里面或者外面  雾开始的地方就是文中的plane

http://www.terathon.com/lengyel/Lengyel-UnifiedFog.pdf

这个fog volume可以从中间某个位置height 这个平面产生雾 远近浓度通过depth深度计算

还可以定义雾密度

    // Applies one of standard fog formulas, given fog coordinate (i.e. distance)
half ComputeFogFactor (float coord)
{
float fogFac = 0.0;
if (_SceneFogMode.x == ) // linear
{
// factor = (end-z)/(end-start) = z * (-1/(end-start)) + (end/(end-start))
fogFac = coord * _SceneFogParams.z + _SceneFogParams.w;
}
if (_SceneFogMode.x == ) // exp
{
// factor = exp(-density*z)
fogFac = _SceneFogParams.y * coord; fogFac = exp2(-fogFac);
}
if (_SceneFogMode.x == ) // exp2
{
// factor = exp(-(density*z)^2)
fogFac = _SceneFogParams.x * coord; fogFac = exp2(-fogFac*fogFac);
}
return saturate(fogFac);
} // Distance-based fog
float ComputeDistance (float3 camDir, float zdepth)
{
float dist;
if (_SceneFogMode.y == )
dist = length(camDir);
else
dist = zdepth * _ProjectionParams.z;
// Built-in fog starts at near plane, so match that by
// subtracting the near value. Not a perfect approximation
// if near plane is very large, but good enough.
dist -= _ProjectionParams.y;
return dist;
} float ComputeHalfSpace (float3 wsDir)
{
float3 wpos = _CameraWS + wsDir;
float FH = _HeightParams.x;
float3 C = _CameraWS;
float3 V = wsDir;
float3 P = wpos;
float3 aV = _HeightParams.w * V;
float FdotC = _HeightParams.y;
float k = _HeightParams.z;
float FdotP = P.y-FH;
float FdotV = wsDir.y;
float c1 = k * (FdotP + FdotC);
float c2 = (-*k) * FdotP;
float g = min(c2, 0.0);
g = -length(aV) * (c1 - g * g / abs(FdotV+1.0e-5f));
return g;
}

FdocC = camPos.y-height.value;      height  就是halfplane所定义的高度 plane法线垂直向上

       // Calculate vectors towards frustum corners.
var cam = GetComponent<Camera>();
var camtr = cam.transform;
var camNear = cam.nearClipPlane;
var camFar = cam.farClipPlane; var tanHalfFov = Mathf.Tan(cam.fieldOfView * Mathf.Deg2Rad / );
var toRight = camtr.right * camNear * tanHalfFov * cam.aspect;
var toTop = camtr.up * camNear * tanHalfFov; var v_tl = camtr.forward * camNear - toRight + toTop;
var v_tr = camtr.forward * camNear + toRight + toTop;
var v_br = camtr.forward * camNear + toRight - toTop;
var v_bl = camtr.forward * camNear - toRight - toTop; var v_s = v_tl.magnitude * camFar / camNear; // Draw screen quad.
RenderTexture.active = destination; _material.SetTexture("_MainTex", source);
_material.SetPass(); GL.PushMatrix();
GL.LoadOrtho();
GL.Begin(GL.QUADS); GL.MultiTexCoord2(, , );
GL.MultiTexCoord(, v_bl.normalized * v_s);
GL.Vertex3(, , 0.1f); GL.MultiTexCoord2(, , );
GL.MultiTexCoord(, v_br.normalized * v_s);
GL.Vertex3(, , 0.1f); GL.MultiTexCoord2(, , );
GL.MultiTexCoord(, v_tr.normalized * v_s);
GL.Vertex3(, , 0.1f); GL.MultiTexCoord2(, , );
GL.MultiTexCoord(, v_tl.normalized * v_s);
GL.Vertex3(, , 0.1f); GL.End();
GL.PopMatrix();

这里是用了一个quard我做到用trangle了

要铭记一点 quard 和trangle的插值结果 顶多数据传对了 插值是一样的 没有差别 因为都是线性的 这个问题我想了好几个小时!

uv 和pos肯定是一样的 dir也是一样的 因为也是线性的

这意味着我接下来可以做大面积优化了 好开心

mg你太棒了 这个小故事告诉我们代码要每一行都看懂 不要再像黑盒那样抄了

Vector3 topLeft3 = topLeft*2-bottomLeft;//2

Vector3 bottomRight3 = bottomRight*2 -bottomLeft;//1

Vector3 topRight3= bottomRight3+topLetf3;//0

这里因为scale过到farplane不能在原始那个nearplane的数据直接3x

体积雾 global fog unity 及改进的更多相关文章

  1. [原]Unity3D深入浅出 - 雾效(Fog)

    在Unity中开启雾效的方式:依次选中菜单栏中的 Edit - Render Settings 项,勾选Fog 选框即可开启雾效.雾效的参数如下: Fog Color:雾的颜色. Fog Mode:雾 ...

  2. 【Unity Shaders】Unity里的雾效模拟

    写在前面 熟悉Unity的都知道,Unity可以进行基本的雾效模拟.所谓雾效,就是在远离我们视角的方向上,物体看起来像被蒙上了某种颜色(通常是灰色).这种技术的实现实际上非常简单,就是根据物体距离摄像 ...

  3. 关于Unity中水和雾的使用

    水 自己来做水和雾还是有点麻烦的,不过没关系,Unity帮我们做好了很多可以用的. 1.Unity自己实现了水的特效,帮助我们解决游戏中水的问题 2.Unity的水集成在了Environment的环境 ...

  4. Unity 性能优化(力荐)

    开始之前先分享几款性能优化的插件: 1.SimpleLOD : 除了同样拥有Mesh Baker所具有的Mesh合并.Atlas烘焙等功能,它还能提供Mesh的简化,并对动态蒙皮网格进行了很好的支持. ...

  5. 基于预计算的全局光照(Global Illumination Based On Precomputation)

    目录 基于图像的光照(Image Based Lighting,IBL) The Split Sum Approximation 过滤环境贴图 预计算BRDF积分 预计算辐射度传输(Precomput ...

  6. Unity 几种优化建议

    转: http://user.qzone.qq.com/289422269/blog/1453815561?ptlang=2052 Unity 几种优化建议 最简单的优化建议: 1.PC平台的话保持场 ...

  7. [Unity优化] Unity CPU性能优化

    前段时间本人转战unity手游,由于作者(Chwen)之前参与端游开发,有些端游的经验可以直接移植到手游,比如项目框架架构.代码设计.部分性能分析,而对于移动终端而言,CPU.内存.显卡甚至电池等硬件 ...

  8. Unity Awards 2018最佳资源

    好的工具与资源,将帮助你的开发,达到事办功倍,今天我们将为大家介绍荣获Unity Awards 2018最佳资源的获奖作品. 最佳艺术工具:Aura - Volumetric Lighting Aur ...

  9. Unity Shader 基础(4) 由深度纹理重建坐标

    在PostImage中经常会用到物体本身的位置信息,但是Image Effect自身是不包含这些信息的,因为屏幕后处其实是使用特定的材质渲染一个刚好填满屏幕的四边形面片(四个角对应近剪裁面的四个角). ...

随机推荐

  1. hadoop3.1集成yarn ha

    1.角色分配

  2. Two Sum ——经典的哈希表的题

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  3. [转载]Python命令行参数学习

    转载自: http://blog.163.com/weak_time/blog/static/25852809120169333247925/ Python的命令行参数,提供了很多有用的功能,可以方便 ...

  4. AC日记——[Sdoi2010]粟粟的书架 bzoj 1926

    1926 思路: 主席树+二分水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 500005 #defi ...

  5. LR运行场景时出现的error

    LR运行场景时出现的error 1.Action.c(24): Error -27740: Overlapped transmission of request to "home.asiai ...

  6. bzoj 1407 扩展欧几里德

    思路:枚举洞穴个数,用扩展欧几里德暴力判断没两个人的周期. #include<bits/stdc++.h> #define LL long long #define fi first #d ...

  7. 四十四 常用内建模块 struct

    准确地讲,Python没有专门处理字节的数据类型.但由于str既是字符串,又可以表示字节,所以,字节数组=str.而在C语言中,我们可以很方便地用struct.union来处理字节,以及字节和int, ...

  8. python中,将字符串由utf8转gbk

    uni_str = utf8_str.decode('utf-8'); gbk_str = uni_str.encode('gbk');

  9. 【Bzoj3527】【Luogu3338】[Zjoi2014]力(FFT)

    题面 Bzoj Luogu 题解 先来颓柿子 $$ F_i=\sum_{j<i}\frac{q_iq_j}{(i-j)^2}-\sum_{j>i}\frac{q_iq_j}{(i-j)^2 ...

  10. leetcode155 Min Stack

    题意:模拟一个最小栈,可以push,pop,top,和返回栈中最小值. 思路:已经忘了栈是怎么构建的了,晕···尝试了半天,错误,发现直接用stack数据结构来做最方便,再用一个栈来存最小值.值得注意 ...