Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions code/cmdline/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Flag exe_params[] =
{ "-fb_thrusters", "Enable Framebuffer Thrusters", true, EASY_ALL_ON, EASY_DEFAULT, "Graphics", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-fb_thrusters", },
{ "-no_deferred", "Disable Deferred Lighting", true, EASY_DEFAULT | EASY_HI_MEM_OFF, EASY_ALL_ON | EASY_HI_MEM_ON, "Graphics", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-no_deferred"},
{ "-enable_shadows", "Enable Shadows", true, EASY_ALL_ON | EASY_HI_MEM_ON, EASY_DEFAULT | EASY_HI_MEM_OFF, "Graphics", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-enable_shadows"},
{ "-reversed_depth", "Reversed depth (less distant flicker)", true, 0, EASY_DEFAULT, "Graphics", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-reversed_depth"},
{ "-deferred_cockpit", "Enable Deferred Lighting for Cockpits", true, EASY_ALL_ON | EASY_HI_MEM_ON, EASY_DEFAULT | EASY_HI_MEM_OFF, "Graphics", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-deferred_cockpit"},

//flag launcher text FSO on_flags off_flags category reference URL
Expand Down Expand Up @@ -357,6 +358,7 @@ cmdline_parm fb_explosions_arg("-fb_explosions", NULL, AT_NONE);
cmdline_parm fb_thrusters_arg("-fb_thrusters", NULL, AT_NONE);
cmdline_parm shadow_quality_arg("-shadow_quality", NULL, AT_INT);
cmdline_parm enable_shadows_arg("-enable_shadows", NULL, AT_NONE);
cmdline_parm reversed_depth_arg("-reversed_depth", nullptr, AT_NONE); // Gr_enable_reversed_depth
cmdline_parm rt_shadows_arg("-rt_shadows", nullptr, AT_NONE);
cmdline_parm no_deferred_lighting_arg("-no_deferred", NULL, AT_NONE); // Cmdline_no_deferred
cmdline_parm deferred_lighting_cockpit_arg("-deferred_cockpit", nullptr, AT_NONE);
Expand Down Expand Up @@ -2274,6 +2276,14 @@ bool SetCmdlineParams()
Cmdline_reparse_mainhall = 1;
}

if (reversed_depth_arg.found()) {
Gr_enable_reversed_depth = true;
// in-game options are only read in mods that turn them on; the flag works everywhere
options::OptionsManager::instance()->setOverride("Graphics.ReversedDepth",
std::unique_ptr<json_t>(json_true()),
"-reversed_depth");
}

if( enable_shadows_arg.found() )
{
// if only using `enable_shadows` then default quality level can be overriden in mod_settings.tbl --wookieejedi
Expand Down
5 changes: 5 additions & 0 deletions code/def_files/data/effects/decal-f.sdr
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ vec3 computeViewPosition(vec2 textureCoord) {
clipSpaceLocation.z = texelFetch(gDepthBuffer, ivec2(textureCoord), 0).r;
#else
clipSpaceLocation.xy = normalizedCoord * 2.0f - 1.0f;
#ifdef REVERSED_Z
// reversed depth sets the depth range to [0, 1], as in Vulkan
clipSpaceLocation.z = texelFetch(gDepthBuffer, ivec2(textureCoord), 0).r;
#else
clipSpaceLocation.z = texelFetch(gDepthBuffer, ivec2(textureCoord), 0).r * 2.0f - 1.0f;
#endif
#endif
clipSpaceLocation.w = 1.0f;

Expand Down
5 changes: 5 additions & 0 deletions code/def_files/data/effects/effect-f.sdr
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ void main()
}
fragDepthLinear = -fragPosition.z;
} else {
#ifdef REVERSED_Z
sceneDepthLinear = ( farZ * nearZ ) / ( nearZ + sceneDepth.x * (farZ-nearZ) );
fragDepthLinear = ( farZ * nearZ ) / ( nearZ + gl_FragCoord.z * (farZ-nearZ) );
#else
sceneDepthLinear = ( 2.0 * farZ * nearZ ) / ( farZ + nearZ - sceneDepth.x * (farZ-nearZ) );
fragDepthLinear = ( 2.0 * farZ * nearZ ) / ( farZ + nearZ - gl_FragCoord.z * (farZ-nearZ) );
#endif
}
// assume UV of 0.5, 0.5 is the centroid of this sphere volume
float depthOffset = sqrt((fragRadius*fragRadius) - (offset_len*offset_len));
Expand Down
5 changes: 5 additions & 0 deletions code/def_files/data/effects/fog-f.sdr
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ void main()

// If the scene is in fog then we change the color we operate on based on the depth of the pixel
float depth_val = texture(depth_tex, fragTexCoord.xy).x;
#ifdef REVERSED_Z
float view_depth = zNear * zFar / (zNear + depth_val * (zFar - zNear));
float skybox_compat_fake = depth_val <= 0.0 ? 1.0 : 0.0;
#else
// Transform depth value from [0, 1] to [-1, 1]
float depth_normalized = 2 * depth_val - 1;
// Now we compute the depth value in projection space using the clipping plane information
float view_depth = 2.0 * zNear * zFar / (zFar + zNear - depth_normalized * (zFar - zNear));

float skybox_compat_fake = step(1.0, depth_val);
#endif
view_depth = clamp(view_depth, 0.0, mix(clip_dist, clip_inf_dist, skybox_compat_fake));

if (isinf(view_depth)) {
Expand Down
17 changes: 15 additions & 2 deletions code/def_files/data/effects/ls-f.sdr
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,27 @@ void main()
float decay = 1.0;
vec4 sum = vec4(0.0);
vec4 mask = texture(cockpit, fragTexCoord.st);
if (mask.r < 1.0) {
#if defined(REVERSED_Z) && defined(VULKAN)
// Vulkan binds no cockpit depth here; its placeholder texture is white, which reads as the near plane
bool cockpit_covers = false;
#elif defined(REVERSED_Z)
bool cockpit_covers = mask.r > 0.0;
#else
bool cockpit_covers = mask.r < 1.0;
#endif
if (cockpit_covers) {
fragOut0 = vec4(cp_intensity);
return;
}
#ifdef REVERSED_Z
const float sky_depth = 0.0;
#else
const float sky_depth = 1.0;
#endif
for(int i=0; i < SAMPLE_NUM ; i++) {
pos.st -= step;
vec4 tex_sample = texture(scene, pos);
if (tex_sample.r == 1.0)
if (tex_sample.r == sky_depth)
sum += decay * weight;
decay *= falloff;
}
Expand Down
5 changes: 5 additions & 0 deletions code/def_files/data/effects/main-v.sdr
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ void main()

// Fog distance
#prereplace IF_FLAG MODEL_SDR_FLAG_FOG
#ifdef REVERSED_Z
// clip z no longer grows with distance; w is the view depth
vertOut.fogDist = gl_Position.w - fogNear;
#else
vertOut.fogDist = gl_Position.z - fogNear;
#endif
#prereplace ENDIF_FLAG //MODEL_SDR_FLAG_FOG
#ifdef VULKAN
#prereplace IF_NOT_FLAG MODEL_SDR_FLAG_FOG
Expand Down
2 changes: 1 addition & 1 deletion code/def_files/data/effects/shadows.sdr
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ vec4 transformToShadowMap(mat4 shadow_proj_matrix, int i, vec4 pos)
{
vec4 shadow_proj;
shadow_proj = shadow_proj_matrix * pos;
#ifdef VULKAN
#if defined(VULKAN) || defined(REVERSED_Z)
// Vulkan shadow projection: XY is [-1,1] → [0,1], Z is already [0,1]
shadow_proj.xy = shadow_proj.xy * 0.5 + 0.5;
#else
Expand Down
4 changes: 3 additions & 1 deletion code/def_files/data/effects/volumetric-f.sdr
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ void main()
vec2 fragcoordAngle = (fragTexCoord.xy - 0.5) * fov;
fragcoordAngle.x *= aspect;
float rawDepth = texture(depth_tex, fragTexCoord.xy).x;
#ifdef VULKAN
#if defined(REVERSED_Z)
float fragDepth = (zNear * zFar / (zNear + rawDepth * (zFar - zNear))) * sqrt(1.0 + tan(fragcoordAngle.x) * tan(fragcoordAngle.x) + tan(fragcoordAngle.y) * tan(fragcoordAngle.y));
#elif defined(VULKAN)
// Vulkan depth range is [0,1]
float fragDepth = (zNear * zFar / (zFar - rawDepth * (zFar - zNear))) * sqrt(1.0 + tan(fragcoordAngle.x) * tan(fragcoordAngle.x) + tan(fragcoordAngle.y) * tan(fragcoordAngle.y));
#else
Expand Down
14 changes: 14 additions & 0 deletions code/graphics/2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,20 @@ static auto HDROption __UNUSED = options::OptionBuilder<bool>("Graphics.HDR",
.parser(parse_hdr_func)
.finish();

bool Gr_enable_reversed_depth = false;
bool Gr_reversed_depth_active = false;

// coverity[GLOBAL_INIT_ORDER] -- safe; OptionBuilder::finish() uses Meyers singleton
static auto ReversedDepthOption __UNUSED = options::OptionBuilder<bool>("Graphics.ReversedDepth",
std::pair<const char*, int>{"Reversed Depth", -1},
std::pair<const char*, int>{"Reduces flicker between distant surfaces. Needs Vulkan or OpenGL 4.5. Requires a restart to take effect.", -1})
.category(std::make_pair("Graphics", 1825))
.level(options::ExpertLevel::Advanced)
.default_val(false)
.bind_to_once(&Gr_enable_reversed_depth)
.importance(67)
.finish();

float Gr_hdr_paperwhite_nits = 200.0f;

static void parse_hdr_paperwhite_func()
Expand Down
11 changes: 11 additions & 0 deletions code/graphics/2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ extern bool Gr_enable_vsync;

// HDR10 (PQ/ST.2084 + BT.2020) output. Currently only honored by the Vulkan renderer.
extern bool Gr_enable_hdr;

// Reversed depth: the request (an option, read at startup) and whether the renderer turned it on.
// With it active, the near plane is depth 1, the far plane depth 0, and closer surfaces pass with GREATER.
extern bool Gr_enable_reversed_depth;
extern bool Gr_reversed_depth_active;

// the depth of an empty pixel: what the depth buffer is cleared to
inline float gr_far_depth()
{
return Gr_reversed_depth_active ? 0.0f : 1.0f;
}
// True once the renderer has actually negotiated an HDR10 swap chain (read-only,
// set by the active renderer). Distinct from Gr_enable_hdr, which is the request.
extern bool Gr_hdr_output_active;
Expand Down
18 changes: 16 additions & 2 deletions code/graphics/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ static void create_perspective_projection_matrix(matrix4 *out, float left, float
out->a1d[10] = -(far_dist + near_dist) / (far_dist - near_dist);
out->a1d[14] = -2.0f * far_dist * near_dist / (far_dist - near_dist);
}

if (Gr_reversed_depth_active) {
// near maps to 1 and far to 0, in the [0, 1] range reversed depth uses on both APIs. Written out rather
// than flipped from the values above, where float rounding would move the far plane when far is much
// larger than near.
out->a1d[10] = near_dist / (far_dist - near_dist);
out->a1d[14] = far_dist * near_dist / (far_dist - near_dist);
}
}

static void create_orthographic_projection_matrix(matrix4* out, float left, float right, float bottom, float top, float near_dist, float far_dist)
Expand All @@ -81,8 +89,8 @@ static void create_orthographic_projection_matrix(matrix4* out, float left, floa
out->a1d[13] = -(top + bottom) / (top - bottom);
out->a1d[15] = 1.0f;

if (gr_screen.mode == GraphicsAPI::Vulkan) {
// Vulkan NDC Z range is [0, 1] (OpenGL is [-1, 1])
if (gr_screen.mode == GraphicsAPI::Vulkan || Gr_reversed_depth_active) {
// Vulkan NDC Z range is [0, 1] (OpenGL is [-1, 1], unless reversed depth set it to [0, 1])
// Y-flip is handled by negative viewport height (VK_KHR_maintenance1)
out->a1d[10] = -1.0f / (far_dist - near_dist);
out->a1d[14] = -near_dist / (far_dist - near_dist);
Expand All @@ -91,6 +99,12 @@ static void create_orthographic_projection_matrix(matrix4* out, float left, floa
out->a1d[10] = -2.0f / (far_dist - near_dist);
out->a1d[14] = -(far_dist + near_dist) / (far_dist - near_dist);
}

if (Gr_reversed_depth_active) {
// depth becomes 1 - depth: near maps to 1, far to 0
out->a1d[10] = -out->a1d[10];
out->a1d[14] = 1.0f - out->a1d[14];
}
}

void gr_start_instance_matrix(const vec3d *offset, const matrix *rotation)
Expand Down
27 changes: 25 additions & 2 deletions code/graphics/opengl/gropengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,15 +863,33 @@ void gr_opengl_set_fill_mode(int mode)
GL_state.SetPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}

// GL 4.5 drivers advertise ARB_clip_control too, so one check covers both
static void opengl_enable_reversed_depth()
{
#ifndef USE_OPENGL_ES
if (!GLAD_GL_ARB_clip_control) {
mprintf((" Reversed depth needs ARB_clip_control; using normal depth\n"));
return;
}

glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
glClearDepth(0.0);
Gr_reversed_depth_active = true;
mprintf((" Using reversed depth\n"));
#endif
}

void gr_opengl_zbias(int bias)
{
if (bias) {
// with reversed depth, closer means larger depth, so the offset changes sign
const float sign = Gr_reversed_depth_active ? -1.0f : 1.0f;
GL_state.PolygonOffsetFill(GL_TRUE);
if(bias < 0) {
GL_state.SetPolygonOffset(1.0, -i2fl(bias));
GL_state.SetPolygonOffset(sign * 1.0f, sign * -i2fl(bias));
}
else {
GL_state.SetPolygonOffset(0.0, -i2fl(bias));
GL_state.SetPolygonOffset(0.0, sign * -i2fl(bias));
}
} else {
GL_state.PolygonOffsetFill(GL_FALSE);
Expand Down Expand Up @@ -1415,6 +1433,10 @@ bool gr_opengl_init(std::unique_ptr<os::GraphicsOperations>&& graphicsOps)

GL_initted = true;

if (Gr_enable_reversed_depth) {
opengl_enable_reversed_depth();
}

#ifndef NDEBUG
// Set up the debug extension if present
if (GLAD_GL_ARB_debug_output) {
Expand Down Expand Up @@ -1442,6 +1464,7 @@ bool gr_opengl_init(std::unique_ptr<os::GraphicsOperations>&& graphicsOps)
mprintf((" Layered viewport support : %s\n", GLAD_GL_ARB_shader_viewport_layer_array ? NOX("YES") : NOX("NO")));
mprintf((" S3TC texture support : %s\n", GLAD_GL_EXT_texture_compression_s3tc ? NOX("YES") : NOX("NO")));
mprintf((" BPTC texture support : %s\n", GLAD_GL_ARB_texture_compression_bptc ? NOX("YES") : NOX("NO")));
mprintf((" Clip control support : %s\n", GLAD_GL_ARB_clip_control ? NOX("YES") : NOX("NO")));

#ifdef USE_OPENGL_ES
GLint maxBuffers;
Expand Down
18 changes: 9 additions & 9 deletions code/graphics/opengl/gropengldraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ void opengl_setup_scene_textures()

glTexImage2D(GL_TEXTURE_2D,
0,
GL_DEPTH24_STENCIL8,
Gr_reversed_depth_active ? GL_DEPTH32F_STENCIL8 : GL_DEPTH24_STENCIL8,
Scene_texture_width,
Scene_texture_height,
0,
GL_DEPTH_COMPONENT,
GL_FLOAT,
Gr_reversed_depth_active ? GL_DEPTH_STENCIL : GL_DEPTH_COMPONENT,
Gr_reversed_depth_active ? GL_FLOAT_32_UNSIGNED_INT_24_8_REV : GL_FLOAT,
nullptr);
opengl_set_object_label(GL_TEXTURE, Cockpit_depth_texture, "Cockpit depth texture");

Expand All @@ -319,12 +319,12 @@ void opengl_setup_scene_textures()

glTexImage2D(GL_TEXTURE_2D,
0,
GL_DEPTH24_STENCIL8,
Gr_reversed_depth_active ? GL_DEPTH32F_STENCIL8 : GL_DEPTH24_STENCIL8,
Scene_texture_width,
Scene_texture_height,
0,
GL_DEPTH_COMPONENT,
GL_FLOAT,
Gr_reversed_depth_active ? GL_DEPTH_STENCIL : GL_DEPTH_COMPONENT,
Gr_reversed_depth_active ? GL_FLOAT_32_UNSIGNED_INT_24_8_REV : GL_FLOAT,
nullptr);
opengl_set_object_label(GL_TEXTURE, Scene_depth_texture, "Scene depth texture");
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, Scene_depth_texture, 0);
Expand Down Expand Up @@ -513,7 +513,7 @@ void opengl_setup_scene_textures()

glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE,
Cmdline_msaa_enabled,
GL_DEPTH24_STENCIL8,
Gr_reversed_depth_active ? GL_DEPTH32F_STENCIL8 : GL_DEPTH24_STENCIL8,
Scene_texture_width,
Scene_texture_height,
GL_TRUE);
Expand Down Expand Up @@ -569,12 +569,12 @@ void opengl_setup_scene_textures()

glTexImage2D(GL_TEXTURE_2D,
0,
GL_DEPTH24_STENCIL8,
Gr_reversed_depth_active ? GL_DEPTH32F_STENCIL8 : GL_DEPTH24_STENCIL8,
gr_screen.max_w,
gr_screen.max_h,
0,
GL_DEPTH_STENCIL,
GL_UNSIGNED_INT_24_8,
Gr_reversed_depth_active ? GL_FLOAT_32_UNSIGNED_INT_24_8_REV : GL_UNSIGNED_INT_24_8,
nullptr);
opengl_set_object_label(GL_TEXTURE, Back_depth_texture, "Backbuffer depth texture");

Expand Down
4 changes: 2 additions & 2 deletions code/graphics/opengl/gropenglstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void opengl_state::SetZbufferType(gr_zbuffer_type zt)
break;

case ZBUFFER_TYPE_READ:
GL_state.DepthFunc(GL_LESS);
GL_state.DepthFunc(Gr_reversed_depth_active ? GL_GREATER : GL_LESS);
GL_state.DepthMask(GL_FALSE);
break;

Expand All @@ -522,7 +522,7 @@ void opengl_state::SetZbufferType(gr_zbuffer_type zt)
break;

case ZBUFFER_TYPE_FULL:
GL_state.DepthFunc(GL_LESS);
GL_state.DepthFunc(Gr_reversed_depth_active ? GL_GREATER : GL_LESS);
GL_state.DepthMask(GL_TRUE);
break;

Expand Down
5 changes: 4 additions & 1 deletion code/graphics/opengl/gropengltexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,10 @@ int opengl_make_render_target( int handle, int *w, int *h, int *bpp, int *mm_lvl
if (flags & BMP_FLAG_RENDER_TARGET_DEPTH_ATTACHMENT) {
glGenRenderbuffers(1, &new_fbo->renderbuffer_id);
glBindRenderbuffer(GL_RENDERBUFFER, new_fbo->renderbuffer_id);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, *w, *h);
glRenderbufferStorage(GL_RENDERBUFFER,
Gr_reversed_depth_active ? GL_DEPTH32F_STENCIL8 : GL_DEPTH24_STENCIL8,
*w,
*h);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}

Expand Down
1 change: 1 addition & 0 deletions code/graphics/opengl/gropengltnl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ static bool opengl_init_shadow_framebuffer(int size)
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, Gr_reversed_depth_active ? GL_GEQUAL : GL_LEQUAL);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, size, size, Num_shadow_cascades + Num_cockpit_shadow_cascades, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);

glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, Shadow_map_depth_texture, 0);
Expand Down
3 changes: 3 additions & 0 deletions code/graphics/shader_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ SCP_string shader_preprocess_defines(const SCP_string& filename, const SCP_strin

//In any shader, define GLOBAL_FAR_Z
output << "#define GLOBAL_FAR_Z " << std::fixed << std::setprecision(2) << Max_draw_distance << std::defaultfloat << '\n';
if (Gr_reversed_depth_active) {
output << "#define REVERSED_Z\n";
}

const char* PREDEFINE_STRING = "#predefine";
const char* PREREPLACE_STRING = "#prereplace";
Expand Down
10 changes: 8 additions & 2 deletions code/graphics/shadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,21 @@ void shadows_construct_light_proj(light_frustum_info *shadow_data)
shadow_data->proj_matrix.a1d[13] = -(shadow_data->max.xyz.y + shadow_data->min.xyz.y) / ( shadow_data->max.xyz.y - shadow_data->min.xyz.y );
shadow_data->proj_matrix.a1d[15] = 1.0f;

if (gr_screen.mode == GraphicsAPI::Vulkan) {
// Vulkan uses [0, 1] depth range
if (gr_screen.mode == GraphicsAPI::Vulkan || Gr_reversed_depth_active) {
// Vulkan uses [0, 1] depth range, and so does OpenGL with reversed depth
shadow_data->proj_matrix.a1d[10] = -1.0f / ( shadow_data->max.xyz.z - shadow_data->min.xyz.z );
shadow_data->proj_matrix.a1d[14] = -shadow_data->min.xyz.z / ( shadow_data->max.xyz.z - shadow_data->min.xyz.z );
} else {
// OpenGL uses [-1, 1] depth range
shadow_data->proj_matrix.a1d[10] = -2.0f / ( shadow_data->max.xyz.z - shadow_data->min.xyz.z );
shadow_data->proj_matrix.a1d[14] = -(shadow_data->max.xyz.z + shadow_data->min.xyz.z) / ( shadow_data->max.xyz.z - shadow_data->min.xyz.z );
}

// shadow maps share the depth test with everything else, so they are reversed as well
if (Gr_reversed_depth_active) {
shadow_data->proj_matrix.a1d[10] = -shadow_data->proj_matrix.a1d[10];
shadow_data->proj_matrix.a1d[14] = 1.0f - shadow_data->proj_matrix.a1d[14];
}
}

void shadows_debug_show_frustum(matrix* orient, vec3d *pos, float fov, float aspect, float z_near, float z_far)
Expand Down
Loading
Loading