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. 修改eclipse中settings.xml和默认资源库保存地址

    1.打开eclipse 2.window-->references-->Maven0-->User Settings:修改User Settings,Browse重新选择新位置D:\ ...

  2. 尽量少用if else

    Michael Feathers是Object Mentor International公司的技术顾问.他的工作不仅是技术开发,他还参与对世界各地技术团队进行培训.指导等工作.他曾开发了将JUnit迁 ...

  3. php protected封装

    <?//父类class father{ public function a(){     echo 'father->a()'.'<br>';  echo "func ...

  4. Azure IOT (EventHub + Stream Analytics + Table Storage)的使用

    最近研究利用Azure的 Event hub ,Stream Analytics和TableStorage来实现IOT的一个方案, 利用Event hub来采集传感器设备数据值,然后输入到Stream ...

  5. ZOJ2532_Internship

    一个单源多汇的有向图,求增大那些边的容量可以使得网络的最大流增加. 很简单,直接跑最大流,保留残余网络,然后枚举所有余量为0的边,使其容量增加一个1,看看是否出现新的增广路即可. 召唤代码君: #in ...

  6. poj 1080 (LCS变形)

    Human Gene Functions 题意: LCS: 设dp[i][j]为前i,j的最长公共序列长度: dp[i][j] = dp[i-1][j-1]+1;(a[i] == b[j]) dp[i ...

  7. php中文截取无乱码方法

    直接使用PHP函数substr截取中文字符可能会出现乱码,主要是substr可能硬生生的将一个中文字符“锯”成两半.解决办法: 1.使用mbstring扩展库的mb_substr截取就不会出现乱码了. ...

  8. JavaScript-setTimeout

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  9. ubuntu卸载java

    Try this command: java -version If 1.6* comes then try: sudo apt-get autoremove openjdk-6-jre If 1.7 ...

  10. 跟我一起学WCF(8)——WCF中Session、实例管理详解

    一.引言 由前面几篇博文我们知道,WCF是微软基于SOA建立的一套在分布式环境中各个相对独立的应用进行交流(Communication)的框架,它实现了最新的基于WS-*规范.按照SOA的原则,相对独 ...