1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-15 09:34:18 +02:00

fix rgba8 depth packing precision

This commit is contained in:
XProger
2018-05-20 16:31:09 +03:00
parent 0799647a0b
commit 42b516c87b
3 changed files with 19 additions and 26 deletions

View File

@@ -12,8 +12,8 @@
#ifdef WIN32
#define _OS_WIN 1
//#define _GAPI_GL 1
#define _GAPI_D3D9 1
#define _GAPI_GL 1
//#define _GAPI_D3D9 1
//#define _GAPI_VULKAN 1
#include <windows.h>

View File

@@ -3,7 +3,7 @@
#define WATER_FOG_DIST (1.0 / (6.0 * 1024.0))
#define UNDERWATER_COLOR float3(0.6, 0.9, 0.9)
#define SHADOW_NORMAL_BIAS 16.0
#define SHADOW_CONST_BIAS 0.18
#define SHADOW_CONST_BIAS 0.04
#define PI 3.141592653589793
static const float3 SHADOW_TEXEL = float3(1.0 / 1024.0, 1.0 / 1024.0, 0.0);
@@ -67,14 +67,10 @@ float4 uContacts[MAX_CONTACTS] : register( c94 );
#define OPT_CAUSTICS uFlags[11]
float4 pack(float value) {
float4 bitSh = float4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
float4 bitMsk = float4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
float4 res = frac(value * bitSh);
res -= res.xxyz * bitMsk;
return res;
float4 v = frac(value * float4(1.0, 255.0, 65025.0, 16581375.0));
return v - v.yzww * float4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);
}
float unpack(float4 value) {
float4 bitSh = float4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);
return dot(value, bitSh);
return dot(value, float4(1.0, 1/255.0, 1/65025.0, 1/16581375.0));
}

View File

@@ -9,6 +9,9 @@ R"====(
#define WATER_FOG_DIST (1.0 / (6.0 * 1024.0))
#define UNDERWATER_COLOR vec3(0.6, 0.9, 0.9)
#define SHADOW_NORMAL_BIAS 16.0
#define SHADOW_CONST_BIAS 0.04
#if (defined(PASS_AMBIENT) || defined(PASS_COMPOSE)) && !defined(TYPE_FLASH)
varying vec3 vCoord;
#endif
@@ -250,15 +253,14 @@ uniform vec4 uFogParams;
uniform samplerCube sEnvironment;
#endif
#if defined(PASS_SHADOW) && defined(SHADOW_COLOR)
vec4 pack(in float value) {
vec4 bitSh = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
vec4 bitMsk = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
vec4 res = fract(value * bitSh);
res -= res.xxyz * bitMsk;
return res;
float v = fract(value * vec4(1.0, 255.0, 65025.0, 16581375.0));
return v - v.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);
}
float unpack(vec4 value) {
return dot(value, vec4(1.0, 1/255.0, 1/65025.0, 1/16581375.0));
}
#endif
#ifdef OPT_SHADOW
#ifdef SHADOW_SAMPLER
@@ -271,11 +273,6 @@ uniform vec4 uFogParams;
#else
uniform sampler2D sShadow;
float unpack(vec4 value) {
vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);
return dot(value, bitSh);
}
float SHADOW(vec2 p) {
#ifdef SHADOW_DEPTH
return texture2D(sShadow, p).x;
@@ -288,7 +285,7 @@ uniform vec4 uFogParams;
float getShadow(vec3 lightVec, vec3 normal, vec4 lightProj) {
vec3 p = lightProj.xyz / lightProj.w;
p.xyz = p.xyz * 0.5 + 0.5;
p.z -= 0.04 * SHADOW_TEXEL.x;
p.z -= SHADOW_CONST_BIAS * SHADOW_TEXEL.x;
float vis = lightProj.w;
#ifdef TYPE_ROOM
@@ -317,7 +314,7 @@ uniform vec4 uFogParams;
float getShadow(vec3 lightVec, vec3 normal) {
float factor = clamp(1.0 - dot(normalize(lightVec), normal), 0.0, 1.0);
factor *= 16.0;
factor *= SHADOW_NORMAL_BIAS;
return getShadow(lightVec, normal, uLightProj * vec4(vCoord + normal * factor, 1.0));
}
#endif