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. MapReduce案例一:天气温度

    1.需求 2.思路 3.代码实现 3.1MyWeather 类代码: 这个类主要是用来定义hadoop的配置,在执行计算程序时所需加载的一些类. package com.hadoop.mr.weath ...

  2. Word Search——经典题(还没细看)

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  3. 图论&双连通分量&强联通分量&2-SAT

    图论入门费: 数据小,大胆的写 https://vjudge.net/problem/UVA-10047 入门费 https://vjudge.net/problem/UVA-11624 思维,建图异 ...

  4. 洛谷——P1920 成功密码

    P1920 成功密码 题目描述 void_rank匪别人的书来看,原本想看杂志颓废的,结果不小心拿错拿成了被导师称作旁门左道的高中数学杂志<成功密码>.数学差得不行的void_rank实在 ...

  5. 计蒜客 UCloud 的安全秘钥(困难)(哈希)

    UCloud 的安全秘钥(困难) 编辑代码 9.53% 1200ms 262144K 每个 UCloud 用户会构造一个由数字序列组成的秘钥,用于对服务器进行各种操作.作为一家安全可信的云计算平台,秘 ...

  6. Linux命令之find(二)

    接上一篇Linux命令之find(一) (1).实例 1.列出当前目录下及子目录下所有的.txt文件 [xf@xuexi ~]$ ls 1.txt 3.txt b.txt 公共 视频 文档 音乐 2. ...

  7. BZOJ 2288 【POJ Challenge】生日礼物(贪心+优先队列)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2288 [题目大意] 给出一列数,求最多取m段连续的数字,使得总和最大 [题解] 首先我 ...

  8. 【推导】【构造】Petrozavodsk Summer Training Camp 2015 Day 2: Xudyh (TooSimple) Contest, Saturday, August 22, 2015 Problem G. Travelling Salesman Problem

    一个矩阵,每个位置有一个非负整数,一个人从左上走到右下,不能走重复的格子,问得到的最大权值. 当长宽不都为偶数时,必然能走遍所有格子,横着从左到右,从右到左(或是竖着走)走完即可. 当长宽都是偶数时, ...

  9. 【AC自动机】HDU中模板题

    [HDU2222] 最纯粹的裸题,错误点详见注释. #include<iostream> #include<cstdio> #include<cstring> #i ...

  10. 【Trie模板】HDU1251-统计难题

    [题意] n统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). [思路] 裸题,不过G++好像会超内存,C++就不会. #include<iostream> #include& ...