I'm implementing ominidirectional shadow mapping for point lights. I want to use a linear depth which will be stored in the color textures (cube map). A program will contain two filtering techniques: software pcf (because hardware pcf works only with depth textures) and variance shadow mapping. I found two ways of storing linear depth:

constfloat linearDepthConstant =1.0/(zFar - zNear);//firstfloat moment1 =-viewSpace.z * linearDepthConstant;float moment2 = moment1 * moment1;
outColor = vec2(moment1, moment2);//secondfloat moment1 = length(viewSpace)* linearDepthConstant;float moment2 = moment1 * moment1;
outColor = vec2(moment1, moment2);

What are differences between them ? Are both ways correct ?

For the standard shadow mapping with software pcf a shadow test will depend on the linear depth format. What about variance shadow mapping ?

I implemented omnidirectional shadow mapping for points light using a non-linear depth and hardware pcf. In that case a shadow test looks like this:

vec3 lightToPixel = worldSpacePos - worldSpaceLightPos;
vec3 aPos = abs(lightToPixel);float fZ =-max(aPos.x, max(aPos.y, aPos.z));
vec4 clip = pLightProjection * vec4(0.0,0.0, fZ,1.0);float depth =(clip.z / clip.w)*0.5+0.5;float shadow = texture(ShadowMapCube, vec4(normalize(lightToPixel), depth));

I also implemented standard shadow mapping without pcf which using second format of linear depth: (Edit 1: i.e. distance to the light + some offset to fix shadow acne)

vec3 lightToPixel = worldSpacePos - worldSpaceLightPos;constfloat linearDepthConstant =1.0/(zFar - zNear);float fZ = length(lightToPixel)* linearDepthConstant;float depth = texture(ShadowMapCube, normalize(lightToPixel)).x;if(depth <= fZ){
shadow =0.0;}else{
shadow =1.0;}

but I have no idea how to do that for the first format of linear depth. Is it possible ?

Edit 2: For non-linear depth I used glPolygonOffset to fix shadow acne. For linear depth and distance to the light some offset should be add in the shader. I'm trying to implement standard shadow mapping without pcf using a linear depth (-viewSpace.z * linearDepthConstant + offset) but following shadow test doesn't produce correct results:

vec3 lightToPixel = worldSpacePos - worldSpaceLightPos;
vec3 aPos = abs(lightToPixel);float fZ =-max(aPos.x, max(aPos.y, aPos.z));
vec4 clip = pLightProjection * vec4(0.0,0.0, fZ,1.0);float fDepth =(clip.z / clip.w)*0.5+0.5;float depth = texture(ShadowMapCube, normalize(lightToPixel)).x;if(depth <= fDepth){
shadow =0.0;}else{
shadow =1.0;}

How to fix that ?

asked Sep 26 '13 at 23:29
Irbis
30917
  add comment

The method with viewSpace.z is storing depth, while the method with length(viewSpace) is storingdistance to the light, not depth (which is always measured parallel to a view direction).

You could store either one, but you have to be consistent about it. If you store distance instead of depth when you render your shadow map, you have to compare against distance instead of depth when you apply the shadow map.

Depth is the natural choice as that's what will be generated by the GPU rasterizer when you draw the shadow map. It takes extra work to convert it to distance (you have to set up the viewSpace vector). But I can imagine that distance might give better results in some situations with VSM. You'd have to experiment to see.

depth and distance的更多相关文章

  1. 引擎设计跟踪(九.14.3.1) deferred shading: Depthstencil as GBuffer depth

    问题汇总 1.Light support for Editor编辑器加入了灯光工具, 可以添加和修改灯光. 问题1. light object的用户互交.point light可以把对应的volume ...

  2. SOCV / POCV 模型 (3)

    STA无疑是数字集成电路设计实现方法学中最『漂亮』的模型之一,但是随意着工艺进步,local varition 的随机性及重要性增加,传统STA 的局限性日渐突出.大概在十五年前,SSTA成了一个研究 ...

  3. STA之AOCV

    为什么要引入AOCV 为了精确性,为了剔除悲观度.用set_timing_derate来设置OCV,对于一个固定的corner,只能对data/clock, cell/net, late/early分 ...

  4. poj 1986 Distance Queries LCA

    题目链接:http://poj.org/problem?id=1986 Farmer John's cows refused to run in his marathon since he chose ...

  5. Kinect SDK C++ - 2. Kinect Depth Data

    Today we will learn how to get depth data from a kinect and what the format of the data is kinect co ...

  6. POJ 1986 Distance Queries / UESTC 256 Distance Queries / CJOJ 1129 【USACO】距离咨询(最近公共祖先)

    POJ 1986 Distance Queries / UESTC 256 Distance Queries / CJOJ 1129 [USACO]距离咨询(最近公共祖先) Description F ...

  7. distance field(占坑

    signed distance field https://kosmonautblog.wordpress.com/2017/05/09/signed-distance-field-rendering ...

  8. Depth Buffer

    Up until now there is only one type of output buffer you've made use of, the color buffer. This chap ...

  9. depth peeling实现半透明

    aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aH

随机推荐

  1. fiddler的使用

    查看fiddler监听的端口: tools=>fiddler options=>connections=>fiddler listens on port 8888 如果想抓curl发 ...

  2. 2016 小马哥 IOS

    2016  小马哥 IOS 最新视频完整版       链接:http://pan.baidu.com/s/1c1EQlBM 密码:mxkt

  3. Java泛型总结(转)

    本文是转载,原文链接:http://www.cnblogs.com/lwbqqyumidi/p/3837629.html 一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: ...

  4. Servlet 的认识

    Servlet的响应过程:1,web 客户端向 Servlet容器发出http请求2,Servlet容器接收 客户端发来的请求3,创建一个 HttpRequest对象,将客户端发来的请求信息封装到这个 ...

  5. linux运维的认知及RHEL7 Unix/Linux 系统 介绍和安装

    如何成为一个优秀的linux运维人员?      如果你有机会和条件:环境能够磨练一个人的能力和意志.      大胆的做你从未做过的项目,每一个项目都是对自身的极大提升.      有好的环境资源不 ...

  6. Java垃圾回收小结

    一.如何确定某个对象是“垃圾”? 首先要搞清一个最基本的问题:如果确定某个对象是“垃圾”?既然垃圾收集器的任务是回收垃圾对象所占的空间供新的对象使用,那么垃圾收集器如何确定某个对象是“垃圾”?—即通过 ...

  7. utime函数

    utime函数:对一个文件的访问和修改时间 #include <utime.h> int utime( const char *pathname, const struct utimbuf ...

  8. Python动态生成变量

    Python 也可以像javascript那样动态生成变量.我们看javascript的动态生成变量. var obj = {}; for (var i =0, len = 10; i < le ...

  9. javascript基础知识-对象

    javascript创建对象有三种方法: 1)对象直接量 例:var empty = {}; var point = {x:1,y:4}; var book = { "main title& ...

  10. day7----面向对象编程进阶

    本节内容: 面向对象高级语法部分 静态方法.类方法.属性方法 类的特殊方法 反射 异常处理 Socket开发基础 静态方法 它与类唯一的关联就是需要通过类名来调用这个方法 #静态方法实际跟类没关系,不 ...