Skip to content

Commit 07e151d

Browse files
committed
fix another revZ problem in ogl
fix another revZ problem in ogl
1 parent 707b68d commit 07e151d

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/ShaderBase.hlsl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef __SHADERBASE_H__
22
#define __SHADERBASE_H__
33

4+
// can't use UNITY_REVERSED_Z since it's not enabled in compute shaders
5+
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
6+
#define REVERSE_ZBUF
7+
#endif
8+
49
#ifdef SHADER_API_PSSL
510

611
#ifndef Texture2DMS
@@ -20,7 +25,7 @@
2025
float FetchDepth(Texture2D depthTexture, uint2 pixCoord)
2126
{
2227
float zdpth = LOAD_TEXTURE2D(depthTexture, pixCoord.xy).x;
23-
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
28+
#ifdef REVERSE_ZBUF
2429
zdpth = 1.0 - zdpth;
2530
#endif
2631
return zdpth;
@@ -29,7 +34,7 @@ float FetchDepth(Texture2D depthTexture, uint2 pixCoord)
2934
float FetchDepthMSAA(Texture2DMS<float> depthTexture, uint2 pixCoord, uint sampleIdx)
3035
{
3136
float zdpth = LOAD_TEXTURE2D_MSAA(depthTexture, pixCoord.xy, sampleIdx).x;
32-
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
37+
#ifdef REVERSE_ZBUF
3338
zdpth = 1.0 - zdpth;
3439
#endif
3540
return zdpth;

Assets/ScriptableRenderLoop/common/ShaderBase.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef __SHADERBASE_H__
22
#define __SHADERBASE_H__
33

4+
// can't use UNITY_REVERSED_Z since it's not enabled in compute shaders
5+
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
6+
#define REVERSE_ZBUF
7+
#endif
8+
49
#ifdef SHADER_API_PSSL
510

611
#ifndef Texture2DMS
@@ -32,7 +37,7 @@
3237
float FetchDepth(Texture2D depthTexture, uint2 pixCoord)
3338
{
3439
float zdpth = depthTexture.Load(uint3(pixCoord.xy, 0)).x;
35-
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
40+
#ifdef REVERSE_ZBUF
3641
zdpth = 1.0 - zdpth;
3742
#endif
3843
return zdpth;
@@ -41,7 +46,7 @@ float FetchDepth(Texture2D depthTexture, uint2 pixCoord)
4146
float FetchDepthMSAA(Texture2DMS<float> depthTexture, uint2 pixCoord, uint sampleIdx)
4247
{
4348
float zdpth = depthTexture.Load(uint3(pixCoord.xy, 0), sampleIdx).x;
44-
#if !defined(SHADER_API_GLES3) && !defined(SHADER_API_GLCORE)
49+
#ifdef REVERSE_ZBUF
4550
zdpth = 1.0 - zdpth;
4651
#endif
4752
return zdpth;

Assets/ScriptableRenderLoop/fptl/LightingTemplate.hlsl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ StructuredBuffer<DirectionalLight> g_dirLightData;
4646

4747

4848
#define DECLARE_SHADOWMAP( tex ) Texture2D tex; SamplerComparisonState sampler##tex
49-
#define SAMPLE_SHADOW( tex, coord ) tex.SampleCmpLevelZero( sampler##tex, (coord).xy, (coord).z )
49+
#ifdef REVERSE_ZBUF
50+
#define SAMPLE_SHADOW( tex, coord ) tex.SampleCmpLevelZero( sampler##tex, (coord).xy, (coord).z )
51+
#else
52+
#define SAMPLE_SHADOW( tex, coord ) tex.SampleCmpLevelZero( sampler##tex, (coord).xy, 1.0-(coord).z )
53+
#endif
5054

5155
DECLARE_SHADOWMAP(g_tShadowBuffer);
5256

0 commit comments

Comments
 (0)