http://www.michaelwalczyk.com/blog/2017/5/25/ray-marching

https://kosmonautblog.wordpress.com/2017/05/01/signed-distance-field-rendering-journey-pt-1/

http://martindevans.me/game-development/2016/12/27/Dual-Contouring-In-2D/

https://static1.squarespace.com/static/559921a3e4b02c1d7480f8f4/t/596773e9f7e0ab3d29bb102f/1499952110561/Mroz+Michael_746.pdf

这篇硕士论文比较详细 很难找

sdf是个函数 input 是一个point output是离这个点最近的任意表面的距离 如果在surface内部是负数

存在3dtexture里面

raymarching distance field是个后处理

要了解sdf需要几个依赖

1.sdf func 下面是个球的例子
// params:
// p: arbitrary point in 3D space
// c: the center of our sphere
// r: the radius of our sphere
float distance_from_sphere(in vec3 p, in vec3 c, float r)
{
return length(p - c) - r;
} 2.ray marching(sphere tracing)
view 到 light 直线上 按照起始点(view)为圆心 起始点存的distance值为半径做圆 同样的方式迭代一直到到达light 如果能到达的话(也就是说空间的任何一个点都存有distance了)
3.mesh distance field 如何得到 用1里面的基本图元合起来的 合的方式也是各种各样
下面这个是暴力算法
Foreach GridCell in DistanceFieldGrid: 
Foreach Triangle in Mesh:
   Find distance from Triangle to GridCell, save the closest one
(从上面这段也可以推知场景空间每个cell都存了距离)
ue4是这个算法用cpu 可以用kd-tree优化
也可以用gpu computeshader来算 mTec 心情真的很不好呢
http://flafla2.github.io/2016/10/01/raymarching.html
===============================================================
fixed4 raymarch(float3 ro, float3 rd) {
fixed4 ret = fixed4(0,0,0,0); const int maxstep = 64;
float t = 0; // current distance traveled along ray
for (int i = 0; i < maxstep; ++i) {
float3 p = ro + rd * t; // World space position of sample
float d = map(p); // Sample of distance field (see map()) // If the sample <= 0, we have hit something (see map()).
if (d < 0.001) {
// Lambertian Lighting
float3 n = calcNormal(p);
ret = fixed4(dot(-_LightDir.xyz, n).rrr, 1);
break;
} // If the sample > 0, we haven't hit anything yet so we should march forward
// We step forward by distance d, because d is the minimum distance possible to intersect
// an object (see map()).
t += d;
}
return ret;
}
fixed4 frag (v2f i) : SV_Target
{
// ray direction
float3 rd = normalize(i.ray.xyz);
// ray origin (camera position)
float3 ro = _CameraWS; fixed3 col = tex2D(_MainTex,i.uv); // Color of the scene before this shader was run
fixed4 add = raymarch(ro, rd); // Returns final color using alpha blending
return fixed4(col*(1.0 - add.w) + add.xyz * add.w,1.0);
}

做光照的

{

for (int i = 0; i<maxSteps; i++)
{
float S = GetSdfDistNoSun(P,radius,cullIndex);
//float S = combinedSDFNoSun(P);
closestPass = min(closestPass, (multiplier*S / radius));
//radius+=S;
// radius+= max( S, 0.02);
radius += clamp(S, 0.02, 0.1);
dist += max(minS, S);
P += d*max(minS, S);
steps = i;
if (dist >= lightDist || dist>maxDist ) {
break;
}

if(S < cutoff)
{
closestPass =0.0;
break;
}
}
}

return clamp(closestPass, 0, 1);
}

==

softshadow的 迭代多次lightmarch的距离dist 如果能到达light 不形成阴影

如果大于maxDist也不形成阴影意思是当前点50以外到light方向都无遮挡也不形成阴影

sdf<cutoff 内部不形成阴影

soft这部分用这个min(closestPass, (multiplier*S / radius))

=================================================================

ao

 
 

raymarching的更多相关文章

  1. Houdini SDF/Raymarching/等高曲面绘制

    1 , SDF <1> union  min(a,b) <2> intersect: max(a,b) <3> Substract  a-b  : if(b> ...

  2. Unity Shader-GodRay,体积光(BillBoard,Volume Shadow,Raidal Blur,Ray-Marching)

    好久没有更新博客了,经历了不少事情,好在最近回归了一点正轨,决定继续Unity Shader的学习之路.作为回归的第一篇,来玩一个比较酷炫的效果(当然废话也比较多),一般称之为GodRay(圣光),也 ...

  3. 光线步进——RayMarching入门

    入门实现 先用RayMarching描绘一个球体,最后在进行光照计算参考:https://www.shadertoy.com/view/llt3R4 模拟摄像机射线float3 rayDirectio ...

  4. Grand Theft Auto V (侠盗列车手5)图形研究

    原文地址:http://www.adriancourreges.com/blog/2015/11/02/gta-v-graphics-study/   原文的简介: GTA(侠盗猎车)系列自从1997 ...

  5. 【Unity Shader】2D动态云彩

    写在前面 赶在年前写一篇文章.之前翻看2015年的SIGGRAPH Course(关于渲染的可以去selfshadow的博客里找到,很全)的时候看到了关于体积云的渲染.这个课程讲述了开发者为游戏< ...

  6. 【ShaderToy】开篇

    写在前面 呜呼,好久没有写博客了,好惭愧.题外话,感觉越大就越想家,希望可以一直和家人在一起,哪怕只是坐在一起不说话也觉得很温暖,一想到要分开眼睛就开始酸,哎.开学还是爬上来老实更新博客学习吧~ 今天 ...

  7. Signed Distance Field Shadow in Unity

    0x00 前言 最近读到了一个今年GDC上很棒的分享,是Sebastian Aaltonen带来的利用Ray-tracing实现一些有趣的效果的分享. 其中有一段他介绍到了对Signed Distan ...

  8. 在UnrealEngine中用Custom节点实现毛玻璃的效果

    本人在论坛上找到了一篇实现毛玻璃效果的文章:https://forums.unrealengine.com/showthread.php?70143-So-Blurred-glass-material ...

  9. How to use the Custom Material node and create Metaballs 官方视频学习笔记

    这个视频Youtube没有字幕着实蛋疼,本人英语很渣,几乎听不懂,里面有很多文档没讲的重要信息(文档讲的东西太少了). 不过学习过后你可以解锁好几个姿势.这个视频主要是教你做DistanceField ...

随机推荐

  1. Commons CLI 学习(1)

    The Apache Commons CLI library provides an API for parsing command line options passed to programs. ...

  2. Factorial Trailing Zeroes——数学类

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  3. Jmeter-----随机生成手机号后8位并去重,来进行注册手机号的压测

    要求:对注册接口进行100000次压测,手机号已126开头,后面的8位数不限 前言:在进行测试中,我们需要对注册接口进行压测100000次,那么就要求手机号码每次填写的不一致,否则手机号使用一次后会出 ...

  4. 【转】kubernetes 中 deployment 支持哪些键值

    这个比较全,可以参考 ================= https://www.addops.cn/post/kubernetes-deployment-fileds.html ========== ...

  5. AC日记——「SCOI2015」情报传递 LiBreOJ 2011

    #2011. 「SCOI2015」情报传递 思路: 可持久化树状数组模板: 代码: #include <bits/stdc++.h> using namespace std; #defin ...

  6. jstree无限级菜单ajax按需动态加载子节点

    业余时间研究了一下jstree,更新非常快已经是3.0了,首先看一下效果截图: 1.页面引入样式和脚本(注意路径根据实际情况) <link href="~/Scripts/vakata ...

  7. 对angular.js的一点理解

    最近一直在学习angular.js.不得不说和jquery相比有很大不同,有很多的不同点,之前也用过Knockout.js 但是两者还是有一定的区别的,首先knockout.js是基于Mvvm的,是几 ...

  8. CentOS6.5修改/etc/pam.d/sshd后root无法ssh登陆

    现象:由于公司需要服务器的登陆操作进行安全加固,同事为了省事,直接把CentOS7上的/etc/pam.d/sshd替换掉CentOS6.5上的/etc/pam.d/sshd,导致root用户ssh登 ...

  9. CentOS7.5安装配置conky(极简)

    1.安装epel源 下载地址:http://dl.fedoraproject.org/pub/epel/ 找到epel-release-XXXXXXX.rpm文件,下载解压 rpm -ivh epel ...

  10. Struts2 + Hibernate3.3 开发简单的登录注册功能【J2EE】

    开发环境: IDE:Myeclipse10.0 数据库:Oracle(SQL Developer) Web容器:Tomcat 7.0 JDK:1.6 Struts:2.0 Hibernate:3.3 ...