Use Reverse Z for the depth buffer
This commit is contained in:
parent
f47f4a02c8
commit
d950f5f838
|
@ -719,7 +719,8 @@ Projection Projection::operator*(const Projection &p_matrix) const {
|
||||||
return new_matrix;
|
return new_matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Projection::set_depth_correction(bool p_flip_y) {
|
void Projection::set_depth_correction(bool p_flip_y, bool p_reverse_z, bool p_remap_z) {
|
||||||
|
// p_remap_z is used to convert from OpenGL-style clip space (-1 - 1) to Vulkan style (0 - 1).
|
||||||
real_t *m = &columns[0][0];
|
real_t *m = &columns[0][0];
|
||||||
|
|
||||||
m[0] = 1;
|
m[0] = 1;
|
||||||
|
@ -732,11 +733,11 @@ void Projection::set_depth_correction(bool p_flip_y) {
|
||||||
m[7] = 0.0;
|
m[7] = 0.0;
|
||||||
m[8] = 0.0;
|
m[8] = 0.0;
|
||||||
m[9] = 0.0;
|
m[9] = 0.0;
|
||||||
m[10] = 0.5;
|
m[10] = p_remap_z ? (p_reverse_z ? -0.5 : 0.5) : (p_reverse_z ? -1.0 : 1.0);
|
||||||
m[11] = 0.0;
|
m[11] = 0.0;
|
||||||
m[12] = 0.0;
|
m[12] = 0.0;
|
||||||
m[13] = 0.0;
|
m[13] = 0.0;
|
||||||
m[14] = 0.5;
|
m[14] = p_remap_z ? 0.5 : 0.0;
|
||||||
m[15] = 1.0;
|
m[15] = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ struct _NO_DISCARD_ Projection {
|
||||||
void set_identity();
|
void set_identity();
|
||||||
void set_zero();
|
void set_zero();
|
||||||
void set_light_bias();
|
void set_light_bias();
|
||||||
void set_depth_correction(bool p_flip_y = true);
|
void set_depth_correction(bool p_flip_y = true, bool p_reverse_z = true, bool p_remap_z = true);
|
||||||
|
|
||||||
void set_light_atlas_rect(const Rect2 &p_rect);
|
void set_light_atlas_rect(const Rect2 &p_rect);
|
||||||
void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov = false);
|
void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov = false);
|
||||||
|
|
|
@ -823,6 +823,11 @@ void RasterizerSceneGLES3::_draw_sky(RID p_env, const Projection &p_projection,
|
||||||
} else {
|
} else {
|
||||||
camera = p_projection;
|
camera = p_projection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Projection correction;
|
||||||
|
correction.set_depth_correction(false, true, false);
|
||||||
|
camera = correction * camera;
|
||||||
|
|
||||||
Basis sky_transform = environment_get_sky_orientation(p_env);
|
Basis sky_transform = environment_get_sky_orientation(p_env);
|
||||||
sky_transform.invert();
|
sky_transform.invert();
|
||||||
sky_transform = sky_transform * p_transform.basis;
|
sky_transform = sky_transform * p_transform.basis;
|
||||||
|
@ -933,7 +938,7 @@ void RasterizerSceneGLES3::_update_sky_radiance(RID p_env, const Projection &p_p
|
||||||
Projection cm;
|
Projection cm;
|
||||||
cm.set_perspective(90, 1, 0.01, 10.0);
|
cm.set_perspective(90, 1, 0.01, 10.0);
|
||||||
Projection correction;
|
Projection correction;
|
||||||
correction.columns[1][1] = -1.0;
|
correction.set_depth_correction(true, true, false);
|
||||||
cm = correction * cm;
|
cm = correction * cm;
|
||||||
|
|
||||||
bool success = material_storage->shaders.sky_shader.version_bind_shader(shader_data->version, SkyShaderGLES3::MODE_CUBEMAP);
|
bool success = material_storage->shaders.sky_shader.version_bind_shader(shader_data->version, SkyShaderGLES3::MODE_CUBEMAP);
|
||||||
|
@ -1546,7 +1551,7 @@ void RasterizerSceneGLES3::_fill_render_list(RenderListType p_render_list, const
|
||||||
// Needs to be called after _setup_lights so that directional_light_count is accurate.
|
// Needs to be called after _setup_lights so that directional_light_count is accurate.
|
||||||
void RasterizerSceneGLES3::_setup_environment(const RenderDataGLES3 *p_render_data, bool p_no_fog, const Size2i &p_screen_size, bool p_flip_y, const Color &p_default_bg_color, bool p_pancake_shadows, float p_shadow_bias) {
|
void RasterizerSceneGLES3::_setup_environment(const RenderDataGLES3 *p_render_data, bool p_no_fog, const Size2i &p_screen_size, bool p_flip_y, const Color &p_default_bg_color, bool p_pancake_shadows, float p_shadow_bias) {
|
||||||
Projection correction;
|
Projection correction;
|
||||||
correction.columns[1][1] = p_flip_y ? -1.0 : 1.0;
|
correction.set_depth_correction(p_flip_y, true, false);
|
||||||
Projection projection = correction * p_render_data->cam_projection;
|
Projection projection = correction * p_render_data->cam_projection;
|
||||||
//store camera into ubo
|
//store camera into ubo
|
||||||
GLES3::MaterialStorage::store_camera(projection, scene_state.ubo.projection_matrix);
|
GLES3::MaterialStorage::store_camera(projection, scene_state.ubo.projection_matrix);
|
||||||
|
@ -1801,7 +1806,9 @@ void RasterizerSceneGLES3::_setup_lights(const RenderDataGLES3 *p_render_data, b
|
||||||
shadow_data.blend_splits = uint32_t((shadow_mode != RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL) && light_storage->light_directional_get_blend_splits(base));
|
shadow_data.blend_splits = uint32_t((shadow_mode != RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL) && light_storage->light_directional_get_blend_splits(base));
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
Rect2 atlas_rect = li->shadow_transform[j].atlas_rect;
|
Rect2 atlas_rect = li->shadow_transform[j].atlas_rect;
|
||||||
Projection matrix = li->shadow_transform[j].camera;
|
Projection correction;
|
||||||
|
correction.set_depth_correction(false, true, false);
|
||||||
|
Projection matrix = correction * li->shadow_transform[j].camera;
|
||||||
float split = li->shadow_transform[MIN(limit, j)].split;
|
float split = li->shadow_transform[MIN(limit, j)].split;
|
||||||
|
|
||||||
Projection bias;
|
Projection bias;
|
||||||
|
@ -2027,7 +2034,9 @@ void RasterizerSceneGLES3::_setup_lights(const RenderDataGLES3 *p_render_data, b
|
||||||
Projection bias;
|
Projection bias;
|
||||||
bias.set_light_bias();
|
bias.set_light_bias();
|
||||||
|
|
||||||
Projection cm = li->shadow_transform[0].camera;
|
Projection correction;
|
||||||
|
correction.set_depth_correction(false, true, false);
|
||||||
|
Projection cm = correction * li->shadow_transform[0].camera;
|
||||||
Projection shadow_mtx = bias * cm * modelview;
|
Projection shadow_mtx = bias * cm * modelview;
|
||||||
GLES3::MaterialStorage::store_camera(shadow_mtx, shadow_data.shadow_matrix);
|
GLES3::MaterialStorage::store_camera(shadow_mtx, shadow_data.shadow_matrix);
|
||||||
}
|
}
|
||||||
|
@ -2274,11 +2283,11 @@ void RasterizerSceneGLES3::_render_shadow_pass(RID p_light, RID p_shadow_atlas,
|
||||||
scene_state.reset_gl_state();
|
scene_state.reset_gl_state();
|
||||||
scene_state.enable_gl_depth_test(true);
|
scene_state.enable_gl_depth_test(true);
|
||||||
scene_state.enable_gl_depth_draw(true);
|
scene_state.enable_gl_depth_draw(true);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_GREATER);
|
||||||
|
|
||||||
glColorMask(0, 0, 0, 0);
|
glColorMask(0, 0, 0, 0);
|
||||||
glDrawBuffers(0, nullptr);
|
glDrawBuffers(0, nullptr);
|
||||||
RasterizerGLES3::clear_depth(1.0);
|
RasterizerGLES3::clear_depth(0.0);
|
||||||
if (needs_clear) {
|
if (needs_clear) {
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
@ -2515,7 +2524,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
|
||||||
Projection projection = render_data.cam_projection;
|
Projection projection = render_data.cam_projection;
|
||||||
if (render_data.reflection_probe.is_valid()) {
|
if (render_data.reflection_probe.is_valid()) {
|
||||||
Projection correction;
|
Projection correction;
|
||||||
correction.columns[1][1] = -1.0;
|
correction.set_depth_correction(true, true, false);
|
||||||
projection = correction * render_data.cam_projection;
|
projection = correction * render_data.cam_projection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2554,11 +2563,11 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
|
||||||
scene_state.enable_gl_depth_test(true);
|
scene_state.enable_gl_depth_test(true);
|
||||||
scene_state.enable_gl_depth_draw(true);
|
scene_state.enable_gl_depth_draw(true);
|
||||||
scene_state.enable_gl_blend(false);
|
scene_state.enable_gl_blend(false);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_GEQUAL);
|
||||||
scene_state.enable_gl_scissor_test(false);
|
scene_state.enable_gl_scissor_test(false);
|
||||||
|
|
||||||
glColorMask(0, 0, 0, 0);
|
glColorMask(0, 0, 0, 0);
|
||||||
RasterizerGLES3::clear_depth(1.0);
|
RasterizerGLES3::clear_depth(0.0);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
glDrawBuffers(0, nullptr);
|
glDrawBuffers(0, nullptr);
|
||||||
|
|
||||||
|
@ -2590,7 +2599,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
|
||||||
scene_state.enable_gl_scissor_test(false);
|
scene_state.enable_gl_scissor_test(false);
|
||||||
scene_state.enable_gl_depth_test(true);
|
scene_state.enable_gl_depth_test(true);
|
||||||
scene_state.enable_gl_depth_draw(true);
|
scene_state.enable_gl_depth_draw(true);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_GEQUAL);
|
||||||
|
|
||||||
{
|
{
|
||||||
GLuint db = GL_COLOR_ATTACHMENT0;
|
GLuint db = GL_COLOR_ATTACHMENT0;
|
||||||
|
@ -2598,7 +2607,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fb_cleared) {
|
if (!fb_cleared) {
|
||||||
RasterizerGLES3::clear_depth(1.0);
|
RasterizerGLES3::clear_depth(0.0);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3559,12 +3568,12 @@ void RasterizerSceneGLES3::render_particle_collider_heightfield(RID p_collider,
|
||||||
scene_state.reset_gl_state();
|
scene_state.reset_gl_state();
|
||||||
scene_state.enable_gl_depth_test(true);
|
scene_state.enable_gl_depth_test(true);
|
||||||
scene_state.enable_gl_depth_draw(true);
|
scene_state.enable_gl_depth_draw(true);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_GREATER);
|
||||||
|
|
||||||
glDrawBuffers(0, nullptr);
|
glDrawBuffers(0, nullptr);
|
||||||
|
|
||||||
glColorMask(0, 0, 0, 0);
|
glColorMask(0, 0, 0, 0);
|
||||||
RasterizerGLES3::clear_depth(1.0);
|
RasterizerGLES3::clear_depth(0.0);
|
||||||
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
@ -3605,7 +3614,7 @@ void RasterizerSceneGLES3::_render_uv2(const PagedArray<RenderGeometryInstance *
|
||||||
scene_state.reset_gl_state();
|
scene_state.reset_gl_state();
|
||||||
scene_state.enable_gl_depth_test(true);
|
scene_state.enable_gl_depth_test(true);
|
||||||
scene_state.enable_gl_depth_draw(true);
|
scene_state.enable_gl_depth_draw(true);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_GREATER);
|
||||||
|
|
||||||
TightLocalVector<GLenum> draw_buffers;
|
TightLocalVector<GLenum> draw_buffers;
|
||||||
draw_buffers.push_back(GL_COLOR_ATTACHMENT0);
|
draw_buffers.push_back(GL_COLOR_ATTACHMENT0);
|
||||||
|
@ -3738,7 +3747,7 @@ void RasterizerSceneGLES3::_render_buffers_debug_draw(Ref<RenderSceneBuffersGLES
|
||||||
copy_effects->copy_cube_to_rect(atlas_uv_rect);
|
copy_effects->copy_cube_to_rect(atlas_uv_rect);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, shadow_tex);
|
glBindTexture(GL_TEXTURE_2D, shadow_tex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||||
|
@ -3746,7 +3755,7 @@ void RasterizerSceneGLES3::_render_buffers_debug_draw(Ref<RenderSceneBuffersGLES
|
||||||
copy_effects->copy_to_rect(atlas_uv_rect);
|
copy_effects->copy_to_rect(atlas_uv_rect);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3782,7 +3791,7 @@ void RasterizerSceneGLES3::_render_buffers_debug_draw(Ref<RenderSceneBuffersGLES
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,6 @@ void main() {
|
||||||
float depth_fix = 1.0 / dot(normal, unorm);
|
float depth_fix = 1.0 / dot(normal, unorm);
|
||||||
|
|
||||||
depth = 2.0 * depth - 1.0;
|
depth = 2.0 * depth - 1.0;
|
||||||
float linear_depth = 2.0 * z_near * z_far / (z_far + z_near - depth * (z_far - z_near));
|
float linear_depth = 2.0 * z_near * z_far / (z_far + z_near + depth * (z_far - z_near));
|
||||||
gl_FragDepth = (linear_depth * depth_fix + bias) / z_far;
|
gl_FragDepth = (z_far - (linear_depth * depth_fix + bias)) / z_far;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1710,7 +1710,7 @@ void main() {
|
||||||
#ifdef MODE_RENDER_DEPTH
|
#ifdef MODE_RENDER_DEPTH
|
||||||
#ifdef RENDER_SHADOWS_LINEAR
|
#ifdef RENDER_SHADOWS_LINEAR
|
||||||
// Linearize the depth buffer if rendering cubemap shadows.
|
// Linearize the depth buffer if rendering cubemap shadows.
|
||||||
gl_FragDepth = (length(vertex) + scene_data.shadow_bias) / scene_data.z_far;
|
gl_FragDepth = (scene_data.z_far - (length(vertex) + scene_data.shadow_bias)) / scene_data.z_far;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Nothing happens, so a tree-ssa optimizer will result in no fragment shader :)
|
// Nothing happens, so a tree-ssa optimizer will result in no fragment shader :)
|
||||||
|
@ -1914,7 +1914,7 @@ void main() {
|
||||||
float omni_shadow = 1.0f;
|
float omni_shadow = 1.0f;
|
||||||
#ifndef SHADOWS_DISABLED
|
#ifndef SHADOWS_DISABLED
|
||||||
vec3 light_ray = ((positional_shadows[positional_shadow_index].shadow_matrix * vec4(shadow_coord.xyz, 1.0))).xyz;
|
vec3 light_ray = ((positional_shadows[positional_shadow_index].shadow_matrix * vec4(shadow_coord.xyz, 1.0))).xyz;
|
||||||
omni_shadow = texture(omni_shadow_texture, vec4(light_ray, length(light_ray) * omni_lights[omni_light_index].inv_radius));
|
omni_shadow = texture(omni_shadow_texture, vec4(light_ray, 1.0 - length(light_ray) * omni_lights[omni_light_index].inv_radius));
|
||||||
omni_shadow = mix(1.0, omni_shadow, omni_lights[omni_light_index].shadow_opacity);
|
omni_shadow = mix(1.0, omni_shadow, omni_lights[omni_light_index].shadow_opacity);
|
||||||
#endif // SHADOWS_DISABLED
|
#endif // SHADOWS_DISABLED
|
||||||
light_process_omni(omni_light_index, vertex, view, normal, f0, roughness, metallic, omni_shadow, albedo, alpha,
|
light_process_omni(omni_light_index, vertex, view, normal, f0, roughness, metallic, omni_shadow, albedo, alpha,
|
||||||
|
|
|
@ -28,7 +28,7 @@ void main() {
|
||||||
// We're doing clockwise culling so flip the order
|
// We're doing clockwise culling so flip the order
|
||||||
uv_interp = vec2(vertex_attrib.x, vertex_attrib.y * -1.0);
|
uv_interp = vec2(vertex_attrib.x, vertex_attrib.y * -1.0);
|
||||||
#endif
|
#endif
|
||||||
gl_Position = vec4(uv_interp, 1.0, 1.0);
|
gl_Position = vec4(uv_interp, -1.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
@ -139,9 +139,11 @@ void main() {
|
||||||
vec3 cube_normal;
|
vec3 cube_normal;
|
||||||
#ifdef USE_MULTIVIEW
|
#ifdef USE_MULTIVIEW
|
||||||
// In multiview our projection matrices will contain positional and rotational offsets that we need to properly unproject.
|
// In multiview our projection matrices will contain positional and rotational offsets that we need to properly unproject.
|
||||||
vec4 unproject = vec4(uv_interp.x, uv_interp.y, 1.0, 1.0);
|
vec4 unproject = vec4(uv_interp.xy, -1.0, 1.0); // unproject at the far plane
|
||||||
vec4 unprojected = multiview_data.inv_projection_matrix_view[ViewIndex] * unproject;
|
vec4 unprojected = multiview_data.inv_projection_matrix_view[ViewIndex] * unproject;
|
||||||
cube_normal = unprojected.xyz / unprojected.w;
|
cube_normal = unprojected.xyz / unprojected.w;
|
||||||
|
|
||||||
|
// Unproject will give us the position between the eyes, need to re-offset.
|
||||||
cube_normal += multiview_data.eye_offset[ViewIndex].xyz;
|
cube_normal += multiview_data.eye_offset[ViewIndex].xyz;
|
||||||
#else
|
#else
|
||||||
cube_normal.z = -1.0;
|
cube_normal.z = -1.0;
|
||||||
|
|
|
@ -1020,7 +1020,7 @@ bool LightStorage::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_i
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X, texture_id, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X, texture_id, 0);
|
||||||
|
|
||||||
|
@ -1042,7 +1042,7 @@ bool LightStorage::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_i
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture_id, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture_id, 0);
|
||||||
|
|
||||||
|
@ -1128,14 +1128,14 @@ void LightStorage::update_directional_shadow_atlas() {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, directional_shadow.depth, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, directional_shadow.depth, 0);
|
||||||
}
|
}
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, directional_shadow.fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, directional_shadow.fbo);
|
||||||
RasterizerGLES3::clear_depth(1.0);
|
RasterizerGLES3::clear_depth(0.0);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
|
@ -1077,7 +1077,7 @@ Ref<Image> TextureStorage::texture_2d_get(RID p_texture) const {
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_GEQUAL);
|
||||||
glColorMask(1, 1, 1, 1);
|
glColorMask(1, 1, 1, 1);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->tex_id);
|
glBindTexture(GL_TEXTURE_2D, texture->tex_id);
|
||||||
|
|
|
@ -583,7 +583,7 @@ void CopyEffects::copy_to_fb_rect(RID p_source_rd_texture, RID p_dest_framebuffe
|
||||||
RID shader = copy_to_fb.shader.version_get_shader(copy_to_fb.shader_version, mode);
|
RID shader = copy_to_fb.shader.version_get_shader(copy_to_fb.shader_version, mode);
|
||||||
ERR_FAIL_COND(shader.is_null());
|
ERR_FAIL_COND(shader.is_null());
|
||||||
|
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, p_rect);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 0.0, 0, p_rect);
|
||||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, copy_to_fb.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
|
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, copy_to_fb.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
|
||||||
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
|
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
|
||||||
if (p_secondary.is_valid()) {
|
if (p_secondary.is_valid()) {
|
||||||
|
@ -982,7 +982,7 @@ void CopyEffects::set_color_raster(RID p_dest_texture, const Color &p_color, con
|
||||||
RID shader = copy_to_fb.shader.version_get_shader(copy_to_fb.shader_version, mode);
|
RID shader = copy_to_fb.shader.version_get_shader(copy_to_fb.shader_version, mode);
|
||||||
ERR_FAIL_COND(shader.is_null());
|
ERR_FAIL_COND(shader.is_null());
|
||||||
|
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(dest_framebuffer, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, p_region);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(dest_framebuffer, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 0.0, 0, p_region);
|
||||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, copy_to_fb.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(dest_framebuffer)));
|
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, copy_to_fb.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(dest_framebuffer)));
|
||||||
RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array());
|
RD::get_singleton()->draw_list_bind_index_array(draw_list, material_storage->get_quad_index_array());
|
||||||
RD::get_singleton()->draw_list_set_push_constant(draw_list, ©_to_fb.push_constant, sizeof(CopyToFbPushConstant));
|
RD::get_singleton()->draw_list_set_push_constant(draw_list, ©_to_fb.push_constant, sizeof(CopyToFbPushConstant));
|
||||||
|
|
|
@ -282,7 +282,7 @@ void DebugEffects::draw_shadow_frustum(RID p_light, const Projection &p_cam_proj
|
||||||
// And draw our frustum.
|
// And draw our frustum.
|
||||||
RD::FramebufferFormatID fb_format_id = RD::get_singleton()->framebuffer_get_format(p_dest_fb);
|
RD::FramebufferFormatID fb_format_id = RD::get_singleton()->framebuffer_get_format(p_dest_fb);
|
||||||
|
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_fb, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, rect);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_fb, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 0.0, 0, rect);
|
||||||
|
|
||||||
RID pipeline = shadow_frustum.pipelines[SFP_TRANSPARENT].get_render_pipeline(frustum.vertex_format, fb_format_id);
|
RID pipeline = shadow_frustum.pipelines[SFP_TRANSPARENT].get_render_pipeline(frustum.vertex_format, fb_format_id);
|
||||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, pipeline);
|
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, pipeline);
|
||||||
|
@ -326,7 +326,7 @@ void DebugEffects::draw_shadow_frustum(RID p_light, const Projection &p_cam_proj
|
||||||
rect.size.x *= atlas_rect_norm.size.x;
|
rect.size.x *= atlas_rect_norm.size.x;
|
||||||
rect.size.y *= atlas_rect_norm.size.y;
|
rect.size.y *= atlas_rect_norm.size.y;
|
||||||
|
|
||||||
draw_list = RD::get_singleton()->draw_list_begin(p_dest_fb, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, rect);
|
draw_list = RD::get_singleton()->draw_list_begin(p_dest_fb, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_LOAD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 0.0, 0, rect);
|
||||||
|
|
||||||
pipeline = shadow_frustum.pipelines[SFP_TRANSPARENT].get_render_pipeline(frustum.vertex_format, fb_format_id);
|
pipeline = shadow_frustum.pipelines[SFP_TRANSPARENT].get_render_pipeline(frustum.vertex_format, fb_format_id);
|
||||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, pipeline);
|
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, pipeline);
|
||||||
|
|
|
@ -527,6 +527,7 @@ FSR2Effect::FSR2Effect() {
|
||||||
"\n#define FFX_GLSL 1\n"
|
"\n#define FFX_GLSL 1\n"
|
||||||
"\n#define FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS 1\n"
|
"\n#define FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS 1\n"
|
||||||
"\n#define FFX_FSR2_OPTION_HDR_COLOR_INPUT 1\n"
|
"\n#define FFX_FSR2_OPTION_HDR_COLOR_INPUT 1\n"
|
||||||
|
"\n#define FFX_FSR2_OPTION_INVERTED_DEPTH 1\n"
|
||||||
"\n#define FFX_FSR2_OPTION_GODOT_REACTIVE_MASK_CLAMP 1\n"
|
"\n#define FFX_FSR2_OPTION_GODOT_REACTIVE_MASK_CLAMP 1\n"
|
||||||
"\n#define FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS 1\n";
|
"\n#define FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS 1\n";
|
||||||
|
|
||||||
|
@ -808,7 +809,7 @@ FSR2Effect::~FSR2Effect() {
|
||||||
|
|
||||||
FSR2Context *FSR2Effect::create_context(Size2i p_internal_size, Size2i p_target_size) {
|
FSR2Context *FSR2Effect::create_context(Size2i p_internal_size, Size2i p_target_size) {
|
||||||
FSR2Context *context = memnew(RendererRD::FSR2Context);
|
FSR2Context *context = memnew(RendererRD::FSR2Context);
|
||||||
context->fsr_desc.flags = FFX_FSR2_ENABLE_HIGH_DYNAMIC_RANGE;
|
context->fsr_desc.flags = FFX_FSR2_ENABLE_HIGH_DYNAMIC_RANGE | FFX_FSR2_ENABLE_DEPTH_INVERTED;
|
||||||
context->fsr_desc.maxRenderSize.width = p_internal_size.x;
|
context->fsr_desc.maxRenderSize.width = p_internal_size.x;
|
||||||
context->fsr_desc.maxRenderSize.height = p_internal_size.y;
|
context->fsr_desc.maxRenderSize.height = p_internal_size.y;
|
||||||
context->fsr_desc.displaySize.width = p_target_size.x;
|
context->fsr_desc.displaySize.width = p_target_size.x;
|
||||||
|
|
|
@ -483,8 +483,12 @@ void SSEffects::downsample_depth(Ref<RenderSceneBuffersRD> p_render_buffers, uin
|
||||||
downsample_uniform_set = uniform_set_cache->get_cache_vec(shader, 2, u_depths);
|
downsample_uniform_set = uniform_set_cache->get_cache_vec(shader, 2, u_depths);
|
||||||
}
|
}
|
||||||
|
|
||||||
float depth_linearize_mul = -p_projection.columns[3][2] * 0.5;
|
Projection correction;
|
||||||
float depth_linearize_add = p_projection.columns[2][2];
|
correction.set_depth_correction(false);
|
||||||
|
Projection temp = correction * p_projection;
|
||||||
|
|
||||||
|
float depth_linearize_mul = -temp.columns[3][2];
|
||||||
|
float depth_linearize_add = temp.columns[2][2];
|
||||||
if (depth_linearize_mul * depth_linearize_add < 0) {
|
if (depth_linearize_mul * depth_linearize_add < 0) {
|
||||||
depth_linearize_add = -depth_linearize_add;
|
depth_linearize_add = -depth_linearize_add;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3407,7 +3407,7 @@ void GI::init(SkyRD *p_sky) {
|
||||||
RD::PipelineDepthStencilState ds;
|
RD::PipelineDepthStencilState ds;
|
||||||
ds.enable_depth_test = true;
|
ds.enable_depth_test = true;
|
||||||
ds.enable_depth_write = true;
|
ds.enable_depth_write = true;
|
||||||
ds.depth_compare_operator = RD::COMPARE_OP_LESS_OR_EQUAL;
|
ds.depth_compare_operator = RD::COMPARE_OP_GREATER_OR_EQUAL;
|
||||||
|
|
||||||
voxel_gi_debug_shader_version_pipelines[i].setup(voxel_gi_debug_shader_version_shaders[i], RD::RENDER_PRIMITIVE_TRIANGLES, rs, RD::PipelineMultisampleState(), ds, RD::PipelineColorBlendState::create_disabled(), 0);
|
voxel_gi_debug_shader_version_pipelines[i].setup(voxel_gi_debug_shader_version_shaders[i], RD::RENDER_PRIMITIVE_TRIANGLES, rs, RD::PipelineMultisampleState(), ds, RD::PipelineColorBlendState::create_disabled(), 0);
|
||||||
}
|
}
|
||||||
|
@ -3575,7 +3575,7 @@ void GI::init(SkyRD *p_sky) {
|
||||||
RD::PipelineDepthStencilState ds;
|
RD::PipelineDepthStencilState ds;
|
||||||
ds.enable_depth_test = true;
|
ds.enable_depth_test = true;
|
||||||
ds.enable_depth_write = true;
|
ds.enable_depth_write = true;
|
||||||
ds.depth_compare_operator = RD::COMPARE_OP_LESS_OR_EQUAL;
|
ds.depth_compare_operator = RD::COMPARE_OP_GREATER_OR_EQUAL;
|
||||||
for (int i = 0; i < SDFGIShader::PROBE_DEBUG_MAX; i++) {
|
for (int i = 0; i < SDFGIShader::PROBE_DEBUG_MAX; i++) {
|
||||||
// TODO check if version is enabled
|
// TODO check if version is enabled
|
||||||
|
|
||||||
|
@ -3810,8 +3810,13 @@ void GI::process_gi(Ref<RenderSceneBuffersRD> p_render_buffers, const RID *p_nor
|
||||||
rbgi->scene_data_ubo = RD::get_singleton()->uniform_buffer_create(sizeof(SceneData));
|
rbgi->scene_data_ubo = RD::get_singleton()->uniform_buffer_create(sizeof(SceneData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Projection correction;
|
||||||
|
correction.set_depth_correction(false);
|
||||||
|
|
||||||
for (uint32_t v = 0; v < p_view_count; v++) {
|
for (uint32_t v = 0; v < p_view_count; v++) {
|
||||||
RendererRD::MaterialStorage::store_camera(p_projections[v].inverse(), scene_data.inv_projection[v]);
|
Projection temp = correction * p_projections[v];
|
||||||
|
|
||||||
|
RendererRD::MaterialStorage::store_camera(temp.inverse(), scene_data.inv_projection[v]);
|
||||||
scene_data.eye_offset[v][0] = p_eye_offsets[v].x;
|
scene_data.eye_offset[v][0] = p_eye_offsets[v].x;
|
||||||
scene_data.eye_offset[v][1] = p_eye_offsets[v].y;
|
scene_data.eye_offset[v][1] = p_eye_offsets[v].y;
|
||||||
scene_data.eye_offset[v][2] = p_eye_offsets[v].z;
|
scene_data.eye_offset[v][2] = p_eye_offsets[v].z;
|
||||||
|
|
|
@ -141,7 +141,7 @@ void SkyRD::SkyShaderData::set_code(const String &p_code) {
|
||||||
for (int i = 0; i < SKY_VERSION_MAX; i++) {
|
for (int i = 0; i < SKY_VERSION_MAX; i++) {
|
||||||
RD::PipelineDepthStencilState depth_stencil_state;
|
RD::PipelineDepthStencilState depth_stencil_state;
|
||||||
depth_stencil_state.enable_depth_test = true;
|
depth_stencil_state.enable_depth_test = true;
|
||||||
depth_stencil_state.depth_compare_operator = RD::COMPARE_OP_LESS_OR_EQUAL;
|
depth_stencil_state.depth_compare_operator = RD::COMPARE_OP_GREATER_OR_EQUAL;
|
||||||
|
|
||||||
if (scene_singleton->sky.sky_shader.shader.is_variant_enabled(i)) {
|
if (scene_singleton->sky.sky_shader.shader.is_variant_enabled(i)) {
|
||||||
RID shader_variant = scene_singleton->sky.sky_shader.shader.version_get_shader(version, i);
|
RID shader_variant = scene_singleton->sky.sky_shader.shader.version_get_shader(version, i);
|
||||||
|
@ -1174,6 +1174,7 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
||||||
}
|
}
|
||||||
|
|
||||||
Projection correction;
|
Projection correction;
|
||||||
|
correction.set_depth_correction(false, true);
|
||||||
correction.add_jitter_offset(p_jitter);
|
correction.add_jitter_offset(p_jitter);
|
||||||
|
|
||||||
sky_scene_state.view_count = p_view_count;
|
sky_scene_state.view_count = p_view_count;
|
||||||
|
@ -1184,10 +1185,12 @@ void SkyRD::setup_sky(RID p_env, Ref<RenderSceneBuffersRD> p_render_buffers, con
|
||||||
for (uint32_t i = 0; i < p_view_count; i++) {
|
for (uint32_t i = 0; i < p_view_count; i++) {
|
||||||
Projection view_inv_projection = (correction * p_view_projections[i]).inverse();
|
Projection view_inv_projection = (correction * p_view_projections[i]).inverse();
|
||||||
if (p_view_count > 1) {
|
if (p_view_count > 1) {
|
||||||
|
// Reprojection is used when we need to have things in combined space.
|
||||||
RendererRD::MaterialStorage::store_camera(p_cam_projection * view_inv_projection, sky_scene_state.ubo.combined_reprojection[i]);
|
RendererRD::MaterialStorage::store_camera(p_cam_projection * view_inv_projection, sky_scene_state.ubo.combined_reprojection[i]);
|
||||||
} else {
|
} else {
|
||||||
|
// This is unused so just reset to identity.
|
||||||
Projection ident;
|
Projection ident;
|
||||||
RendererRD::MaterialStorage::store_camera(correction, sky_scene_state.ubo.combined_reprojection[i]);
|
RendererRD::MaterialStorage::store_camera(ident, sky_scene_state.ubo.combined_reprojection[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
RendererRD::MaterialStorage::store_camera(view_inv_projection, sky_scene_state.ubo.view_inv_projections[i]);
|
RendererRD::MaterialStorage::store_camera(view_inv_projection, sky_scene_state.ubo.view_inv_projections[i]);
|
||||||
|
|
|
@ -2014,7 +2014,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
|
||||||
uint32_t opaque_color_pass_flags = using_motion_pass ? (color_pass_flags & ~COLOR_PASS_FLAG_MOTION_VECTORS) : color_pass_flags;
|
uint32_t opaque_color_pass_flags = using_motion_pass ? (color_pass_flags & ~COLOR_PASS_FLAG_MOTION_VECTORS) : color_pass_flags;
|
||||||
RID opaque_framebuffer = using_motion_pass ? rb_data->get_color_pass_fb(opaque_color_pass_flags) : color_framebuffer;
|
RID opaque_framebuffer = using_motion_pass ? rb_data->get_color_pass_fb(opaque_color_pass_flags) : color_framebuffer;
|
||||||
RenderListParameters render_list_params(render_list[RENDER_LIST_OPAQUE].elements.ptr(), render_list[RENDER_LIST_OPAQUE].element_info.ptr(), render_list[RENDER_LIST_OPAQUE].elements.size(), reverse_cull, PASS_MODE_COLOR, opaque_color_pass_flags, rb_data.is_null(), p_render_data->directional_light_soft_shadows, rp_uniform_set, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_WIREFRAME, Vector2(), p_render_data->scene_data->lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, p_render_data->scene_data->view_count, 0, spec_constant_base_flags);
|
RenderListParameters render_list_params(render_list[RENDER_LIST_OPAQUE].elements.ptr(), render_list[RENDER_LIST_OPAQUE].element_info.ptr(), render_list[RENDER_LIST_OPAQUE].elements.size(), reverse_cull, PASS_MODE_COLOR, opaque_color_pass_flags, rb_data.is_null(), p_render_data->directional_light_soft_shadows, rp_uniform_set, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_WIREFRAME, Vector2(), p_render_data->scene_data->lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, p_render_data->scene_data->view_count, 0, spec_constant_base_flags);
|
||||||
_render_list_with_draw_list(&render_list_params, opaque_framebuffer, load_color ? RD::INITIAL_ACTION_LOAD : RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, depth_pre_pass ? RD::INITIAL_ACTION_LOAD : RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, c, 1.0, 0);
|
_render_list_with_draw_list(&render_list_params, opaque_framebuffer, load_color ? RD::INITIAL_ACTION_LOAD : RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, depth_pre_pass ? RD::INITIAL_ACTION_LOAD : RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, c, 0.0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
RD::get_singleton()->draw_command_end_label();
|
RD::get_singleton()->draw_command_end_label();
|
||||||
|
@ -2629,7 +2629,7 @@ void RenderForwardClustered::_render_shadow_end() {
|
||||||
|
|
||||||
for (SceneState::ShadowPass &shadow_pass : scene_state.shadow_passes) {
|
for (SceneState::ShadowPass &shadow_pass : scene_state.shadow_passes) {
|
||||||
RenderListParameters render_list_parameters(render_list[RENDER_LIST_SECONDARY].elements.ptr() + shadow_pass.element_from, render_list[RENDER_LIST_SECONDARY].element_info.ptr() + shadow_pass.element_from, shadow_pass.element_count, shadow_pass.flip_cull, shadow_pass.pass_mode, 0, true, false, shadow_pass.rp_uniform_set, false, Vector2(), shadow_pass.lod_distance_multiplier, shadow_pass.screen_mesh_lod_threshold, 1, shadow_pass.element_from);
|
RenderListParameters render_list_parameters(render_list[RENDER_LIST_SECONDARY].elements.ptr() + shadow_pass.element_from, render_list[RENDER_LIST_SECONDARY].element_info.ptr() + shadow_pass.element_from, shadow_pass.element_count, shadow_pass.flip_cull, shadow_pass.pass_mode, 0, true, false, shadow_pass.rp_uniform_set, false, Vector2(), shadow_pass.lod_distance_multiplier, shadow_pass.screen_mesh_lod_threshold, 1, shadow_pass.element_from);
|
||||||
_render_list_with_draw_list(&render_list_parameters, shadow_pass.framebuffer, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, shadow_pass.initial_depth_action, RD::FINAL_ACTION_STORE, Vector<Color>(), 1.0, 0, shadow_pass.rect);
|
_render_list_with_draw_list(&render_list_parameters, shadow_pass.framebuffer, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, shadow_pass.initial_depth_action, RD::FINAL_ACTION_STORE, Vector<Color>(), 0.0, 0, shadow_pass.rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
RD::get_singleton()->draw_command_end_label();
|
RD::get_singleton()->draw_command_end_label();
|
||||||
|
@ -2729,7 +2729,7 @@ void RenderForwardClustered::_render_material(const Transform3D &p_cam_transform
|
||||||
Color(0, 0, 0, 0)
|
Color(0, 0, 0, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, clear, 1.0, 0, p_region);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, clear, 0.0, 0, p_region);
|
||||||
_render_list(draw_list, RD::get_singleton()->framebuffer_get_format(p_framebuffer), &render_list_params, 0, render_list_params.element_count);
|
_render_list(draw_list, RD::get_singleton()->framebuffer_get_format(p_framebuffer), &render_list_params, 0, render_list_params.element_count);
|
||||||
RD::get_singleton()->draw_list_end();
|
RD::get_singleton()->draw_list_end();
|
||||||
}
|
}
|
||||||
|
@ -2779,7 +2779,7 @@ void RenderForwardClustered::_render_uv2(const PagedArray<RenderGeometryInstance
|
||||||
Color(0, 0, 0, 0),
|
Color(0, 0, 0, 0),
|
||||||
Color(0, 0, 0, 0)
|
Color(0, 0, 0, 0)
|
||||||
};
|
};
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, clear, 1.0, 0, p_region);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, clear, 0.0, 0, p_region);
|
||||||
|
|
||||||
const int uv_offset_count = 9;
|
const int uv_offset_count = 9;
|
||||||
static const Vector2 uv_offsets[uv_offset_count] = {
|
static const Vector2 uv_offsets[uv_offset_count] = {
|
||||||
|
@ -2885,7 +2885,7 @@ void RenderForwardClustered::_render_sdfgi(Ref<RenderSceneBuffersRD> p_render_bu
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].element_info.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), true, pass_mode, 0, true, false, rp_uniform_set, false);
|
RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].element_info.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), true, pass_mode, 0, true, false, rp_uniform_set, false);
|
||||||
_render_list_with_draw_list(&render_list_params, E->value, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, Rect2());
|
_render_list_with_draw_list(&render_list_params, E->value, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 0.0, 0, Rect2());
|
||||||
}
|
}
|
||||||
|
|
||||||
RD::get_singleton()->draw_command_end_label();
|
RD::get_singleton()->draw_command_end_label();
|
||||||
|
@ -4265,7 +4265,7 @@ RenderForwardClustered::RenderForwardClustered() {
|
||||||
sampler.mag_filter = RD::SAMPLER_FILTER_NEAREST;
|
sampler.mag_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||||
sampler.min_filter = RD::SAMPLER_FILTER_NEAREST;
|
sampler.min_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||||
sampler.enable_compare = true;
|
sampler.enable_compare = true;
|
||||||
sampler.compare_op = RD::COMPARE_OP_LESS;
|
sampler.compare_op = RD::COMPARE_OP_GREATER;
|
||||||
shadow_sampler = RD::get_singleton()->sampler_create(sampler);
|
shadow_sampler = RD::get_singleton()->sampler_create(sampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -379,7 +379,7 @@ class RenderForwardClustered : public RendererSceneRenderRD {
|
||||||
template <PassMode p_pass_mode, uint32_t p_color_pass_flags = 0>
|
template <PassMode p_pass_mode, uint32_t p_color_pass_flags = 0>
|
||||||
_FORCE_INLINE_ void _render_list_template(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element);
|
_FORCE_INLINE_ void _render_list_template(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element);
|
||||||
void _render_list(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element);
|
void _render_list(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element);
|
||||||
void _render_list_with_draw_list(RenderListParameters *p_params, RID p_framebuffer, RD::InitialAction p_initial_color_action, RD::FinalAction p_final_color_action, RD::InitialAction p_initial_depth_action, RD::FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2());
|
void _render_list_with_draw_list(RenderListParameters *p_params, RID p_framebuffer, RD::InitialAction p_initial_color_action, RD::FinalAction p_final_color_action, RD::InitialAction p_initial_depth_action, RD::FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 0.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2());
|
||||||
|
|
||||||
void _update_instance_data_buffer(RenderListType p_render_list);
|
void _update_instance_data_buffer(RenderListType p_render_list);
|
||||||
void _fill_instance_data(RenderListType p_render_list, int *p_render_info = nullptr, uint32_t p_offset = 0, int32_t p_max_elements = -1, bool p_update_buffer = true);
|
void _fill_instance_data(RenderListType p_render_list, int *p_render_info = nullptr, uint32_t p_offset = 0, int32_t p_max_elements = -1, bool p_update_buffer = true);
|
||||||
|
|
|
@ -260,7 +260,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) {
|
||||||
|
|
||||||
if (depth_test != DEPTH_TEST_DISABLED) {
|
if (depth_test != DEPTH_TEST_DISABLED) {
|
||||||
depth_stencil_state.enable_depth_test = true;
|
depth_stencil_state.enable_depth_test = true;
|
||||||
depth_stencil_state.depth_compare_operator = RD::COMPARE_OP_LESS_OR_EQUAL;
|
depth_stencil_state.depth_compare_operator = RD::COMPARE_OP_GREATER_OR_EQUAL;
|
||||||
depth_stencil_state.enable_depth_write = depth_draw != DEPTH_DRAW_DISABLED ? true : false;
|
depth_stencil_state.enable_depth_write = depth_draw != DEPTH_DRAW_DISABLED ? true : false;
|
||||||
}
|
}
|
||||||
bool depth_pre_pass_enabled = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
|
bool depth_pre_pass_enabled = bool(GLOBAL_GET("rendering/driver/depth_prepass/enable"));
|
||||||
|
@ -827,7 +827,7 @@ void fragment() {
|
||||||
sampler.mag_filter = RD::SAMPLER_FILTER_LINEAR;
|
sampler.mag_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||||
sampler.min_filter = RD::SAMPLER_FILTER_LINEAR;
|
sampler.min_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||||
sampler.enable_compare = true;
|
sampler.enable_compare = true;
|
||||||
sampler.compare_op = RD::COMPARE_OP_LESS;
|
sampler.compare_op = RD::COMPARE_OP_GREATER;
|
||||||
shadow_sampler = RD::get_singleton()->sampler_create(sampler);
|
shadow_sampler = RD::get_singleton()->sampler_create(sampler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -984,7 +984,7 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(framebuffer, load_color ? RD::INITIAL_ACTION_LOAD : RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, c, 1.0, 0);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(framebuffer, load_color ? RD::INITIAL_ACTION_LOAD : RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, c, 0.0, 0);
|
||||||
RD::FramebufferFormatID fb_format = RD::get_singleton()->framebuffer_get_format(framebuffer);
|
RD::FramebufferFormatID fb_format = RD::get_singleton()->framebuffer_get_format(framebuffer);
|
||||||
|
|
||||||
if (copy_canvas) {
|
if (copy_canvas) {
|
||||||
|
@ -1385,7 +1385,7 @@ void RenderForwardMobile::_render_shadow_end() {
|
||||||
|
|
||||||
for (SceneState::ShadowPass &shadow_pass : scene_state.shadow_passes) {
|
for (SceneState::ShadowPass &shadow_pass : scene_state.shadow_passes) {
|
||||||
RenderListParameters render_list_parameters(render_list[RENDER_LIST_SECONDARY].elements.ptr() + shadow_pass.element_from, render_list[RENDER_LIST_SECONDARY].element_info.ptr() + shadow_pass.element_from, shadow_pass.element_count, shadow_pass.flip_cull, shadow_pass.pass_mode, shadow_pass.rp_uniform_set, 0, false, Vector2(), shadow_pass.lod_distance_multiplier, shadow_pass.screen_mesh_lod_threshold, 1, shadow_pass.element_from);
|
RenderListParameters render_list_parameters(render_list[RENDER_LIST_SECONDARY].elements.ptr() + shadow_pass.element_from, render_list[RENDER_LIST_SECONDARY].element_info.ptr() + shadow_pass.element_from, shadow_pass.element_count, shadow_pass.flip_cull, shadow_pass.pass_mode, shadow_pass.rp_uniform_set, 0, false, Vector2(), shadow_pass.lod_distance_multiplier, shadow_pass.screen_mesh_lod_threshold, 1, shadow_pass.element_from);
|
||||||
_render_list_with_draw_list(&render_list_parameters, shadow_pass.framebuffer, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, shadow_pass.initial_depth_action, RD::FINAL_ACTION_STORE, Vector<Color>(), 1.0, 0, shadow_pass.rect);
|
_render_list_with_draw_list(&render_list_parameters, shadow_pass.framebuffer, RD::INITIAL_ACTION_DISCARD, RD::FINAL_ACTION_DISCARD, shadow_pass.initial_depth_action, RD::FINAL_ACTION_STORE, Vector<Color>(), 0.0, 0, shadow_pass.rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
RD::get_singleton()->draw_command_end_label();
|
RD::get_singleton()->draw_command_end_label();
|
||||||
|
@ -1437,7 +1437,7 @@ void RenderForwardMobile::_render_material(const Transform3D &p_cam_transform, c
|
||||||
Color(0, 0, 0, 0),
|
Color(0, 0, 0, 0),
|
||||||
Color(0, 0, 0, 0)
|
Color(0, 0, 0, 0)
|
||||||
};
|
};
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, clear, 1.0, 0, p_region);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, clear, 0.0, 0, p_region);
|
||||||
_render_list(draw_list, RD::get_singleton()->framebuffer_get_format(p_framebuffer), &render_list_params, 0, render_list_params.element_count);
|
_render_list(draw_list, RD::get_singleton()->framebuffer_get_format(p_framebuffer), &render_list_params, 0, render_list_params.element_count);
|
||||||
RD::get_singleton()->draw_list_end();
|
RD::get_singleton()->draw_list_end();
|
||||||
}
|
}
|
||||||
|
@ -1483,7 +1483,7 @@ void RenderForwardMobile::_render_uv2(const PagedArray<RenderGeometryInstance *>
|
||||||
Color(0, 0, 0, 0)
|
Color(0, 0, 0, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, clear, 1.0, 0, p_region);
|
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_STORE, clear, 0.0, 0, p_region);
|
||||||
|
|
||||||
const int uv_offset_count = 9;
|
const int uv_offset_count = 9;
|
||||||
static const Vector2 uv_offsets[uv_offset_count] = {
|
static const Vector2 uv_offsets[uv_offset_count] = {
|
||||||
|
|
|
@ -350,7 +350,7 @@ private:
|
||||||
template <PassMode p_pass_mode>
|
template <PassMode p_pass_mode>
|
||||||
_FORCE_INLINE_ void _render_list_template(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element);
|
_FORCE_INLINE_ void _render_list_template(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element);
|
||||||
void _render_list(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element);
|
void _render_list(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element);
|
||||||
void _render_list_with_draw_list(RenderListParameters *p_params, RID p_framebuffer, RD::InitialAction p_initial_color_action, RD::FinalAction p_final_color_action, RD::InitialAction p_initial_depth_action, RD::FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2());
|
void _render_list_with_draw_list(RenderListParameters *p_params, RID p_framebuffer, RD::InitialAction p_initial_color_action, RD::FinalAction p_final_color_action, RD::InitialAction p_initial_depth_action, RD::FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 0.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2());
|
||||||
|
|
||||||
RenderList render_list[RENDER_LIST_MAX];
|
RenderList render_list[RENDER_LIST_MAX];
|
||||||
|
|
||||||
|
|
|
@ -271,7 +271,7 @@ void SceneShaderForwardMobile::ShaderData::set_code(const String &p_code) {
|
||||||
|
|
||||||
if (depth_test != DEPTH_TEST_DISABLED) {
|
if (depth_test != DEPTH_TEST_DISABLED) {
|
||||||
depth_stencil_state.enable_depth_test = true;
|
depth_stencil_state.enable_depth_test = true;
|
||||||
depth_stencil_state.depth_compare_operator = RD::COMPARE_OP_LESS_OR_EQUAL;
|
depth_stencil_state.depth_compare_operator = RD::COMPARE_OP_GREATER_OR_EQUAL;
|
||||||
depth_stencil_state.enable_depth_write = depth_draw != DEPTH_DRAW_DISABLED ? true : false;
|
depth_stencil_state.enable_depth_write = depth_draw != DEPTH_DRAW_DISABLED ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,7 +731,7 @@ void fragment() {
|
||||||
sampler.mag_filter = RD::SAMPLER_FILTER_LINEAR;
|
sampler.mag_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||||
sampler.min_filter = RD::SAMPLER_FILTER_LINEAR;
|
sampler.min_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||||
sampler.enable_compare = true;
|
sampler.enable_compare = true;
|
||||||
sampler.compare_op = RD::COMPARE_OP_LESS;
|
sampler.compare_op = RD::COMPARE_OP_GREATER;
|
||||||
shadow_sampler = RD::get_singleton()->sampler_create(sampler);
|
shadow_sampler = RD::get_singleton()->sampler_create(sampler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ layout(set = 1, binding = 0) uniform sampler2D source_bokeh;
|
||||||
float get_depth_at_pos(vec2 uv) {
|
float get_depth_at_pos(vec2 uv) {
|
||||||
float depth = textureLod(source_depth, uv, 0.0).x * 2.0 - 1.0;
|
float depth = textureLod(source_depth, uv, 0.0).x * 2.0 - 1.0;
|
||||||
if (params.orthogonal) {
|
if (params.orthogonal) {
|
||||||
depth = ((depth + (params.z_far + params.z_near) / (params.z_far - params.z_near)) * (params.z_far - params.z_near)) / 2.0;
|
depth = -(depth * (params.z_far - params.z_near) - (params.z_far + params.z_near)) / 2.0;
|
||||||
} else {
|
} else {
|
||||||
depth = 2.0 * params.z_near * params.z_far / (params.z_far + params.z_near - depth * (params.z_far - params.z_near));
|
depth = 2.0 * params.z_near * params.z_far / (params.z_far + params.z_near + depth * (params.z_far - params.z_near));
|
||||||
}
|
}
|
||||||
return depth;
|
return depth;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ layout(set = 2, binding = 0) uniform sampler2D original_weight;
|
||||||
float get_depth_at_pos(vec2 uv) {
|
float get_depth_at_pos(vec2 uv) {
|
||||||
float depth = textureLod(source_depth, uv, 0.0).x * 2.0 - 1.0;
|
float depth = textureLod(source_depth, uv, 0.0).x * 2.0 - 1.0;
|
||||||
if (params.orthogonal) {
|
if (params.orthogonal) {
|
||||||
depth = ((depth + (params.z_far + params.z_near) / (params.z_far - params.z_near)) * (params.z_far - params.z_near)) / 2.0;
|
depth = -(depth * (params.z_far - params.z_near) - (params.z_far + params.z_near)) / 2.0;
|
||||||
} else {
|
} else {
|
||||||
depth = 2.0 * params.z_near * params.z_far / (params.z_far + params.z_near - depth * (params.z_far - params.z_near));
|
depth = 2.0 * params.z_near * params.z_far / (params.z_far + params.z_near + depth * (params.z_far - params.z_near));
|
||||||
}
|
}
|
||||||
return depth;
|
return depth;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,8 @@ void main() {
|
||||||
float depth_fix = 1.0 / dot(normal, unorm);
|
float depth_fix = 1.0 / dot(normal, unorm);
|
||||||
|
|
||||||
depth = 2.0 * depth - 1.0;
|
depth = 2.0 * depth - 1.0;
|
||||||
float linear_depth = 2.0 * params.z_near * params.z_far / (params.z_far + params.z_near - depth * (params.z_far - params.z_near));
|
float linear_depth = 2.0 * params.z_near * params.z_far / (params.z_far + params.z_near + depth * (params.z_far - params.z_near));
|
||||||
depth = (linear_depth * depth_fix) / params.z_far;
|
// linear_depth equal to view space depth
|
||||||
|
depth = (params.z_far - linear_depth * depth_fix) / params.z_far;
|
||||||
gl_FragDepth = depth;
|
gl_FragDepth = depth;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,9 +98,9 @@ void main() {
|
||||||
// unproject our Z value so we can use it directly.
|
// unproject our Z value so we can use it directly.
|
||||||
depth = depth * 2.0 - 1.0;
|
depth = depth * 2.0 - 1.0;
|
||||||
if (params.orthogonal) {
|
if (params.orthogonal) {
|
||||||
depth = ((depth + (params.camera_z_far + params.camera_z_near) / (params.camera_z_far - params.camera_z_near)) * (params.camera_z_far - params.camera_z_near)) / 2.0;
|
depth = -(depth * (params.camera_z_far - params.camera_z_near) - (params.camera_z_far + params.camera_z_near)) / 2.0;
|
||||||
} else {
|
} else {
|
||||||
depth = 2.0 * params.camera_z_near * params.camera_z_far / (params.camera_z_far + params.camera_z_near - depth * (params.camera_z_far - params.camera_z_near));
|
depth = 2.0 * params.camera_z_near * params.camera_z_far / (params.camera_z_far + params.camera_z_near + depth * (params.camera_z_far - params.camera_z_near));
|
||||||
}
|
}
|
||||||
depth = -depth;
|
depth = -depth;
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,9 +174,9 @@ vec3 reconstruct_position(ivec2 screen_pos) {
|
||||||
|
|
||||||
pos.z = pos.z * 2.0 - 1.0;
|
pos.z = pos.z * 2.0 - 1.0;
|
||||||
if (params.orthogonal) {
|
if (params.orthogonal) {
|
||||||
pos.z = ((pos.z + (params.z_far + params.z_near) / (params.z_far - params.z_near)) * (params.z_far - params.z_near)) / 2.0;
|
pos.z = -(pos.z * (params.z_far - params.z_near) - (params.z_far + params.z_near)) / 2.0;
|
||||||
} else {
|
} else {
|
||||||
pos.z = 2.0 * params.z_near * params.z_far / (params.z_far + params.z_near - pos.z * (params.z_far - params.z_near));
|
pos.z = 2.0 * params.z_near * params.z_far / (params.z_far + params.z_near + pos.z * (params.z_far - params.z_near));
|
||||||
}
|
}
|
||||||
pos.z = -pos.z;
|
pos.z = -pos.z;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ params;
|
||||||
void main() {
|
void main() {
|
||||||
vec2 base_arr[3] = vec2[](vec2(-1.0, -3.0), vec2(-1.0, 1.0), vec2(3.0, 1.0));
|
vec2 base_arr[3] = vec2[](vec2(-1.0, -3.0), vec2(-1.0, 1.0), vec2(3.0, 1.0));
|
||||||
uv_interp = base_arr[gl_VertexIndex];
|
uv_interp = base_arr[gl_VertexIndex];
|
||||||
gl_Position = vec4(uv_interp, 1.0, 1.0);
|
gl_Position = vec4(uv_interp, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fragment]
|
#[fragment]
|
||||||
|
@ -158,7 +158,7 @@ vec3 interleaved_gradient_noise(vec2 pos) {
|
||||||
|
|
||||||
vec4 volumetric_fog_process(vec2 screen_uv) {
|
vec4 volumetric_fog_process(vec2 screen_uv) {
|
||||||
#ifdef USE_MULTIVIEW
|
#ifdef USE_MULTIVIEW
|
||||||
vec4 reprojected = sky_scene_data.combined_reprojection[ViewIndex] * (vec4(screen_uv * 2.0 - 1.0, 1.0, 1.0) * sky_scene_data.z_far);
|
vec4 reprojected = sky_scene_data.combined_reprojection[ViewIndex] * vec4(screen_uv * 2.0 - 1.0, 0.0, 1.0); // Unproject at the far plane
|
||||||
vec3 fog_pos = vec3(reprojected.xy / reprojected.w, 1.0) * 0.5 + 0.5;
|
vec3 fog_pos = vec3(reprojected.xy / reprojected.w, 1.0) * 0.5 + 0.5;
|
||||||
#else
|
#else
|
||||||
vec3 fog_pos = vec3(screen_uv, 1.0);
|
vec3 fog_pos = vec3(screen_uv, 1.0);
|
||||||
|
@ -187,9 +187,11 @@ void main() {
|
||||||
vec3 cube_normal;
|
vec3 cube_normal;
|
||||||
#ifdef USE_MULTIVIEW
|
#ifdef USE_MULTIVIEW
|
||||||
// In multiview our projection matrices will contain positional and rotational offsets that we need to properly unproject.
|
// In multiview our projection matrices will contain positional and rotational offsets that we need to properly unproject.
|
||||||
vec4 unproject = vec4(uv_interp.x, -uv_interp.y, 1.0, 1.0);
|
vec4 unproject = vec4(uv_interp.x, -uv_interp.y, 0.0, 1.0); // unproject at the far plane
|
||||||
vec4 unprojected = sky_scene_data.view_inv_projections[ViewIndex] * unproject;
|
vec4 unprojected = sky_scene_data.view_inv_projections[ViewIndex] * unproject;
|
||||||
cube_normal = unprojected.xyz / unprojected.w;
|
cube_normal = unprojected.xyz / unprojected.w;
|
||||||
|
|
||||||
|
// Unproject will give us the position between the eyes, need to re-offset
|
||||||
cube_normal += sky_scene_data.view_eye_offsets[ViewIndex].xyz;
|
cube_normal += sky_scene_data.view_eye_offsets[ViewIndex].xyz;
|
||||||
#else
|
#else
|
||||||
cube_normal.z = -1.0;
|
cube_normal.z = -1.0;
|
||||||
|
|
|
@ -416,7 +416,7 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
float depth = texture(sampler2D(directional_shadow_atlas, linear_sampler), pssm_coord.xy).r;
|
float depth = texture(sampler2D(directional_shadow_atlas, linear_sampler), pssm_coord.xy).r;
|
||||||
float shadow = exp(min(0.0, (depth - pssm_coord.z)) * z_range * INV_FOG_FADE);
|
float shadow = exp(min(0.0, (pssm_coord.z - depth)) * z_range * INV_FOG_FADE);
|
||||||
|
|
||||||
shadow = mix(shadow, 1.0, smoothstep(directional_lights.data[i].fade_from, directional_lights.data[i].fade_to, view_pos.z)); //done with negative values for performance
|
shadow = mix(shadow, 1.0, smoothstep(directional_lights.data[i].fade_from, directional_lights.data[i].fade_to, view_pos.z)); //done with negative values for performance
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ void main() {
|
||||||
|
|
||||||
float depth = texture(sampler2D(shadow_atlas, linear_sampler), pos.xy).r;
|
float depth = texture(sampler2D(shadow_atlas, linear_sampler), pos.xy).r;
|
||||||
|
|
||||||
shadow_attenuation = mix(1.0 - omni_lights.data[light_index].shadow_opacity, 1.0, exp(min(0.0, (depth - pos.z)) / omni_lights.data[light_index].inv_radius * INV_FOG_FADE));
|
shadow_attenuation = mix(1.0 - omni_lights.data[light_index].shadow_opacity, 1.0, exp(min(0.0, (pos.z - depth)) / omni_lights.data[light_index].inv_radius * INV_FOG_FADE));
|
||||||
}
|
}
|
||||||
total_light += light * attenuation * shadow_attenuation * henyey_greenstein(dot(normalize(light_pos - view_pos), normalize(view_pos)), params.phase_g) * omni_lights.data[light_index].volumetric_fog_energy;
|
total_light += light * attenuation * shadow_attenuation * henyey_greenstein(dot(normalize(light_pos - view_pos), normalize(view_pos)), params.phase_g) * omni_lights.data[light_index].volumetric_fog_energy;
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@ void main() {
|
||||||
|
|
||||||
float depth = texture(sampler2D(shadow_atlas, linear_sampler), pos.xy).r;
|
float depth = texture(sampler2D(shadow_atlas, linear_sampler), pos.xy).r;
|
||||||
|
|
||||||
shadow_attenuation = mix(1.0 - spot_lights.data[light_index].shadow_opacity, 1.0, exp(min(0.0, (depth - pos.z)) / spot_lights.data[light_index].inv_radius * INV_FOG_FADE));
|
shadow_attenuation = mix(1.0 - spot_lights.data[light_index].shadow_opacity, 1.0, exp(min(0.0, (pos.z - depth)) / spot_lights.data[light_index].inv_radius * INV_FOG_FADE));
|
||||||
}
|
}
|
||||||
total_light += light * attenuation * shadow_attenuation * henyey_greenstein(dot(normalize(light_rel_vec), normalize(view_pos)), params.phase_g) * spot_lights.data[light_index].volumetric_fog_energy;
|
total_light += light * attenuation * shadow_attenuation * henyey_greenstein(dot(normalize(light_rel_vec), normalize(view_pos)), params.phase_g) * spot_lights.data[light_index].volumetric_fog_energy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,8 +487,8 @@ void vertex_shader(vec3 vertex_input,
|
||||||
|
|
||||||
#ifdef MODE_RENDER_DEPTH
|
#ifdef MODE_RENDER_DEPTH
|
||||||
if (scene_data.pancake_shadows) {
|
if (scene_data.pancake_shadows) {
|
||||||
if (gl_Position.z <= 0.00001) {
|
if (gl_Position.z >= 0.9999) {
|
||||||
gl_Position.z = 0.00001;
|
gl_Position.z = 0.9999;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -475,8 +475,8 @@ void main() {
|
||||||
|
|
||||||
#ifdef MODE_RENDER_DEPTH
|
#ifdef MODE_RENDER_DEPTH
|
||||||
if (scene_data.pancake_shadows) {
|
if (scene_data.pancake_shadows) {
|
||||||
if (gl_Position.z <= 0.00001) {
|
if (gl_Position.z >= 0.9999) {
|
||||||
gl_Position.z = 0.00001;
|
gl_Position.z = 0.9999;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // MODE_RENDER_DEPTH
|
#endif // MODE_RENDER_DEPTH
|
||||||
|
|
|
@ -454,7 +454,7 @@ float light_process_omni_shadow(uint idx, vec3 vertex, vec3 normal) {
|
||||||
vec3 v0 = abs(basis_normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);
|
vec3 v0 = abs(basis_normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);
|
||||||
vec3 tangent = normalize(cross(v0, basis_normal));
|
vec3 tangent = normalize(cross(v0, basis_normal));
|
||||||
vec3 bitangent = normalize(cross(tangent, basis_normal));
|
vec3 bitangent = normalize(cross(tangent, basis_normal));
|
||||||
float z_norm = shadow_len * omni_lights.data[idx].inv_radius;
|
float z_norm = 1.0 - shadow_len * omni_lights.data[idx].inv_radius;
|
||||||
|
|
||||||
tangent *= omni_lights.data[idx].soft_shadow_size * omni_lights.data[idx].soft_shadow_scale;
|
tangent *= omni_lights.data[idx].soft_shadow_size * omni_lights.data[idx].soft_shadow_scale;
|
||||||
bitangent *= omni_lights.data[idx].soft_shadow_size * omni_lights.data[idx].soft_shadow_scale;
|
bitangent *= omni_lights.data[idx].soft_shadow_size * omni_lights.data[idx].soft_shadow_scale;
|
||||||
|
@ -479,7 +479,7 @@ float light_process_omni_shadow(uint idx, vec3 vertex, vec3 normal) {
|
||||||
pos.xy = uv_rect.xy + pos.xy * uv_rect.zw;
|
pos.xy = uv_rect.xy + pos.xy * uv_rect.zw;
|
||||||
|
|
||||||
float d = textureLod(sampler2D(shadow_atlas, SAMPLER_LINEAR_CLAMP), pos.xy, 0.0).r;
|
float d = textureLod(sampler2D(shadow_atlas, SAMPLER_LINEAR_CLAMP), pos.xy, 0.0).r;
|
||||||
if (d < z_norm) {
|
if (d > z_norm) {
|
||||||
blocker_average += d;
|
blocker_average += d;
|
||||||
blocker_count += 1.0;
|
blocker_count += 1.0;
|
||||||
}
|
}
|
||||||
|
@ -488,11 +488,11 @@ float light_process_omni_shadow(uint idx, vec3 vertex, vec3 normal) {
|
||||||
if (blocker_count > 0.0) {
|
if (blocker_count > 0.0) {
|
||||||
//blockers found, do soft shadow
|
//blockers found, do soft shadow
|
||||||
blocker_average /= blocker_count;
|
blocker_average /= blocker_count;
|
||||||
float penumbra = (z_norm - blocker_average) / blocker_average;
|
float penumbra = (z_norm + blocker_average) / blocker_average;
|
||||||
tangent *= penumbra;
|
tangent *= penumbra;
|
||||||
bitangent *= penumbra;
|
bitangent *= penumbra;
|
||||||
|
|
||||||
z_norm -= omni_lights.data[idx].inv_radius * omni_lights.data[idx].shadow_bias;
|
z_norm += omni_lights.data[idx].inv_radius * omni_lights.data[idx].shadow_bias;
|
||||||
|
|
||||||
shadow = 0.0;
|
shadow = 0.0;
|
||||||
for (uint i = 0; i < sc_penumbra_shadow_samples; i++) {
|
for (uint i = 0; i < sc_penumbra_shadow_samples; i++) {
|
||||||
|
@ -536,6 +536,7 @@ float light_process_omni_shadow(uint idx, vec3 vertex, vec3 normal) {
|
||||||
vec2 pos = shadow_sample.xy / shadow_sample.z;
|
vec2 pos = shadow_sample.xy / shadow_sample.z;
|
||||||
float depth = shadow_len - omni_lights.data[idx].shadow_bias;
|
float depth = shadow_len - omni_lights.data[idx].shadow_bias;
|
||||||
depth *= omni_lights.data[idx].inv_radius;
|
depth *= omni_lights.data[idx].inv_radius;
|
||||||
|
depth = 1.0 - depth;
|
||||||
shadow = mix(1.0, sample_omni_pcf_shadow(shadow_atlas, omni_lights.data[idx].soft_shadow_scale / shadow_sample.z, pos, uv_rect, flip_offset, depth), omni_lights.data[idx].shadow_opacity);
|
shadow = mix(1.0, sample_omni_pcf_shadow(shadow_atlas, omni_lights.data[idx].soft_shadow_scale / shadow_sample.z, pos, uv_rect, flip_offset, depth), omni_lights.data[idx].shadow_opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,7 +707,7 @@ float light_process_spot_shadow(uint idx, vec3 vertex, vec3 normal) {
|
||||||
vec4 v = vec4(vertex + normal_bias, 1.0);
|
vec4 v = vec4(vertex + normal_bias, 1.0);
|
||||||
|
|
||||||
vec4 splane = (spot_lights.data[idx].shadow_matrix * v);
|
vec4 splane = (spot_lights.data[idx].shadow_matrix * v);
|
||||||
splane.z -= spot_lights.data[idx].shadow_bias / (light_length * spot_lights.data[idx].inv_radius);
|
splane.z += spot_lights.data[idx].shadow_bias / (light_length * spot_lights.data[idx].inv_radius);
|
||||||
splane /= splane.w;
|
splane /= splane.w;
|
||||||
|
|
||||||
float shadow;
|
float shadow;
|
||||||
|
|
|
@ -668,7 +668,9 @@ void LightStorage::update_light_buffers(RenderDataRD *p_render_data, const Paged
|
||||||
light_data.blend_splits = (smode != RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL) && light->directional_blend_splits;
|
light_data.blend_splits = (smode != RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL) && light->directional_blend_splits;
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
Rect2 atlas_rect = light_instance->shadow_transform[j].atlas_rect;
|
Rect2 atlas_rect = light_instance->shadow_transform[j].atlas_rect;
|
||||||
Projection matrix = light_instance->shadow_transform[j].camera;
|
Projection correction;
|
||||||
|
correction.set_depth_correction(false, true, false);
|
||||||
|
Projection matrix = correction * light_instance->shadow_transform[j].camera;
|
||||||
float split = light_instance->shadow_transform[MIN(limit, j)].split;
|
float split = light_instance->shadow_transform[MIN(limit, j)].split;
|
||||||
|
|
||||||
Projection bias;
|
Projection bias;
|
||||||
|
@ -967,7 +969,9 @@ void LightStorage::update_light_buffers(RenderDataRD *p_render_data, const Paged
|
||||||
Projection bias;
|
Projection bias;
|
||||||
bias.set_light_bias();
|
bias.set_light_bias();
|
||||||
|
|
||||||
Projection cm = light_instance->shadow_transform[0].camera;
|
Projection correction;
|
||||||
|
correction.set_depth_correction(false, true, false);
|
||||||
|
Projection cm = correction * light_instance->shadow_transform[0].camera;
|
||||||
Projection shadow_mtx = bias * cm * modelview;
|
Projection shadow_mtx = bias * cm * modelview;
|
||||||
RendererRD::MaterialStorage::store_camera(shadow_mtx, light_data.shadow_matrix);
|
RendererRD::MaterialStorage::store_camera(shadow_mtx, light_data.shadow_matrix);
|
||||||
|
|
||||||
|
|
|
@ -1103,7 +1103,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color());
|
DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color());
|
||||||
DrawListID draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2());
|
DrawListID draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 0.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2());
|
||||||
|
|
||||||
void draw_list_set_blend_constants(DrawListID p_list, const Color &p_color);
|
void draw_list_set_blend_constants(DrawListID p_list, const Color &p_color);
|
||||||
void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline);
|
void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline);
|
||||||
|
|
Loading…
Reference in New Issue