EEVEE: Reverse-Z implementation
This feature greatly increase depth buffer precision. This is very noticeable in large view distance scenes. This is enabled by default on GPUs that supports it (most of the hardware we support already supports this). This makes rendering different on the GPUs that do not support that feature (`glClipControl`). While this give much better depth precision as before, we also have a lot of imprecision caused by our vertex transformations. This can be improved in another task. Pull Request: https://projects.blender.org/blender/blender/pulls/138898
This commit is contained in:
committed by
Clément Foucault
parent
cb8f0c7800
commit
ca88983af2
@@ -428,6 +428,7 @@ set(GLSL_SRC
|
||||
engines/eevee/shaders/eevee_ray_trace_screen_comp.glsl
|
||||
engines/eevee/shaders/eevee_ray_trace_screen_lib.glsl
|
||||
engines/eevee/shaders/eevee_ray_types_lib.glsl
|
||||
engines/eevee/shaders/eevee_reverse_z_lib.glsl
|
||||
engines/eevee/shaders/eevee_lightprobe_sphere_convolve_comp.glsl
|
||||
engines/eevee/shaders/eevee_lightprobe_sphere_eval_lib.glsl
|
||||
engines/eevee/shaders/eevee_lightprobe_sphere_irradiance_comp.glsl
|
||||
|
||||
@@ -281,6 +281,9 @@ void Film::init(const int2 &extent, const rcti *output_rect)
|
||||
}
|
||||
}
|
||||
|
||||
this->depth = GPU_clip_control_support() ? DepthState{0.0f, DRW_STATE_DEPTH_GREATER_EQUAL} :
|
||||
DepthState{1.0f, DRW_STATE_DEPTH_LESS_EQUAL};
|
||||
|
||||
/* Compute the passes needed by the viewport compositor. */
|
||||
Set<std::string> passes_used_by_viewport_compositor;
|
||||
if (inst_.is_viewport_compositor_enabled) {
|
||||
|
||||
@@ -55,6 +55,14 @@ class Film {
|
||||
/** For debugging purpose but could be a user option in the future. */
|
||||
static constexpr bool use_box_filter = false;
|
||||
|
||||
struct DepthState {
|
||||
/** Set to 0 if reverse Z is supported, 1 otherwise. */
|
||||
float clear_value = 1.0f;
|
||||
/** Set to DRW_STATE_DEPTH_GREATER_EQUAL if reverse Z is supported, DRW_STATE_DEPTH_LESS_EQUAL
|
||||
* otherwise. */
|
||||
DRWState test_state = DRW_STATE_DEPTH_LESS_EQUAL;
|
||||
} depth;
|
||||
|
||||
private:
|
||||
Instance &inst_;
|
||||
|
||||
|
||||
@@ -150,7 +150,8 @@ void PlanarProbeModule::viewport_draw(View &view, GPUFrameBuffer *view_fb)
|
||||
|
||||
viewport_display_ps_.init();
|
||||
viewport_display_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
|
||||
DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK);
|
||||
DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state |
|
||||
DRW_STATE_CULL_BACK);
|
||||
viewport_display_ps_.framebuffer_set(&view_fb);
|
||||
viewport_display_ps_.shader_set(inst_.shaders.static_shader_get(DISPLAY_PROBE_PLANAR));
|
||||
SphereProbeData &world_data = *static_cast<SphereProbeData *>(&inst_.light_probes.world_sphere_);
|
||||
|
||||
@@ -344,7 +344,8 @@ void SphereProbeModule::viewport_draw(View &view, GPUFrameBuffer *view_fb)
|
||||
|
||||
viewport_display_ps_.init();
|
||||
viewport_display_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
|
||||
DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK);
|
||||
DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
instance_.film.depth.test_state | DRW_STATE_CULL_BACK);
|
||||
viewport_display_ps_.framebuffer_set(&view_fb);
|
||||
viewport_display_ps_.shader_set(instance_.shaders.static_shader_get(DISPLAY_PROBE_SPHERE));
|
||||
viewport_display_ps_.bind_resources(*this);
|
||||
|
||||
@@ -509,7 +509,7 @@ void VolumeProbeModule::debug_pass_draw(View &view, GPUFrameBuffer *view_fb)
|
||||
float max_axis_len = math::reduce_max(math::to_scale(grid.object_to_world));
|
||||
debug_ps_.init();
|
||||
debug_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
|
||||
DRW_STATE_DEPTH_LESS_EQUAL);
|
||||
DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state);
|
||||
debug_ps_.framebuffer_set(&view_fb);
|
||||
debug_ps_.shader_set(inst_.shaders.static_shader_get(DEBUG_SURFELS));
|
||||
debug_ps_.push_constant("debug_surfel_radius", 0.5f * max_axis_len / grid.surfel_density);
|
||||
@@ -534,7 +534,7 @@ void VolumeProbeModule::debug_pass_draw(View &view, GPUFrameBuffer *view_fb)
|
||||
int3 grid_size = int3(cache->size);
|
||||
debug_ps_.init();
|
||||
debug_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
|
||||
DRW_STATE_DEPTH_LESS_EQUAL);
|
||||
DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state);
|
||||
debug_ps_.framebuffer_set(&view_fb);
|
||||
debug_ps_.shader_set(inst_.shaders.static_shader_get(DEBUG_IRRADIANCE_GRID));
|
||||
debug_ps_.push_constant("debug_mode", int(inst_.debug_mode));
|
||||
@@ -655,7 +655,8 @@ void VolumeProbeModule::display_pass_draw(View &view, GPUFrameBuffer *view_fb)
|
||||
|
||||
display_grids_ps_.init();
|
||||
display_grids_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
|
||||
DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK);
|
||||
DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state |
|
||||
DRW_STATE_CULL_BACK);
|
||||
display_grids_ps_.framebuffer_set(&view_fb);
|
||||
display_grids_ps_.shader_set(inst_.shaders.static_shader_get(DISPLAY_PROBE_VOLUME));
|
||||
|
||||
|
||||
@@ -307,8 +307,7 @@ void LookdevModule::sync_pass(PassSimple &pass,
|
||||
ResourceHandle res_handle)
|
||||
{
|
||||
pass.init();
|
||||
pass.clear_depth(1.0f);
|
||||
pass.clear_color(float4(0.0, 0.0, 0.0, 1.0));
|
||||
pass.clear_color_depth_stencil(float4(0.0, 0.0, 0.0, 1.0), inst_.film.depth.clear_value, 0);
|
||||
|
||||
const DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_CULL_BACK;
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ void BackgroundPipeline::sync(GPUMaterial *gpumat,
|
||||
RenderBuffers &rbufs = inst_.render_buffers;
|
||||
|
||||
world_ps_.init();
|
||||
world_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
|
||||
world_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
DRW_STATE_DEPTH_EQUAL);
|
||||
world_ps_.material_set(manager, gpumat);
|
||||
world_ps_.push_constant("world_opacity_fade", background_opacity);
|
||||
world_ps_.push_constant("world_background_blur", square_f(background_blur));
|
||||
@@ -289,9 +290,9 @@ void ForwardPipeline::sync()
|
||||
has_opaque_ = false;
|
||||
has_transparent_ = false;
|
||||
|
||||
DRWState state_depth_only = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
DRWState state_depth_color = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS |
|
||||
DRW_STATE_WRITE_COLOR;
|
||||
DRWState state_depth_only = DRW_STATE_WRITE_DEPTH | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
inst_.film.depth.test_state;
|
||||
DRWState state_depth_color = state_depth_only | DRW_STATE_WRITE_COLOR;
|
||||
{
|
||||
prepass_ps_.init();
|
||||
|
||||
@@ -332,11 +333,12 @@ void ForwardPipeline::sync()
|
||||
}
|
||||
|
||||
opaque_single_sided_ps_ = &opaque_ps_.sub("SingleSided");
|
||||
opaque_single_sided_ps_->state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL |
|
||||
DRW_STATE_CULL_BACK);
|
||||
opaque_single_sided_ps_->state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
DRW_STATE_DEPTH_EQUAL | DRW_STATE_CULL_BACK);
|
||||
|
||||
opaque_double_sided_ps_ = &opaque_ps_.sub("DoubleSided");
|
||||
opaque_double_sided_ps_->state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
|
||||
opaque_double_sided_ps_->state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
DRW_STATE_DEPTH_EQUAL);
|
||||
}
|
||||
{
|
||||
transparent_ps_.init();
|
||||
@@ -399,7 +401,8 @@ PassMain::Sub *ForwardPipeline::prepass_transparent_add(const Object *ob,
|
||||
if ((blender_mat->blend_flag & MA_BL_HIDE_BACKFACE) == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
|
||||
DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
inst_.film.depth.test_state;
|
||||
if (blender_mat->blend_flag & MA_BL_CULL_BACKFACE) {
|
||||
state |= DRW_STATE_CULL_BACK;
|
||||
}
|
||||
@@ -415,7 +418,8 @@ PassMain::Sub *ForwardPipeline::material_transparent_add(const Object *ob,
|
||||
::Material *blender_mat,
|
||||
GPUMaterial *gpumat)
|
||||
{
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM | DRW_STATE_DEPTH_LESS_EQUAL;
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM |
|
||||
DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state;
|
||||
if (blender_mat->blend_flag & MA_BL_CULL_BACKFACE) {
|
||||
state |= DRW_STATE_CULL_BACK;
|
||||
}
|
||||
@@ -502,7 +506,7 @@ void DeferredLayerBase::gbuffer_pass_sync(Instance &inst)
|
||||
gbuffer_ps_.bind_resources(inst.volume_probes);
|
||||
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_WRITE_STENCIL |
|
||||
DRW_STATE_STENCIL_ALWAYS;
|
||||
DRW_STATE_CLIP_CONTROL_UNIT_RANGE | DRW_STATE_STENCIL_ALWAYS;
|
||||
|
||||
gbuffer_single_sided_hybrid_ps_ = &gbuffer_ps_.sub("DoubleSided");
|
||||
gbuffer_single_sided_hybrid_ps_->state_set(state | DRW_STATE_CULL_BACK);
|
||||
@@ -536,9 +540,10 @@ void DeferredLayer::begin_sync()
|
||||
prepass_ps_.bind_resources(inst_.velocity);
|
||||
prepass_ps_.bind_resources(inst_.sampling);
|
||||
|
||||
DRWState state_depth_only = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
DRWState state_depth_color = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS |
|
||||
DRW_STATE_WRITE_COLOR;
|
||||
DRWState state_depth_only = DRW_STATE_WRITE_DEPTH | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
inst_.film.depth.test_state;
|
||||
DRWState state_depth_color = DRW_STATE_WRITE_DEPTH | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
inst_.film.depth.test_state | DRW_STATE_WRITE_COLOR;
|
||||
|
||||
prepass_double_sided_static_ps_ = &prepass_ps_.sub("DoubleSided.Static");
|
||||
prepass_double_sided_static_ps_->state_set(state_depth_only);
|
||||
@@ -1252,7 +1257,8 @@ void DeferredProbePipeline::begin_sync()
|
||||
pass.bind_resources(inst_.sampling);
|
||||
}
|
||||
|
||||
DRWState state_depth_only = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
DRWState state_depth_only = DRW_STATE_WRITE_DEPTH | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
inst_.film.depth.test_state;
|
||||
/* Only setting up static pass because we don't use motion vectors for light-probes. */
|
||||
opaque_layer_.prepass_double_sided_static_ps_ = &pass.sub("DoubleSided");
|
||||
opaque_layer_.prepass_double_sided_static_ps_->state_set(state_depth_only);
|
||||
@@ -1365,7 +1371,8 @@ void PlanarProbePipeline::begin_sync()
|
||||
prepass_ps_.bind_resources(inst_.uniform_data);
|
||||
prepass_ps_.bind_resources(inst_.sampling);
|
||||
|
||||
DRWState state_depth_only = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
DRWState state_depth_only = DRW_STATE_WRITE_DEPTH | DRW_STATE_CLIP_CONTROL_UNIT_RANGE |
|
||||
inst_.film.depth.test_state;
|
||||
|
||||
prepass_double_sided_static_ps_ = &prepass_ps_.sub("DoubleSided.Static");
|
||||
prepass_double_sided_static_ps_->state_set(state_depth_only);
|
||||
@@ -1447,7 +1454,7 @@ void PlanarProbePipeline::render(View &view,
|
||||
inst_.uniform_data.push_update();
|
||||
|
||||
GPU_framebuffer_bind(gbuffer_fb);
|
||||
GPU_framebuffer_clear_depth(gbuffer_fb, 1.0f);
|
||||
GPU_framebuffer_clear_depth(gbuffer_fb, inst_.film.depth.clear_value);
|
||||
inst_.manager->submit(prepass_ps_, view);
|
||||
|
||||
/* TODO(fclem): This is the only place where we use the layer source to HiZ.
|
||||
|
||||
@@ -66,10 +66,10 @@ void RenderBuffers::acquire(int2 extent)
|
||||
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
|
||||
|
||||
/* Depth and combined are always needed. */
|
||||
depth_tx.ensure_2d(GPU_DEPTH24_STENCIL8, extent, usage);
|
||||
depth_tx.ensure_2d(GPU_DEPTH32F_STENCIL8, extent, usage);
|
||||
/* TODO(fclem): depth_tx should ideally be a texture from pool but we need stencil_view
|
||||
* which is currently unsupported by pool textures. */
|
||||
// depth_tx.acquire(extent, GPU_DEPTH24_STENCIL8);
|
||||
// depth_tx.acquire(extent, GPU_DEPTH32F_STENCIL8);
|
||||
combined_tx.acquire(extent, color_format);
|
||||
|
||||
eGPUTextureUsage usage_attachment_read_write = GPU_TEXTURE_USAGE_ATTACHMENT |
|
||||
|
||||
@@ -639,12 +639,8 @@ void ShaderModule::material_create_info_amend(GPUMaterial *gpumat, GPUCodegenOut
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 /* Waiting for using DRW_STATE_CLIP_CONTROL_UNIT_RANGE where these are used. */
|
||||
if (geometry_type != MAT_GEOM_WORLD) {
|
||||
/* Allow to use Reverse-Z on OpenGL. Does nothing in other backend. */
|
||||
info.builtins(BuiltinBits::CLIP_CONTROL);
|
||||
}
|
||||
#endif
|
||||
/* Allow to use Reverse-Z on OpenGL. Does nothing in other backend. */
|
||||
info.builtins(BuiltinBits::CLIP_CONTROL);
|
||||
|
||||
std::stringstream global_vars;
|
||||
switch (geometry_type) {
|
||||
|
||||
@@ -1128,7 +1128,7 @@ void ShadowModule::debug_end_sync()
|
||||
return;
|
||||
}
|
||||
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL |
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | inst_.film.depth.test_state |
|
||||
DRW_STATE_BLEND_CUSTOM;
|
||||
|
||||
debug_draw_ps_.state_set(state);
|
||||
|
||||
@@ -118,7 +118,7 @@ void ShadingView::render()
|
||||
/* Alpha stores transmittance. So start at 1. */
|
||||
float4 clear_color = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
GPU_framebuffer_bind(combined_fb_);
|
||||
GPU_framebuffer_clear_color_depth(combined_fb_, clear_color, 1.0f);
|
||||
GPU_framebuffer_clear_color_depth(combined_fb_, clear_color, inst_.film.depth.clear_value);
|
||||
inst_.pipelines.background.clear(render_view_);
|
||||
|
||||
/* TODO(fclem): Move it after the first prepass (and hiz update) once pipeline is stabilized. */
|
||||
@@ -366,7 +366,8 @@ void CaptureView::render_probes()
|
||||
GPU_ATTACHMENT_TEXTURE_LAYER(inst_.gbuffer.closure_tx.layer_view(1), 0));
|
||||
|
||||
GPU_framebuffer_bind(combined_fb_);
|
||||
GPU_framebuffer_clear_color_depth(combined_fb_, float4(0.0f, 0.0f, 0.0f, 1.0f), 1.0f);
|
||||
GPU_framebuffer_clear_color_depth(
|
||||
combined_fb_, float4(0.0f, 0.0f, 0.0f, 1.0f), inst_.film.depth.clear_value);
|
||||
inst_.pipelines.probe.render(view, prepass_fb, combined_fb_, gbuffer_fb_, extent);
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ void VolumeModule::end_sync()
|
||||
|
||||
eGPUTextureUsage front_depth_usage = GPU_TEXTURE_USAGE_SHADER_READ |
|
||||
GPU_TEXTURE_USAGE_ATTACHMENT;
|
||||
front_depth_tx_.ensure_2d(GPU_DEPTH24_STENCIL8, data_.tex_size.xy(), front_depth_usage);
|
||||
front_depth_tx_.ensure_2d(GPU_DEPTH32F_STENCIL8, data_.tex_size.xy(), front_depth_usage);
|
||||
occupancy_fb_.ensure(GPU_ATTACHMENT_TEXTURE(front_depth_tx_));
|
||||
|
||||
bool created = false;
|
||||
|
||||
@@ -194,6 +194,7 @@ set(SRC_GLSL_LIB
|
||||
eevee_ray_trace_screen_lib.glsl
|
||||
eevee_ray_types_lib.glsl
|
||||
eevee_renderpass_lib.glsl
|
||||
eevee_reverse_z_lib.glsl
|
||||
eevee_sampling_lib.glsl
|
||||
eevee_shadow_lib.glsl
|
||||
eevee_shadow_page_ops_lib.glsl
|
||||
|
||||
@@ -20,6 +20,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_depth_of_field_gather)
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_colorspace_lib.glsl"
|
||||
#include "eevee_depth_of_field_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
#include "gpu_shader_debug_gradients_lib.glsl"
|
||||
#include "gpu_shader_math_matrix_lib.glsl"
|
||||
@@ -644,7 +645,7 @@ void dof_slight_focus_gather(sampler2DDepth depth_tx,
|
||||
float2 sample_offset = ((i == 0) ? offset : -offset);
|
||||
/* OPTI: could precompute the factor. */
|
||||
float2 sample_uv = (frag_coord + sample_offset) / float2(textureSize(depth_tx, 0));
|
||||
float depth = textureLod(depth_tx, sample_uv, 0.0f).r;
|
||||
float depth = reverse_z::read(textureLod(depth_tx, sample_uv, 0.0f).r);
|
||||
pair_data[i].coc = dof_coc_from_depth(dof_buf, sample_uv, depth);
|
||||
pair_data[i].color = colorspace_safe_color(textureLod(color_tx, sample_uv, 0.0f));
|
||||
pair_data[i].dist = ring_dist;
|
||||
@@ -684,7 +685,7 @@ void dof_slight_focus_gather(sampler2DDepth depth_tx,
|
||||
DofGatherData center_data;
|
||||
center_data.color = colorspace_safe_color(textureLod(color_tx, sample_uv, 0.0f));
|
||||
center_data.coc = dof_coc_from_depth(
|
||||
dof_buf, sample_uv, textureLod(depth_tx, sample_uv, 0.0f).r);
|
||||
dof_buf, sample_uv, reverse_z::read(textureLod(depth_tx, sample_uv, 0.0f).r));
|
||||
center_data.coc = clamp(center_data.coc, -dof_buf.coc_abs_max, dof_buf.coc_abs_max);
|
||||
center_data.dist = 0.0f;
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ float dof_slight_focus_coc_tile_get(float2 frag_coord)
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float2 sample_uv = (frag_coord + quad_offsets[i] * 2.0f * dof_max_slight_focus_radius) /
|
||||
float2(textureSize(color_tx, 0));
|
||||
float coc = dof_coc_from_depth(dof_buf, sample_uv, textureLod(depth_tx, sample_uv, 0.0f).r);
|
||||
float depth = reverse_z::read(textureLod(depth_tx, sample_uv, 0.0f).r);
|
||||
float coc = dof_coc_from_depth(dof_buf, sample_uv, depth);
|
||||
coc = clamp(coc, -dof_buf.coc_abs_max, dof_buf.coc_abs_max);
|
||||
if (abs(coc) < dof_max_slight_focus_radius) {
|
||||
local_abs_max = max(local_abs_max, abs(coc));
|
||||
@@ -142,7 +143,8 @@ void main()
|
||||
}
|
||||
|
||||
if (prediction.do_focus) {
|
||||
float center_coc = (dof_coc_from_depth(dof_buf, uv, textureLod(depth_tx, uv, 0.0f).r));
|
||||
float depth = reverse_z::read(textureLod(depth_tx, uv, 0.0f).r);
|
||||
float center_coc = (dof_coc_from_depth(dof_buf, uv, depth));
|
||||
prediction.do_focus = abs(center_coc) <= 0.5f;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_depth_of_field_setup)
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_colorspace_lib.glsl"
|
||||
#include "eevee_depth_of_field_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
|
||||
void main()
|
||||
@@ -33,9 +34,10 @@ void main()
|
||||
float4 cocs;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float2 sample_uv = quad_center + quad_offsets[i] * fullres_texel_size;
|
||||
float depth = reverse_z::read(textureLod(depth_tx, sample_uv, 0.0f).r);
|
||||
/* NOTE: We use samplers without filtering. */
|
||||
colors[i] = colorspace_safe_color(textureLod(color_tx, sample_uv, 0.0f));
|
||||
cocs[i] = dof_coc_from_depth(dof_buf, sample_uv, textureLod(depth_tx, sample_uv, 0.0f).r);
|
||||
cocs[i] = dof_coc_from_depth(dof_buf, sample_uv, depth);
|
||||
}
|
||||
|
||||
cocs = clamp(cocs, -dof_buf.coc_abs_max, dof_buf.coc_abs_max);
|
||||
|
||||
@@ -23,6 +23,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_depth_of_field_stabilize)
|
||||
|
||||
#include "eevee_colorspace_lib.glsl"
|
||||
#include "eevee_depth_of_field_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_velocity_lib.glsl"
|
||||
|
||||
struct DofSample {
|
||||
@@ -87,7 +88,8 @@ void dof_cache_init()
|
||||
/* Depth is full-resolution. Load every 2 pixels. */
|
||||
int2 load_texel = clamp((texel + offset - 2) * 2, int2(0), textureSize(depth_tx, 0) - 1);
|
||||
|
||||
depth_cache[cache_texel.y][cache_texel.x] = texelFetch(depth_tx, load_texel, 0).x;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, load_texel, 0).x);
|
||||
depth_cache[cache_texel.y][cache_texel.x] = depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ FRAGMENT_SHADER_CREATE_INFO(eevee_display_lightprobe_planar)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_lightprobe_sphere_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
|
||||
float2 sampling_uv(float2 screen_uv)
|
||||
{
|
||||
@@ -19,7 +20,7 @@ float2 sampling_uv(float2 screen_uv)
|
||||
void main()
|
||||
{
|
||||
float2 uv = gl_FragCoord.xy / float2(textureSize(planar_radiance_tx, 0).xy);
|
||||
float depth = texture(planar_depth_tx, float3(sampling_uv(uv), probe_index)).r;
|
||||
float depth = reverse_z::read(texture(planar_depth_tx, float3(sampling_uv(uv), probe_index)).r);
|
||||
if (depth == 1.0f) {
|
||||
float3 ndc = drw_screen_to_ndc(float3(uv, 0.0f));
|
||||
float3 wP = drw_point_ndc_to_world(ndc);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
VERTEX_SHADER_CREATE_INFO(eevee_display_lightprobe_planar)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "gpu_shader_math_matrix_lib.glsl"
|
||||
|
||||
void main()
|
||||
@@ -33,4 +34,5 @@ void main()
|
||||
gl_Position = drw_point_world_to_homogenous(P);
|
||||
/* Small bias to let the probe draw without Z-fighting. */
|
||||
gl_Position.z -= 0.0001f;
|
||||
gl_Position = reverse_z::transform(gl_Position);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_display_lightprobe_sphere)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_lightprobe_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -36,4 +37,5 @@ void main()
|
||||
gl_Position = drw_point_view_to_homogenous(vP);
|
||||
/* Small bias to let the icon draw without Z-fighting. */
|
||||
gl_Position.z += 0.0001f;
|
||||
gl_Position = reverse_z::transform(gl_Position);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_display_lightprobe_volume)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_lightprobe_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -44,4 +45,5 @@ void main()
|
||||
gl_Position = drw_point_view_to_homogenous(vP);
|
||||
/* Small bias to let the icon draw without Z-fighting. */
|
||||
gl_Position.z += 0.0001f;
|
||||
gl_Position = reverse_z::transform(gl_Position);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ SHADER_LIBRARY_CREATE_INFO(eevee_film)
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_colorspace_lib.glsl"
|
||||
#include "eevee_cryptomatte_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_velocity_lib.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
|
||||
@@ -145,7 +146,7 @@ void film_sample_accum_mist(FilmSample samp, inout float accum)
|
||||
if (uniform_buf.film.mist_id == -1) {
|
||||
return;
|
||||
}
|
||||
float depth = texelFetch(depth_tx, samp.texel, 0).x;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, samp.texel, 0).x);
|
||||
float2 uv = (float2(samp.texel) + 0.5f) / float2(textureSize(depth_tx, 0).xy);
|
||||
float3 vP = drw_point_screen_to_view(float3(uv, depth));
|
||||
bool is_persp = drw_view().winmat[3][3] == 0.0f;
|
||||
@@ -252,11 +253,11 @@ float2 film_pixel_history_motion_vector(int2 texel_sample)
|
||||
* "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014 (Slide 27)
|
||||
*/
|
||||
constexpr int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2));
|
||||
float min_depth = texelFetch(depth_tx, texel_sample, 0).x;
|
||||
float min_depth = reverse_z::read(texelFetch(depth_tx, texel_sample, 0).x);
|
||||
int2 nearest_texel = texel_sample;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int2 texel = clamp(texel_sample + corners[i], int2(0), textureSize(depth_tx, 0).xy - 1);
|
||||
float depth = texelFetch(depth_tx, texel, 0).x;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel, 0).x);
|
||||
if (min_depth > depth) {
|
||||
min_depth = depth;
|
||||
nearest_texel = texel;
|
||||
@@ -679,7 +680,7 @@ void film_process_data(int2 texel_film, out float4 out_color, out float out_dept
|
||||
|
||||
/* Using film weight as distance to the pixel. So the check is inverted. */
|
||||
if (film_sample.weight > film_distance) {
|
||||
float depth = texelFetch(depth_tx, film_sample.texel, 0).x;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, film_sample.texel, 0).x);
|
||||
float4 vector = velocity_resolve(vector_tx, film_sample.texel, depth);
|
||||
/* Transform to pixel space, matching Cycles format. */
|
||||
vector *= float4(float2(uniform_buf.film.render_extent),
|
||||
|
||||
@@ -11,6 +11,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_geom_curves)
|
||||
#include "draw_model_lib.glsl"
|
||||
#include "eevee_attributes_curves_lib.glsl"
|
||||
#include "eevee_nodetree_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_surf_lib.glsl"
|
||||
#include "eevee_velocity_lib.glsl"
|
||||
|
||||
@@ -69,5 +70,5 @@ void main()
|
||||
shadow_clip.vector = shadow_clip_vector_get(vs_P, view.clip_distance_inv);
|
||||
#endif
|
||||
|
||||
gl_Position = drw_point_world_to_homogenous(interp.P);
|
||||
gl_Position = reverse_z::transform(drw_point_world_to_homogenous(interp.P));
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_geom_gpencil)
|
||||
#include "draw_grease_pencil_lib.glsl"
|
||||
#include "draw_model_lib.glsl"
|
||||
#include "eevee_attributes_gpencil_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_surf_lib.glsl"
|
||||
#include "eevee_velocity_lib.glsl"
|
||||
|
||||
@@ -67,4 +68,6 @@ void main()
|
||||
shadow_clip.position = shadow_position_vector_get(vs_P, view);
|
||||
shadow_clip.vector = shadow_clip_vector_get(vs_P, view.clip_distance_inv);
|
||||
#endif
|
||||
|
||||
gl_Position = reverse_z::transform(gl_Position);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_geom_mesh)
|
||||
#include "draw_model_lib.glsl"
|
||||
#include "eevee_attributes_mesh_lib.glsl"
|
||||
#include "eevee_nodetree_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_surf_lib.glsl"
|
||||
#include "eevee_velocity_lib.glsl"
|
||||
|
||||
@@ -51,5 +52,5 @@ void main()
|
||||
shadow_clip.vector = shadow_clip_vector_get(vs_P, view.clip_distance_inv);
|
||||
#endif
|
||||
|
||||
gl_Position = drw_point_world_to_homogenous(interp.P);
|
||||
gl_Position = reverse_z::transform(drw_point_world_to_homogenous(interp.P));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_geom_pointcloud)
|
||||
#include "draw_pointcloud_lib.glsl"
|
||||
#include "eevee_attributes_pointcloud_lib.glsl"
|
||||
#include "eevee_nodetree_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_surf_lib.glsl"
|
||||
#include "eevee_velocity_lib.glsl"
|
||||
#include "gpu_shader_math_rotation_lib.glsl"
|
||||
@@ -61,5 +62,5 @@ void main()
|
||||
shadow_clip.vector = shadow_clip_vector_get(vs_P, view.clip_distance_inv);
|
||||
#endif
|
||||
|
||||
gl_Position = drw_point_world_to_homogenous(interp.P);
|
||||
gl_Position = reverse_z::transform(drw_point_world_to_homogenous(interp.P));
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_geom_volume)
|
||||
|
||||
#include "draw_model_lib.glsl"
|
||||
#include "draw_object_infos_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_surf_lib.glsl"
|
||||
|
||||
void main()
|
||||
@@ -26,5 +27,5 @@ void main()
|
||||
float3 lP = loc + pos * size;
|
||||
interp.P = drw_point_object_to_world(lP);
|
||||
|
||||
gl_Position = drw_point_world_to_homogenous(interp.P);
|
||||
gl_Position = reverse_z::transform(drw_point_world_to_homogenous(interp.P));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ VERTEX_SHADER_CREATE_INFO(eevee_geom_world)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_nodetree_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_surf_lib.glsl"
|
||||
|
||||
void main()
|
||||
@@ -28,4 +29,6 @@ void main()
|
||||
/* Pass view position to keep accuracy. */
|
||||
interp.P = drw_point_ndc_to_view(gl_Position.xyz);
|
||||
interp.N = float3(1);
|
||||
|
||||
gl_Position = reverse_z::transform(gl_Position);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
COMPUTE_SHADER_CREATE_INFO(eevee_hiz_update)
|
||||
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
|
||||
shared float local_depths[gl_WorkGroupSize.y][gl_WorkGroupSize.x];
|
||||
@@ -56,6 +57,8 @@ void main()
|
||||
float4 samp = textureGather(depth_tx, samp_co);
|
||||
#endif
|
||||
|
||||
samp = reverse_z::read(samp);
|
||||
|
||||
if (update_mip_0) {
|
||||
imageStoreFast(out_mip_0, src_px + int2(0, 1), samp.xxxx);
|
||||
imageStoreFast(out_mip_0, src_px + int2(1, 1), samp.yyyy);
|
||||
|
||||
@@ -11,6 +11,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_horizon_resolve)
|
||||
#include "eevee_filter_lib.glsl"
|
||||
#include "eevee_gbuffer_lib.glsl"
|
||||
#include "eevee_lightprobe_eval_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
#include "gpu_shader_utildefines_lib.glsl"
|
||||
@@ -30,7 +31,7 @@ float sample_weight_get(float3 center_N, float3 center_P, int2 center_texel, int
|
||||
float2 sample_uv = (float2(sample_texel_fullres) + 0.5f) *
|
||||
uniform_buf.raytrace.full_resolution_inv;
|
||||
|
||||
float sample_depth = texelFetch(depth_tx, sample_texel_fullres, 0).r;
|
||||
float sample_depth = reverse_z::read(texelFetch(depth_tx, sample_texel_fullres, 0).r);
|
||||
|
||||
bool is_valid;
|
||||
float3 sample_N = sample_normal_get(sample_texel, is_valid);
|
||||
@@ -88,7 +89,7 @@ void main()
|
||||
}
|
||||
|
||||
float2 center_uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv;
|
||||
float center_depth = texelFetch(depth_tx, texel_fullres, 0).r;
|
||||
float center_depth = reverse_z::read(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float3 center_P = drw_point_screen_to_world(float3(center_uv, center_depth));
|
||||
float3 center_N = gbuf.surface_N;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_horizon_setup)
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_colorspace_lib.glsl"
|
||||
#include "eevee_gbuffer_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "gpu_shader_math_matrix_lib.glsl"
|
||||
|
||||
void main()
|
||||
@@ -51,7 +52,7 @@ void main()
|
||||
|
||||
/* Re-project radiance. */
|
||||
float2 uv = (float2(texel_fullres) + 0.5f) / float2(textureSize(depth_tx, 0).xy);
|
||||
float depth = texelFetch(depth_tx, texel_fullres, 0).r;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float3 P = drw_point_screen_to_world(float3(uv, depth));
|
||||
|
||||
float3 ssP_prev = drw_ndc_to_screen(project_point(uniform_buf.raytrace.radiance_persmat, P));
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
COMPUTE_SHADER_CREATE_INFO(eevee_motion_blur_tiles_flatten_rgba)
|
||||
|
||||
#include "draw_math_geom_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_velocity_lib.glsl"
|
||||
|
||||
shared uint payload_prev;
|
||||
@@ -56,7 +57,7 @@ void main()
|
||||
|
||||
float2 render_size = float2(imageSize(velocity_img).xy);
|
||||
float2 uv = (float2(texel) + 0.5f) / render_size;
|
||||
float depth = texelFetch(depth_tx, texel, 0).r;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel, 0).r);
|
||||
float4 motion = velocity_resolve(imageLoad(velocity_img, texel), uv, depth);
|
||||
#ifdef FLATTEN_RG
|
||||
/* imageLoad does not perform the swizzling like sampler does. Do it manually. */
|
||||
|
||||
@@ -19,6 +19,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_motion_blur_gather)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_motion_blur_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
#include "eevee_velocity_lib.glsl"
|
||||
|
||||
@@ -86,7 +87,7 @@ void gather_sample(float2 screen_uv,
|
||||
float4 sample_vectors = motion_blur_sample_velocity(velocity_tx, sample_uv);
|
||||
float2 sample_motion = (next) ? sample_vectors.zw : sample_vectors.xy;
|
||||
float sample_motion_len = length(sample_motion);
|
||||
float sample_depth = texture(depth_tx, sample_uv).r;
|
||||
float sample_depth = reverse_z::read(textureLod(depth_tx, sample_uv, 0.0f).r);
|
||||
float4 sample_color = textureLod(in_color_tx, sample_uv, 0.0f);
|
||||
|
||||
sample_depth = drw_depth_screen_to_view(sample_depth);
|
||||
@@ -164,7 +165,8 @@ void main()
|
||||
}
|
||||
|
||||
/* Data of the center pixel of the gather (target). */
|
||||
float center_depth = drw_depth_screen_to_view(texelFetch(depth_tx, texel, 0).r);
|
||||
float center_depth = reverse_z::read(texelFetch(depth_tx, texel, 0).r);
|
||||
center_depth = drw_depth_screen_to_view(center_depth);
|
||||
float4 center_motion = motion_blur_sample_velocity(velocity_tx, uv);
|
||||
|
||||
float4 center_color = textureLod(in_color_tx, uv, 0.0f);
|
||||
|
||||
@@ -23,6 +23,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_denoise_bilateral)
|
||||
#include "eevee_closure_lib.glsl"
|
||||
#include "eevee_filter_lib.glsl"
|
||||
#include "eevee_gbuffer_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
#include "gpu_shader_codegen_lib.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
@@ -45,7 +46,7 @@ void main()
|
||||
int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);
|
||||
float2 center_uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv;
|
||||
|
||||
float center_depth = texelFetch(depth_tx, texel_fullres, 0).r;
|
||||
float center_depth = reverse_z::read(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float3 center_P = drw_point_screen_to_world(float3(center_uv, center_depth));
|
||||
|
||||
ClosureUndetermined center_closure = gbuffer_read_bin(
|
||||
@@ -97,7 +98,7 @@ void main()
|
||||
continue;
|
||||
}
|
||||
|
||||
float sample_depth = texelFetch(depth_tx, sample_texel, 0).r;
|
||||
float sample_depth = reverse_z::read(texelFetch(depth_tx, sample_texel, 0).r);
|
||||
float2 sample_uv = (float2(sample_texel) + 0.5f) * uniform_buf.raytrace.full_resolution_inv;
|
||||
float3 sample_P = drw_point_screen_to_world(float3(sample_uv, sample_depth));
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_denoise_spatial)
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_closure_lib.glsl"
|
||||
#include "eevee_gbuffer_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
#include "gpu_shader_codegen_lib.glsl"
|
||||
#include "gpu_shader_utildefines_lib.glsl"
|
||||
@@ -173,7 +174,8 @@ void main()
|
||||
float3 rgb_variance = abs(rgb_moment - square(rgb_mean));
|
||||
float hit_variance = reduce_max(rgb_variance);
|
||||
|
||||
float scene_z = drw_depth_screen_to_view(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float scene_z = drw_depth_screen_to_view(depth);
|
||||
float hit_depth = drw_depth_view_to_screen(scene_z - closest_hit_time);
|
||||
|
||||
imageStoreFast(out_radiance_img, texel_fullres, float4(radiance_accum, 0.0f));
|
||||
|
||||
@@ -21,6 +21,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_denoise_temporal)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_colorspace_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "gpu_shader_codegen_lib.glsl"
|
||||
#include "gpu_shader_math_matrix_lib.glsl"
|
||||
#include "gpu_shader_utildefines_lib.glsl"
|
||||
@@ -194,7 +195,7 @@ void main()
|
||||
|
||||
/* Surface reprojection. */
|
||||
/* TODO(fclem): Use per pixel velocity. Is this worth it? */
|
||||
float scene_depth = texelFetch(depth_tx, texel_fullres, 0).r;
|
||||
float scene_depth = reverse_z::read(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float3 P = drw_point_screen_to_world(float3(uv, scene_depth));
|
||||
float4 history_radiance = radiance_history_sample(P, local);
|
||||
/* Reflection reprojection. */
|
||||
|
||||
@@ -16,6 +16,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_fallback)
|
||||
#include "eevee_lightprobe_eval_lib.glsl"
|
||||
#include "eevee_ray_trace_screen_lib.glsl"
|
||||
#include "eevee_ray_types_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
#include "eevee_spherical_harmonics_lib.glsl"
|
||||
|
||||
@@ -34,7 +35,7 @@ void main()
|
||||
return;
|
||||
}
|
||||
|
||||
float depth = texelFetch(depth_tx, texel_fullres, 0).r;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float2 uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv;
|
||||
|
||||
float4 ray_data_im = imageLoadFast(ray_data_img, texel);
|
||||
|
||||
@@ -19,6 +19,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_planar)
|
||||
#include "eevee_lightprobe_eval_lib.glsl"
|
||||
#include "eevee_ray_trace_screen_lib.glsl"
|
||||
#include "eevee_ray_types_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
|
||||
void main()
|
||||
@@ -56,7 +57,7 @@ void main()
|
||||
return;
|
||||
}
|
||||
|
||||
float depth = texelFetch(depth_tx, texel_fullres, 0).r;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float2 uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv;
|
||||
|
||||
float3 P = drw_point_screen_to_world(float3(uv, depth));
|
||||
|
||||
@@ -17,6 +17,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_screen)
|
||||
#include "eevee_lightprobe_eval_lib.glsl"
|
||||
#include "eevee_ray_trace_screen_lib.glsl"
|
||||
#include "eevee_ray_types_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
#include "eevee_spherical_harmonics_lib.glsl"
|
||||
|
||||
@@ -60,7 +61,7 @@ void main()
|
||||
is_reflection = false;
|
||||
}
|
||||
|
||||
float depth = texelFetch(depth_tx, texel_fullres, 0).r;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel_fullres, 0).r);
|
||||
float2 uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv;
|
||||
|
||||
float3 P = drw_point_screen_to_world(float3(uv, depth));
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "eevee_bxdf_diffuse_lib.glsl"
|
||||
#include "eevee_bxdf_microfacet_lib.glsl"
|
||||
#include "eevee_ray_types_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_thickness_lib.glsl"
|
||||
#include "gpu_shader_codegen_lib.glsl"
|
||||
#include "gpu_shader_math_fast_lib.glsl"
|
||||
@@ -186,7 +187,8 @@ ScreenTraceHitData raytrace_planar(RayTraceData rt_data,
|
||||
ScreenSpaceRay ssray = raytrace_screenspace_ray_create(ray, 2.0f * inv_texture_size);
|
||||
|
||||
float prev_delta = 0.0f, prev_time = 0.0f;
|
||||
float depth_sample = texture(planar_depth_tx, float3(ssray.origin.xy, planar.layer_id)).r;
|
||||
float depth_sample = reverse_z::read(
|
||||
texture(planar_depth_tx, float3(ssray.origin.xy, planar.layer_id)).r);
|
||||
float delta = depth_sample - ssray.origin.z;
|
||||
|
||||
float t = 0.0f, time = 0.0f;
|
||||
@@ -203,7 +205,7 @@ ScreenTraceHitData raytrace_planar(RayTraceData rt_data,
|
||||
|
||||
float4 ss_ray = ssray.origin + ssray.direction * time;
|
||||
|
||||
depth_sample = texture(planar_depth_tx, float3(ss_ray.xy, planar.layer_id)).r;
|
||||
depth_sample = reverse_z::read(texture(planar_depth_tx, float3(ss_ray.xy, planar.layer_id)).r);
|
||||
|
||||
delta = depth_sample - ss_ray.z;
|
||||
/* Check if the ray is below the surface. */
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Reverse-Z utils functions.
|
||||
*
|
||||
* We only modify the depth buffer content so we need to change the vertex Z position and modify
|
||||
* every depth buffer read. This keeps the projection matrices the same as the rest of blender.
|
||||
*/
|
||||
#include "gpu_glsl_cpp_stubs.hh"
|
||||
|
||||
namespace reverse_z {
|
||||
|
||||
/* Needs to be called at the end of the vertex entry point function. */
|
||||
float4 transform(float4 hs_position)
|
||||
{
|
||||
#ifdef GPU_ARB_clip_control
|
||||
/* Remapping from -1..1 to 1..-1. The scaling to 0..1 is handled by the backend. */
|
||||
hs_position.z = -hs_position.z;
|
||||
#endif
|
||||
return hs_position;
|
||||
}
|
||||
|
||||
/* NOTE: Cannot put the ifdef inside the template because of template as macro. */
|
||||
#ifdef GPU_ARB_clip_control
|
||||
/* Needs to be called for every depth buffer read, but not for the HiZ.
|
||||
* The HiZ buffer is already reversed back before downsample. */
|
||||
template<typename T> T read(T depth_buffer_value)
|
||||
{
|
||||
/* Remapping from 0..1 to 1..0. The scaling to 0..1 is handled as normal by drw_screen_to_ndc. */
|
||||
return 1.0f - depth_buffer_value;
|
||||
}
|
||||
template float read<float>(float);
|
||||
template float4 read<float4>(float4);
|
||||
#else
|
||||
template<typename T> T read(T depth_buffer_value)
|
||||
{
|
||||
/* Passthrough. */
|
||||
return depth_buffer_value;
|
||||
}
|
||||
template float read<float>(float);
|
||||
template float4 read<float4>(float4);
|
||||
#endif
|
||||
|
||||
} // namespace reverse_z
|
||||
@@ -19,6 +19,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_subsurface_convolve)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_gbuffer_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "eevee_sampling_lib.glsl"
|
||||
#include "gpu_shader_codegen_lib.glsl"
|
||||
#include "gpu_shader_math_matrix_lib.glsl"
|
||||
@@ -49,7 +50,7 @@ void cache_populate(float2 local_uv)
|
||||
uint2 texel = gl_LocalInvocationID.xy;
|
||||
cached_radiance[texel.y][texel.x] = texture(radiance_tx, local_uv).rgb;
|
||||
cached_sss_id[texel.y][texel.x] = texture(object_id_tx, local_uv).r;
|
||||
cached_depth[texel.y][texel.x] = texture(depth_tx, local_uv).r;
|
||||
cached_depth[texel.y][texel.x] = reverse_z::read(texture(depth_tx, local_uv).r);
|
||||
}
|
||||
|
||||
bool cache_sample(uint2 texel, out SubSurfaceSample samp)
|
||||
@@ -76,7 +77,7 @@ SubSurfaceSample sample_neighborhood(float2 sample_uv)
|
||||
return samp;
|
||||
}
|
||||
#endif
|
||||
samp.depth = texture(depth_tx, sample_uv).r;
|
||||
samp.depth = reverse_z::read(texture(depth_tx, sample_uv).r);
|
||||
samp.sss_id = texture(object_id_tx, sample_uv).r;
|
||||
samp.radiance = texture(radiance_tx, sample_uv).rgb;
|
||||
return samp;
|
||||
@@ -94,7 +95,7 @@ void main()
|
||||
cache_populate(center_uv);
|
||||
#endif
|
||||
|
||||
float depth = texelFetch(depth_tx, texel, 0).r;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel, 0).r);
|
||||
float3 vP = drw_point_screen_to_view(float3(center_uv, depth));
|
||||
|
||||
GBufferReader gbuf = gbuffer_read(gbuf_header_tx, gbuf_closure_tx, gbuf_normal_tx, texel);
|
||||
|
||||
@@ -13,6 +13,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_subsurface_setup)
|
||||
|
||||
#include "draw_view_lib.glsl"
|
||||
#include "eevee_gbuffer_lib.glsl"
|
||||
#include "eevee_reverse_z_lib.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
#include "gpu_shader_shared_exponent_lib.glsl"
|
||||
|
||||
@@ -42,7 +43,7 @@ void main()
|
||||
imageStoreFast(radiance_img, texel, float4(radiance, 0.0f));
|
||||
imageStoreFast(object_id_img, texel, uint4(object_id));
|
||||
|
||||
float depth = texelFetch(depth_tx, texel, 0).r;
|
||||
float depth = reverse_z::read(texelFetch(depth_tx, texel, 0).r);
|
||||
/* TODO(fclem): Check if this simplifies. */
|
||||
float vPz = drw_depth_screen_to_view(depth);
|
||||
float homcoord = drw_view().winmat[2][3] * vPz + drw_view().winmat[3][3];
|
||||
|
||||
@@ -98,6 +98,7 @@ VERTEX_SOURCE("eevee_display_lightprobe_sphere_vert.glsl")
|
||||
VERTEX_OUT(eevee_display_lightprobe_sphere_iface)
|
||||
FRAGMENT_SOURCE("eevee_display_lightprobe_sphere_frag.glsl")
|
||||
FRAGMENT_OUT(0, float4, out_color)
|
||||
BUILTINS(BuiltinBits::CLIP_CONTROL)
|
||||
DO_STATIC_COMPILATION()
|
||||
GPU_SHADER_CREATE_END()
|
||||
|
||||
@@ -117,6 +118,7 @@ VERTEX_SOURCE("eevee_display_lightprobe_planar_vert.glsl")
|
||||
VERTEX_OUT(eevee_display_lightprobe_planar_iface)
|
||||
FRAGMENT_SOURCE("eevee_display_lightprobe_planar_frag.glsl")
|
||||
FRAGMENT_OUT(0, float4, out_color)
|
||||
BUILTINS(BuiltinBits::CLIP_CONTROL)
|
||||
DO_STATIC_COMPILATION()
|
||||
GPU_SHADER_CREATE_END()
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ FRAGMENT_OUT(0, float4, out_color)
|
||||
STORAGE_BUF(0, read, Surfel, surfels_buf[])
|
||||
PUSH_CONSTANT(float, debug_surfel_radius)
|
||||
PUSH_CONSTANT(int, debug_mode)
|
||||
BUILTINS(BuiltinBits::CLIP_CONTROL)
|
||||
DO_STATIC_COMPILATION()
|
||||
GPU_SHADER_CREATE_END()
|
||||
|
||||
@@ -54,6 +55,7 @@ PUSH_CONSTANT(int, debug_mode)
|
||||
PUSH_CONSTANT(float, debug_value)
|
||||
VERTEX_SOURCE("eevee_debug_irradiance_grid_vert.glsl")
|
||||
FRAGMENT_SOURCE("eevee_debug_irradiance_grid_frag.glsl")
|
||||
BUILTINS(BuiltinBits::CLIP_CONTROL)
|
||||
DO_STATIC_COMPILATION()
|
||||
GPU_SHADER_CREATE_END()
|
||||
|
||||
@@ -79,6 +81,7 @@ SAMPLER(1, sampler3D, irradiance_b_tx)
|
||||
SAMPLER(2, sampler3D, irradiance_c_tx)
|
||||
SAMPLER(3, sampler3D, irradiance_d_tx)
|
||||
SAMPLER(4, sampler3D, validity_tx)
|
||||
BUILTINS(BuiltinBits::CLIP_CONTROL)
|
||||
DO_STATIC_COMPILATION()
|
||||
GPU_SHADER_CREATE_END()
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ bool GPU_geometry_shader_support();
|
||||
bool GPU_shader_draw_parameters_support();
|
||||
bool GPU_hdr_support();
|
||||
bool GPU_stencil_export_support();
|
||||
bool GPU_clip_control_support();
|
||||
|
||||
bool GPU_mem_stats_supported();
|
||||
void GPU_mem_stats_get(int *r_totalmem, int *r_freemem);
|
||||
|
||||
@@ -202,6 +202,11 @@ bool GPU_stencil_export_support()
|
||||
return GCaps.stencil_export_support;
|
||||
}
|
||||
|
||||
bool GPU_clip_control_support()
|
||||
{
|
||||
return GCaps.clip_control_support;
|
||||
}
|
||||
|
||||
int GPU_max_shader_storage_buffer_bindings()
|
||||
{
|
||||
return GCaps.max_shader_storage_buffer_bindings;
|
||||
|
||||
@@ -49,6 +49,7 @@ struct GPUCapabilities {
|
||||
bool shader_draw_parameters_support = false;
|
||||
bool hdr_viewport_support = false;
|
||||
bool stencil_export_support = false;
|
||||
bool clip_control_support = false;
|
||||
|
||||
int max_parallel_compilations = -1;
|
||||
|
||||
|
||||
@@ -552,6 +552,7 @@ void MTLBackend::capabilities_init(MTLContext *ctx)
|
||||
GCaps.max_work_group_size[2] = max_threads_per_threadgroup_per_dim;
|
||||
|
||||
GCaps.stencil_export_support = true;
|
||||
GCaps.clip_control_support = true;
|
||||
|
||||
/* OPENGL Related workarounds -- none needed for Metal. */
|
||||
GCaps.extensions_len = 0;
|
||||
|
||||
@@ -399,6 +399,7 @@ bool MTLShader::generate_msl_from_glsl(const shader::ShaderCreateInfo *info)
|
||||
* from GLSL to MSL. Also include additional GPU defines for
|
||||
* optional high-level feature support. */
|
||||
std::string msl_defines_string = "#define GPU_ARB_shader_draw_parameters 1\n";
|
||||
msl_defines_string += "#define GPU_ARB_clip_control 1\n";
|
||||
|
||||
/* NOTE(Metal): textureGather appears to not function correctly on non-Apple-silicon GPUs.
|
||||
* Manifests as selection outlines not showing up (#103412). Disable texture gather if
|
||||
@@ -869,6 +870,7 @@ bool MTLShader::generate_msl_from_glsl_compute(const shader::ShaderCreateInfo *i
|
||||
ss_compute << "#line " STRINGIFY(__LINE__) " \"" __FILE__ "\"" << std::endl;
|
||||
|
||||
ss_compute << "#define GPU_ARB_shader_draw_parameters 1\n";
|
||||
ss_compute << "#define GPU_ARB_clip_control 1\n";
|
||||
if (bool(info->builtins_ & BuiltinBits::TEXTURE_ATOMIC) &&
|
||||
MTLBackend::get_capabilities().supports_texture_atomics)
|
||||
{
|
||||
|
||||
@@ -429,6 +429,7 @@ static void detect_workarounds()
|
||||
GLContext::framebuffer_fetch_support = false;
|
||||
GLContext::texture_barrier_support = false;
|
||||
GCaps.stencil_export_support = false;
|
||||
GCaps.clip_control_support = false;
|
||||
|
||||
#if 0
|
||||
/* Do not alter OpenGL 4.3 features.
|
||||
@@ -714,6 +715,8 @@ void GLBackend::capabilities_init()
|
||||
"GL_EXT_texture_filter_anisotropic");
|
||||
GLContext::clip_control_support = epoxy_has_gl_extension("GL_ARB_clip_control");
|
||||
|
||||
GCaps.clip_control_support = GLContext::clip_control_support;
|
||||
|
||||
/* Disabled until it is proven to work. */
|
||||
GLContext::framebuffer_fetch_support = false;
|
||||
|
||||
|
||||
@@ -1050,6 +1050,9 @@ static StringRefNull glsl_patch_vertex_get()
|
||||
if (GLContext::native_barycentric_support) {
|
||||
ss << "#extension GL_AMD_shader_explicit_vertex_parameter: enable\n";
|
||||
}
|
||||
if (GLContext::clip_control_support) {
|
||||
ss << "#define GPU_ARB_clip_control\n";
|
||||
}
|
||||
|
||||
/* Fallbacks. */
|
||||
if (!GLContext::shader_draw_parameters_support) {
|
||||
@@ -1086,6 +1089,9 @@ static StringRefNull glsl_patch_geometry_get()
|
||||
if (GLContext::native_barycentric_support) {
|
||||
ss << "#extension GL_AMD_shader_explicit_vertex_parameter: enable\n";
|
||||
}
|
||||
if (GLContext::clip_control_support) {
|
||||
ss << "#define GPU_ARB_clip_control\n";
|
||||
}
|
||||
|
||||
/* Array compatibility. */
|
||||
ss << "#define gpu_Array(_type) _type[]\n";
|
||||
@@ -1121,6 +1127,9 @@ static StringRefNull glsl_patch_fragment_get()
|
||||
ss << "#extension GL_ARB_shader_stencil_export: enable\n";
|
||||
ss << "#define GPU_ARB_shader_stencil_export\n";
|
||||
}
|
||||
if (GLContext::clip_control_support) {
|
||||
ss << "#define GPU_ARB_clip_control\n";
|
||||
}
|
||||
|
||||
/* Array compatibility. */
|
||||
ss << "#define gpu_Array(_type) _type[]\n";
|
||||
@@ -1149,6 +1158,10 @@ static StringRefNull glsl_patch_compute_get()
|
||||
/* Needs to have this defined upfront for configuring shader defines. */
|
||||
ss << "#define GPU_COMPUTE_SHADER\n";
|
||||
|
||||
if (GLContext::clip_control_support) {
|
||||
ss << "#define GPU_ARB_clip_control\n";
|
||||
}
|
||||
|
||||
ss << datatoc_glsl_shader_defines_glsl;
|
||||
|
||||
return ss.str();
|
||||
|
||||
@@ -619,6 +619,7 @@ void VKBackend::capabilities_init(VKDevice &device)
|
||||
/* Reset all capabilities from previous context. */
|
||||
GCaps = {};
|
||||
GCaps.geometry_shader_support = true;
|
||||
GCaps.clip_control_support = true;
|
||||
GCaps.stencil_export_support = device.supports_extension(
|
||||
VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME);
|
||||
GCaps.shader_draw_parameters_support =
|
||||
|
||||
@@ -315,6 +315,7 @@ void VKDevice::init_glsl_patch()
|
||||
ss << "#define GPU_ARB_shader_draw_parameters\n";
|
||||
ss << "#define gpu_BaseInstance (gl_BaseInstanceARB)\n";
|
||||
}
|
||||
ss << "#define GPU_ARB_clip_control\n";
|
||||
|
||||
ss << "#define gl_VertexID gl_VertexIndex\n";
|
||||
ss << "#define gpu_InstanceIndex (gl_InstanceIndex)\n";
|
||||
|
||||
Reference in New Issue
Block a user