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. 基本套接字编程(3) -- select篇

    1. I/O复用 我们学习了I/o复用的基本知识,了解到目前支持I/O复用的系统调用有select.pselect.poll.epoll.而epoll技术以其独特的优势被越来越多的应用到各大企业服务器 ...

  2. 关于MySql数据库设计表与查询耗时分析

    本地建一张表persons,使用脚本插入了1000万条数据 下面比较几种查询方法的耗时(查询9000000到9000005这中间5条数据) 查询结果: 1: SELECT * FROM test.pe ...

  3. Map:containsKey、containsValue 获取Map集合的键值的 值

    get(Object key) 返回与指定键关联的值: containsKey(Object key) 如果Map包含指定键的隐射,则返回true: containsValue(Object valu ...

  4. android的多渠道打包

    本文出处:http://www.cnblogs.com/0616--ataozhijia/p/4203997.html 这里以友盟为例子. 项目快上线了,要做一个多渠道打包.不然每次都要在Androi ...

  5. maven工程引用外部jar包

    maven工程经常回遇到引用外部jar包,需要先安装在jar包,然后再在工程中pom.xml文件中添加依赖. 示例: 命令行中运行: mvn install:install-file -Dfile=E ...

  6. ORACLE 學習筆記

    proc 里的 commit等于提交就是你做了insert或者update后,commit后才是真正修改或者插入了数据库中 如果不提交的话,那么这个表就被锁了 CURSOR MYCURSOR is   ...

  7. 拉格朗日乘子法和KKT条件

    拉格朗日乘子法(Lagrange Multiplier)和KKT(Karush-Kuhn-Tucker)条件是求解约束优化问题的重要方法,在有等式约束时使用拉格朗日乘子法,在有不等约束时使用KKT条件 ...

  8. 作死遇到的坑--view向下偏移

    好大一个坑.--谈谈view偏移问题: 先上张图, 图中白色部分.上面的是从网上找的资源.将导航栏隐藏之后用collectionView加上去而实现的滑动标签功能.开始以为是代码中的问题.然后仔细推敲 ...

  9. 一步一步搭建客服系统 (4) 客户列表 - JS($.ajax)调用WCF 遇到的各种坑

    本文以一个生成.获取“客户列表”的demo来介绍如何用js调用wcf,以及遇到的各种问题. 1 创建WCF服务 1.1 定义接口 创建一个接口,指定用json的格式:   [ServiceContra ...

  10. WPF快速入门系列(4)——深入解析WPF绑定

    一.引言 WPF绑定使得原本需要多行代码实现的功能,现在只需要简单的XAML代码就可以完成之前多行后台代码实现的功能.WPF绑定可以理解为一种关系,该关系告诉WPF从一个源对象提取一些信息,并将这些信 ...