mirror of
https://github.com/godotengine/godot.git
synced 2024-11-25 05:33:11 +00:00
Merge pull request #62133 from BastiaanOlij/move_cubemap_effects
Moved cube_to_dp and cubemap logic into CopyEffects
This commit is contained in:
commit
fbb5e24d1e
@ -29,9 +29,11 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "copy_effects.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
|
||||
#include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"
|
||||
#include "thirdparty/misc/cubemap_coeffs.h"
|
||||
|
||||
using namespace RendererRD;
|
||||
|
||||
@ -123,16 +125,157 @@ CopyEffects::CopyEffects(bool p_prefer_raster_effects) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Initialize copier
|
||||
Vector<String> copy_modes;
|
||||
copy_modes.push_back("\n");
|
||||
|
||||
cube_to_dp.shader.initialize(copy_modes);
|
||||
|
||||
cube_to_dp.shader_version = cube_to_dp.shader.version_create();
|
||||
RID shader = cube_to_dp.shader.version_get_shader(cube_to_dp.shader_version, 0);
|
||||
RD::PipelineDepthStencilState dss;
|
||||
dss.enable_depth_test = true;
|
||||
dss.depth_compare_operator = RD::COMPARE_OP_ALWAYS;
|
||||
dss.enable_depth_write = true;
|
||||
cube_to_dp.pipeline.setup(shader, RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), dss, RD::PipelineColorBlendState(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
//Initialize cubemap downsampler
|
||||
Vector<String> cubemap_downsampler_modes;
|
||||
cubemap_downsampler_modes.push_back("");
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
cubemap_downsampler.raster_shader.initialize(cubemap_downsampler_modes);
|
||||
|
||||
cubemap_downsampler.shader_version = cubemap_downsampler.raster_shader.version_create();
|
||||
|
||||
cubemap_downsampler.raster_pipeline.setup(cubemap_downsampler.raster_shader.version_get_shader(cubemap_downsampler.shader_version, 0), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
|
||||
} else {
|
||||
cubemap_downsampler.compute_shader.initialize(cubemap_downsampler_modes);
|
||||
|
||||
cubemap_downsampler.shader_version = cubemap_downsampler.compute_shader.version_create();
|
||||
|
||||
cubemap_downsampler.compute_pipeline = RD::get_singleton()->compute_pipeline_create(cubemap_downsampler.compute_shader.version_get_shader(cubemap_downsampler.shader_version, 0));
|
||||
cubemap_downsampler.raster_pipeline.clear();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Initialize cubemap filter
|
||||
filter.use_high_quality = GLOBAL_GET("rendering/reflections/sky_reflections/fast_filter_high_quality");
|
||||
|
||||
Vector<String> cubemap_filter_modes;
|
||||
cubemap_filter_modes.push_back("\n#define USE_HIGH_QUALITY\n");
|
||||
cubemap_filter_modes.push_back("\n#define USE_LOW_QUALITY\n");
|
||||
cubemap_filter_modes.push_back("\n#define USE_HIGH_QUALITY\n#define USE_TEXTURE_ARRAY\n");
|
||||
cubemap_filter_modes.push_back("\n#define USE_LOW_QUALITY\n#define USE_TEXTURE_ARRAY\n");
|
||||
|
||||
if (filter.use_high_quality) {
|
||||
filter.coefficient_buffer = RD::get_singleton()->storage_buffer_create(sizeof(high_quality_coeffs));
|
||||
RD::get_singleton()->buffer_update(filter.coefficient_buffer, 0, sizeof(high_quality_coeffs), &high_quality_coeffs[0]);
|
||||
} else {
|
||||
filter.coefficient_buffer = RD::get_singleton()->storage_buffer_create(sizeof(low_quality_coeffs));
|
||||
RD::get_singleton()->buffer_update(filter.coefficient_buffer, 0, sizeof(low_quality_coeffs), &low_quality_coeffs[0]);
|
||||
}
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
filter.raster_shader.initialize(cubemap_filter_modes);
|
||||
|
||||
// array variants are not supported in raster
|
||||
filter.raster_shader.set_variant_enabled(FILTER_MODE_HIGH_QUALITY_ARRAY, false);
|
||||
filter.raster_shader.set_variant_enabled(FILTER_MODE_LOW_QUALITY_ARRAY, false);
|
||||
|
||||
filter.shader_version = filter.raster_shader.version_create();
|
||||
|
||||
for (int i = 0; i < FILTER_MODE_MAX; i++) {
|
||||
if (filter.raster_shader.is_variant_enabled(i)) {
|
||||
filter.raster_pipelines[i].setup(filter.raster_shader.version_get_shader(filter.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
|
||||
} else {
|
||||
filter.raster_pipelines[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
{
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(filter.coefficient_buffer);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
filter.uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.raster_shader.version_get_shader(filter.shader_version, filter.use_high_quality ? 0 : 1), 1);
|
||||
} else {
|
||||
filter.compute_shader.initialize(cubemap_filter_modes);
|
||||
filter.shader_version = filter.compute_shader.version_create();
|
||||
|
||||
for (int i = 0; i < FILTER_MODE_MAX; i++) {
|
||||
filter.compute_pipelines[i] = RD::get_singleton()->compute_pipeline_create(filter.compute_shader.version_get_shader(filter.shader_version, i));
|
||||
filter.raster_pipelines[i].clear();
|
||||
}
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
{
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(filter.coefficient_buffer);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
filter.uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.compute_shader.version_get_shader(filter.shader_version, filter.use_high_quality ? 0 : 1), 1);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Initialize roughness
|
||||
Vector<String> cubemap_roughness_modes;
|
||||
cubemap_roughness_modes.push_back("");
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
roughness.raster_shader.initialize(cubemap_roughness_modes);
|
||||
|
||||
roughness.shader_version = roughness.raster_shader.version_create();
|
||||
|
||||
roughness.raster_pipeline.setup(roughness.raster_shader.version_get_shader(roughness.shader_version, 0), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
|
||||
|
||||
} else {
|
||||
roughness.compute_shader.initialize(cubemap_roughness_modes);
|
||||
|
||||
roughness.shader_version = roughness.compute_shader.version_create();
|
||||
|
||||
roughness.compute_pipeline = RD::get_singleton()->compute_pipeline_create(roughness.compute_shader.version_get_shader(roughness.shader_version, 0));
|
||||
roughness.raster_pipeline.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CopyEffects::~CopyEffects() {
|
||||
if (prefer_raster_effects) {
|
||||
blur_raster.shader.version_free(blur_raster.shader_version);
|
||||
cubemap_downsampler.raster_shader.version_free(cubemap_downsampler.shader_version);
|
||||
filter.raster_shader.version_free(filter.shader_version);
|
||||
roughness.raster_shader.version_free(roughness.shader_version);
|
||||
} else {
|
||||
copy.shader.version_free(copy.shader_version);
|
||||
cubemap_downsampler.compute_shader.version_free(cubemap_downsampler.shader_version);
|
||||
filter.compute_shader.version_free(filter.shader_version);
|
||||
roughness.compute_shader.version_free(roughness.shader_version);
|
||||
}
|
||||
|
||||
RD::get_singleton()->free(filter.coefficient_buffer);
|
||||
|
||||
if (RD::get_singleton()->uniform_set_is_valid(filter.image_uniform_set)) {
|
||||
RD::get_singleton()->free(filter.image_uniform_set);
|
||||
}
|
||||
|
||||
if (RD::get_singleton()->uniform_set_is_valid(filter.uniform_set)) {
|
||||
RD::get_singleton()->free(filter.uniform_set);
|
||||
}
|
||||
|
||||
copy_to_fb.shader.version_free(copy_to_fb.shader_version);
|
||||
cube_to_dp.shader.version_free(cube_to_dp.shader_version);
|
||||
|
||||
singleton = nullptr;
|
||||
}
|
||||
@ -681,3 +824,262 @@ void CopyEffects::set_color(RID p_dest_texture, const Color &p_color, const Rect
|
||||
RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_region.size.width, p_region.size.height, 1);
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void CopyEffects::copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dst_framebuffer, const Rect2 &p_rect, const Vector2 &p_dst_size, float p_z_near, float p_z_far, bool p_dp_flip) {
|
||||
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
|
||||
ERR_FAIL_NULL(uniform_set_cache);
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
ERR_FAIL_NULL(material_storage);
|
||||
|
||||
CopyToDPPushConstant push_constant;
|
||||
push_constant.screen_rect[0] = p_rect.position.x;
|
||||
push_constant.screen_rect[1] = p_rect.position.y;
|
||||
push_constant.screen_rect[2] = p_rect.size.width;
|
||||
push_constant.screen_rect[3] = p_rect.size.height;
|
||||
push_constant.z_far = p_z_far;
|
||||
push_constant.z_near = p_z_near;
|
||||
push_constant.texel_size[0] = 1.0f / p_dst_size.x;
|
||||
push_constant.texel_size[1] = 1.0f / p_dst_size.y;
|
||||
push_constant.texel_size[0] *= p_dp_flip ? -1.0f : 1.0f; // Encode dp flip as x size sign
|
||||
|
||||
// setup our uniforms
|
||||
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
|
||||
|
||||
RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
|
||||
|
||||
RID shader = cube_to_dp.shader.version_get_shader(cube_to_dp.shader_version, 0);
|
||||
ERR_FAIL_COND(shader.is_null());
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dst_framebuffer, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, cube_to_dp.pipeline.get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dst_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_index_array(draw_list, material_storage->get_quad_index_array());
|
||||
|
||||
RD::get_singleton()->draw_list_set_push_constant(draw_list, &push_constant, sizeof(CopyToDPPushConstant));
|
||||
RD::get_singleton()->draw_list_draw(draw_list, true);
|
||||
RD::get_singleton()->draw_list_end(RD::BARRIER_MASK_RASTER | RD::BARRIER_MASK_TRANSFER);
|
||||
}
|
||||
|
||||
void CopyEffects::cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size) {
|
||||
ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use compute based cubemap downsample with the mobile renderer.");
|
||||
|
||||
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
|
||||
ERR_FAIL_NULL(uniform_set_cache);
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
ERR_FAIL_NULL(material_storage);
|
||||
|
||||
cubemap_downsampler.push_constant.face_size = p_size.x;
|
||||
cubemap_downsampler.push_constant.face_id = 0; // we render all 6 sides to each layer in one call
|
||||
|
||||
// setup our uniforms
|
||||
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
|
||||
|
||||
RD::Uniform u_source_cubemap(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_cubemap }));
|
||||
RD::Uniform u_dest_cubemap(RD::UNIFORM_TYPE_IMAGE, 0, Vector<RID>({ p_dest_cubemap }));
|
||||
|
||||
RID shader = cubemap_downsampler.compute_shader.version_get_shader(cubemap_downsampler.shader_version, 0);
|
||||
ERR_FAIL_COND(shader.is_null());
|
||||
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, cubemap_downsampler.compute_pipeline);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_cubemap), 0);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 1, u_dest_cubemap), 1);
|
||||
|
||||
int x_groups = (p_size.x - 1) / 8 + 1;
|
||||
int y_groups = (p_size.y - 1) / 8 + 1;
|
||||
|
||||
RD::get_singleton()->compute_list_set_push_constant(compute_list, &cubemap_downsampler.push_constant, sizeof(CubemapDownsamplerPushConstant));
|
||||
|
||||
RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 6); // one z_group for each face
|
||||
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void CopyEffects::cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size) {
|
||||
ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use raster based cubemap downsample with the clustered renderer.");
|
||||
ERR_FAIL_COND_MSG(p_face_id >= 6, "Raster implementation of cubemap downsample must process one side at a time.");
|
||||
|
||||
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
|
||||
ERR_FAIL_NULL(uniform_set_cache);
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
ERR_FAIL_NULL(material_storage);
|
||||
|
||||
cubemap_downsampler.push_constant.face_size = p_size.x;
|
||||
cubemap_downsampler.push_constant.face_id = p_face_id;
|
||||
|
||||
// setup our uniforms
|
||||
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
|
||||
|
||||
RD::Uniform u_source_cubemap(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_cubemap }));
|
||||
|
||||
RID shader = cubemap_downsampler.raster_shader.version_get_shader(cubemap_downsampler.shader_version, 0);
|
||||
ERR_FAIL_COND(shader.is_null());
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, cubemap_downsampler.raster_pipeline.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_cubemap), 0);
|
||||
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, &cubemap_downsampler.push_constant, sizeof(CubemapDownsamplerPushConstant));
|
||||
|
||||
RD::get_singleton()->draw_list_draw(draw_list, true);
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
||||
void CopyEffects::cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array) {
|
||||
ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use compute based cubemap filter with the mobile renderer.");
|
||||
|
||||
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
|
||||
ERR_FAIL_NULL(uniform_set_cache);
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
ERR_FAIL_NULL(material_storage);
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
for (int i = 0; i < p_dest_cubemap.size(); i++) {
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
|
||||
u.binding = i;
|
||||
u.append_id(p_dest_cubemap[i]);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
if (RD::get_singleton()->uniform_set_is_valid(filter.image_uniform_set)) {
|
||||
RD::get_singleton()->free(filter.image_uniform_set);
|
||||
}
|
||||
filter.image_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.compute_shader.version_get_shader(filter.shader_version, 0), 2);
|
||||
|
||||
// setup our uniforms
|
||||
RID default_mipmap_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
|
||||
|
||||
RD::Uniform u_source_cubemap(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_mipmap_sampler, p_source_cubemap }));
|
||||
|
||||
int mode = p_use_array ? FILTER_MODE_HIGH_QUALITY_ARRAY : FILTER_MODE_HIGH_QUALITY;
|
||||
mode = filter.use_high_quality ? mode : mode + 1;
|
||||
|
||||
RID shader = filter.compute_shader.version_get_shader(filter.shader_version, mode);
|
||||
ERR_FAIL_COND(shader.is_null());
|
||||
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, filter.compute_pipelines[mode]);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_cubemap), 0);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, filter.uniform_set, 1);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, filter.image_uniform_set, 2);
|
||||
|
||||
int x_groups = p_use_array ? 1792 : 342; // (128 * 128 * 7) / 64 : (128*128 + 64*64 + 32*32 + 16*16 + 8*8 + 4*4 + 2*2) / 64
|
||||
|
||||
RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, 6, 1); // one y_group for each face
|
||||
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void CopyEffects::cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level) {
|
||||
ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use raster based cubemap filter with the clustered renderer.");
|
||||
ERR_FAIL_COND_MSG(p_face_id >= 6, "Raster implementation of cubemap filter must process one side at a time.");
|
||||
|
||||
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
|
||||
ERR_FAIL_NULL(uniform_set_cache);
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
ERR_FAIL_NULL(material_storage);
|
||||
|
||||
// TODO implement!
|
||||
CubemapFilterRasterPushConstant push_constant;
|
||||
push_constant.mip_level = p_mip_level;
|
||||
push_constant.face_id = p_face_id;
|
||||
|
||||
// setup our uniforms
|
||||
RID default_mipmap_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
|
||||
|
||||
RD::Uniform u_source_cubemap(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_mipmap_sampler, p_source_cubemap }));
|
||||
|
||||
CubemapFilterMode mode = filter.use_high_quality ? FILTER_MODE_HIGH_QUALITY : FILTER_MODE_LOW_QUALITY;
|
||||
|
||||
RID shader = filter.raster_shader.version_get_shader(filter.shader_version, mode);
|
||||
ERR_FAIL_COND(shader.is_null());
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, filter.raster_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_cubemap), 0);
|
||||
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, filter.uniform_set, 1);
|
||||
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, &push_constant, sizeof(CubemapFilterRasterPushConstant));
|
||||
|
||||
RD::get_singleton()->draw_list_draw(draw_list, true);
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
||||
void CopyEffects::cubemap_roughness(RID p_source_rd_texture, RID p_dest_texture, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size) {
|
||||
ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use compute based cubemap roughness with the mobile renderer.");
|
||||
|
||||
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
|
||||
ERR_FAIL_NULL(uniform_set_cache);
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
ERR_FAIL_NULL(material_storage);
|
||||
|
||||
memset(&roughness.push_constant, 0, sizeof(CubemapRoughnessPushConstant));
|
||||
|
||||
roughness.push_constant.face_id = p_face_id > 9 ? 0 : p_face_id;
|
||||
roughness.push_constant.roughness = p_roughness * p_roughness; // Shader expects roughness, not perceptual roughness, so multiply before passing in.
|
||||
roughness.push_constant.sample_count = p_sample_count;
|
||||
roughness.push_constant.use_direct_write = p_roughness == 0.0;
|
||||
roughness.push_constant.face_size = p_size;
|
||||
|
||||
// setup our uniforms
|
||||
RID default_mipmap_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
|
||||
|
||||
RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_mipmap_sampler, p_source_rd_texture }));
|
||||
RD::Uniform u_dest_texture(RD::UNIFORM_TYPE_IMAGE, 0, Vector<RID>({ p_dest_texture }));
|
||||
|
||||
RID shader = roughness.compute_shader.version_get_shader(filter.shader_version, 0);
|
||||
ERR_FAIL_COND(shader.is_null());
|
||||
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, roughness.compute_pipeline);
|
||||
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 1, u_dest_texture), 1);
|
||||
|
||||
RD::get_singleton()->compute_list_set_push_constant(compute_list, &roughness.push_constant, sizeof(CubemapRoughnessPushConstant));
|
||||
|
||||
int x_groups = (p_size - 1) / 8 + 1;
|
||||
int y_groups = (p_size - 1) / 8 + 1;
|
||||
|
||||
RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, p_face_id > 9 ? 6 : 1);
|
||||
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void CopyEffects::cubemap_roughness_raster(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size) {
|
||||
ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use raster based cubemap roughness with the clustered renderer.");
|
||||
ERR_FAIL_COND_MSG(p_face_id >= 6, "Raster implementation of cubemap roughness must process one side at a time.");
|
||||
|
||||
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
|
||||
ERR_FAIL_NULL(uniform_set_cache);
|
||||
MaterialStorage *material_storage = MaterialStorage::get_singleton();
|
||||
ERR_FAIL_NULL(material_storage);
|
||||
|
||||
memset(&roughness.push_constant, 0, sizeof(CubemapRoughnessPushConstant));
|
||||
|
||||
roughness.push_constant.face_id = p_face_id;
|
||||
roughness.push_constant.roughness = p_roughness * p_roughness; // Shader expects roughness, not perceptual roughness, so multiply before passing in.
|
||||
roughness.push_constant.sample_count = p_sample_count;
|
||||
roughness.push_constant.use_direct_write = p_roughness == 0.0;
|
||||
roughness.push_constant.face_size = p_size;
|
||||
|
||||
// setup our uniforms
|
||||
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
|
||||
|
||||
RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
|
||||
|
||||
RID shader = roughness.raster_shader.version_get_shader(filter.shader_version, 0);
|
||||
ERR_FAIL_COND(shader.is_null());
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, roughness.raster_pipeline.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_index_array(draw_list, material_storage->get_quad_index_array());
|
||||
|
||||
RD::get_singleton()->draw_list_set_push_constant(draw_list, &roughness.push_constant, sizeof(CubemapRoughnessPushConstant));
|
||||
|
||||
RD::get_singleton()->draw_list_draw(draw_list, true);
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
@ -35,6 +35,13 @@
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/blur_raster.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/copy.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/copy_to_fb.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_downsampler.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_downsampler_raster.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_filter.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_filter_raster.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_roughness.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_roughness_raster.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_scene_render.h"
|
||||
|
||||
#include "servers/rendering_server.h"
|
||||
@ -189,6 +196,84 @@ private:
|
||||
|
||||
} copy_to_fb;
|
||||
|
||||
// Copy to DP
|
||||
|
||||
struct CopyToDPPushConstant {
|
||||
float z_far;
|
||||
float z_near;
|
||||
float texel_size[2];
|
||||
float screen_rect[4];
|
||||
};
|
||||
|
||||
struct CopyToDP {
|
||||
CubeToDpShaderRD shader;
|
||||
RID shader_version;
|
||||
PipelineCacheRD pipeline;
|
||||
} cube_to_dp;
|
||||
|
||||
// Cubemap effects
|
||||
|
||||
struct CubemapDownsamplerPushConstant {
|
||||
uint32_t face_size;
|
||||
uint32_t face_id;
|
||||
float pad[2];
|
||||
};
|
||||
|
||||
struct CubemapDownsampler {
|
||||
CubemapDownsamplerPushConstant push_constant;
|
||||
CubemapDownsamplerShaderRD compute_shader;
|
||||
CubemapDownsamplerRasterShaderRD raster_shader;
|
||||
RID shader_version;
|
||||
RID compute_pipeline;
|
||||
PipelineCacheRD raster_pipeline;
|
||||
} cubemap_downsampler;
|
||||
|
||||
enum CubemapFilterMode {
|
||||
FILTER_MODE_HIGH_QUALITY,
|
||||
FILTER_MODE_LOW_QUALITY,
|
||||
FILTER_MODE_HIGH_QUALITY_ARRAY,
|
||||
FILTER_MODE_LOW_QUALITY_ARRAY,
|
||||
FILTER_MODE_MAX,
|
||||
};
|
||||
|
||||
struct CubemapFilterRasterPushConstant {
|
||||
uint32_t mip_level;
|
||||
uint32_t face_id;
|
||||
float pad[2];
|
||||
};
|
||||
|
||||
struct CubemapFilter {
|
||||
CubemapFilterShaderRD compute_shader;
|
||||
CubemapFilterRasterShaderRD raster_shader;
|
||||
RID shader_version;
|
||||
RID compute_pipelines[FILTER_MODE_MAX];
|
||||
PipelineCacheRD raster_pipelines[FILTER_MODE_MAX];
|
||||
|
||||
RID uniform_set;
|
||||
RID image_uniform_set;
|
||||
RID coefficient_buffer;
|
||||
bool use_high_quality;
|
||||
|
||||
} filter;
|
||||
|
||||
struct CubemapRoughnessPushConstant {
|
||||
uint32_t face_id;
|
||||
uint32_t sample_count;
|
||||
float roughness;
|
||||
uint32_t use_direct_write;
|
||||
float face_size;
|
||||
float pad[3];
|
||||
};
|
||||
|
||||
struct CubemapRoughness {
|
||||
CubemapRoughnessPushConstant push_constant;
|
||||
CubemapRoughnessShaderRD compute_shader;
|
||||
CubemapRoughnessRasterShaderRD raster_shader;
|
||||
RID shader_version;
|
||||
RID compute_pipeline;
|
||||
PipelineCacheRD raster_pipeline;
|
||||
} roughness;
|
||||
|
||||
static CopyEffects *singleton;
|
||||
|
||||
public:
|
||||
@ -197,6 +282,8 @@ public:
|
||||
CopyEffects(bool p_prefer_raster_effects);
|
||||
~CopyEffects();
|
||||
|
||||
bool get_prefer_raster_effects() { return prefer_raster_effects; }
|
||||
|
||||
void copy_to_rect(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y = false, bool p_force_luminance = false, bool p_all_source = false, bool p_8_bit_dst = false, bool p_alpha_to_one = false);
|
||||
void copy_cubemap_to_panorama(RID p_source_cube, RID p_dest_panorama, const Size2i &p_panorama_size, float p_lod, bool p_is_array);
|
||||
void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);
|
||||
@ -213,6 +300,15 @@ public:
|
||||
void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_framebuffer, const Size2i &p_size);
|
||||
|
||||
void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);
|
||||
|
||||
void copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dst_framebuffer, const Rect2 &p_rect, const Vector2 &p_dst_size, float p_z_near, float p_z_far, bool p_dp_flip);
|
||||
void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size);
|
||||
void cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size);
|
||||
void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);
|
||||
void cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level);
|
||||
|
||||
void cubemap_roughness(RID p_source_rd_texture, RID p_dest_texture, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);
|
||||
void cubemap_roughness_raster(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);
|
||||
};
|
||||
|
||||
} // namespace RendererRD
|
||||
|
@ -86,7 +86,7 @@ RID EffectsRD::_get_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps)
|
||||
u.append_id(p_texture);
|
||||
uniforms.push_back(u);
|
||||
// anything with the same configuration (one texture in binding 0 for set 0), is good
|
||||
RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, cube_to_dp.shader.version_get_shader(cube_to_dp.shader_version, 0), 0);
|
||||
RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, specular_merge.shader.version_get_shader(specular_merge.shader_version, 0), 0);
|
||||
|
||||
texture_to_uniform_set_cache[p_texture] = uniform_set;
|
||||
|
||||
@ -473,28 +473,6 @@ void EffectsRD::merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_bas
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
||||
void EffectsRD::copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dst_framebuffer, const Rect2 &p_rect, const Vector2 &p_dst_size, float p_z_near, float p_z_far, bool p_dp_flip) {
|
||||
CopyToDPPushConstant push_constant;
|
||||
push_constant.screen_rect[0] = p_rect.position.x;
|
||||
push_constant.screen_rect[1] = p_rect.position.y;
|
||||
push_constant.screen_rect[2] = p_rect.size.width;
|
||||
push_constant.screen_rect[3] = p_rect.size.height;
|
||||
push_constant.z_far = p_z_far;
|
||||
push_constant.z_near = p_z_near;
|
||||
push_constant.texel_size[0] = 1.0f / p_dst_size.x;
|
||||
push_constant.texel_size[1] = 1.0f / p_dst_size.y;
|
||||
push_constant.texel_size[0] *= p_dp_flip ? -1.0f : 1.0f; // Encode dp flip as x size sign
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dst_framebuffer, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, cube_to_dp.pipeline.get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dst_framebuffer)));
|
||||
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_rd_texture), 0);
|
||||
RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
|
||||
|
||||
RD::get_singleton()->draw_list_set_push_constant(draw_list, &push_constant, sizeof(CopyToDPPushConstant));
|
||||
RD::get_singleton()->draw_list_draw(draw_list, true);
|
||||
RD::get_singleton()->draw_list_end(RD::BARRIER_MASK_RASTER | RD::BARRIER_MASK_TRANSFER);
|
||||
}
|
||||
|
||||
void EffectsRD::luminance_reduction(RID p_source_texture, const Size2i p_source_size, const Vector<RID> p_reduce, RID p_prev_luminance, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set) {
|
||||
ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use compute version of luminance reduction with the mobile renderer.");
|
||||
|
||||
@ -1253,149 +1231,6 @@ void EffectsRD::roughness_limit(RID p_source_normal, RID p_roughness, const Size
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void EffectsRD::cubemap_roughness(RID p_source_rd_texture, RID p_dest_texture, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size) {
|
||||
ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use compute based cubemap roughness with the mobile renderer.");
|
||||
|
||||
memset(&roughness.push_constant, 0, sizeof(CubemapRoughnessPushConstant));
|
||||
|
||||
roughness.push_constant.face_id = p_face_id > 9 ? 0 : p_face_id;
|
||||
roughness.push_constant.roughness = p_roughness * p_roughness; // Shader expects roughness, not perceptual roughness, so multiply before passing in.
|
||||
roughness.push_constant.sample_count = p_sample_count;
|
||||
roughness.push_constant.use_direct_write = p_roughness == 0.0;
|
||||
roughness.push_constant.face_size = p_size;
|
||||
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, roughness.compute_pipeline);
|
||||
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_rd_texture, true), 0);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_dest_texture), 1);
|
||||
|
||||
RD::get_singleton()->compute_list_set_push_constant(compute_list, &roughness.push_constant, sizeof(CubemapRoughnessPushConstant));
|
||||
|
||||
int x_groups = (p_size - 1) / 8 + 1;
|
||||
int y_groups = (p_size - 1) / 8 + 1;
|
||||
|
||||
RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, p_face_id > 9 ? 6 : 1);
|
||||
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void EffectsRD::cubemap_roughness_raster(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size) {
|
||||
ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use raster based cubemap roughness with the clustered renderer.");
|
||||
ERR_FAIL_COND_MSG(p_face_id >= 6, "Raster implementation of cubemap roughness must process one side at a time.");
|
||||
|
||||
memset(&roughness.push_constant, 0, sizeof(CubemapRoughnessPushConstant));
|
||||
|
||||
roughness.push_constant.face_id = p_face_id;
|
||||
roughness.push_constant.roughness = p_roughness * p_roughness; // Shader expects roughness, not perceptual roughness, so multiply before passing in.
|
||||
roughness.push_constant.sample_count = p_sample_count;
|
||||
roughness.push_constant.use_direct_write = p_roughness == 0.0;
|
||||
roughness.push_constant.face_size = p_size;
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, roughness.raster_pipeline.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, _get_uniform_set_from_texture(p_source_rd_texture), 0);
|
||||
RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
|
||||
|
||||
RD::get_singleton()->draw_list_set_push_constant(draw_list, &roughness.push_constant, sizeof(CubemapRoughnessPushConstant));
|
||||
|
||||
RD::get_singleton()->draw_list_draw(draw_list, true);
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
||||
void EffectsRD::cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size) {
|
||||
ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use compute based cubemap downsample with the mobile renderer.");
|
||||
|
||||
cubemap_downsampler.push_constant.face_size = p_size.x;
|
||||
cubemap_downsampler.push_constant.face_id = 0; // we render all 6 sides to each layer in one call
|
||||
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, cubemap_downsampler.compute_pipeline);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_cubemap), 0);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_dest_cubemap), 1);
|
||||
|
||||
int x_groups = (p_size.x - 1) / 8 + 1;
|
||||
int y_groups = (p_size.y - 1) / 8 + 1;
|
||||
|
||||
RD::get_singleton()->compute_list_set_push_constant(compute_list, &cubemap_downsampler.push_constant, sizeof(CubemapDownsamplerPushConstant));
|
||||
|
||||
RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 6); // one z_group for each face
|
||||
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void EffectsRD::cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size) {
|
||||
ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use raster based cubemap downsample with the clustered renderer.");
|
||||
ERR_FAIL_COND_MSG(p_face_id >= 6, "Raster implementation of cubemap downsample must process one side at a time.");
|
||||
|
||||
cubemap_downsampler.push_constant.face_size = p_size.x;
|
||||
cubemap_downsampler.push_constant.face_id = p_face_id;
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, cubemap_downsampler.raster_pipeline.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, _get_uniform_set_from_texture(p_source_cubemap), 0);
|
||||
RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
|
||||
|
||||
RD::get_singleton()->draw_list_set_push_constant(draw_list, &cubemap_downsampler.push_constant, sizeof(CubemapDownsamplerPushConstant));
|
||||
|
||||
RD::get_singleton()->draw_list_draw(draw_list, true);
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
||||
void EffectsRD::cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array) {
|
||||
ERR_FAIL_COND_MSG(prefer_raster_effects, "Can't use compute based cubemap filter with the mobile renderer.");
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
for (int i = 0; i < p_dest_cubemap.size(); i++) {
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
|
||||
u.binding = i;
|
||||
u.append_id(p_dest_cubemap[i]);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
if (RD::get_singleton()->uniform_set_is_valid(filter.image_uniform_set)) {
|
||||
RD::get_singleton()->free(filter.image_uniform_set);
|
||||
}
|
||||
filter.image_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.compute_shader.version_get_shader(filter.shader_version, 0), 2);
|
||||
|
||||
int pipeline = p_use_array ? FILTER_MODE_HIGH_QUALITY_ARRAY : FILTER_MODE_HIGH_QUALITY;
|
||||
pipeline = filter.use_high_quality ? pipeline : pipeline + 1;
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, filter.compute_pipelines[pipeline]);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_cubemap, true), 0);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, filter.uniform_set, 1);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, filter.image_uniform_set, 2);
|
||||
|
||||
int x_groups = p_use_array ? 1792 : 342; // (128 * 128 * 7) / 64 : (128*128 + 64*64 + 32*32 + 16*16 + 8*8 + 4*4 + 2*2) / 64
|
||||
|
||||
RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, 6, 1); // one y_group for each face
|
||||
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
void EffectsRD::cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level) {
|
||||
ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use raster based cubemap filter with the clustered renderer.");
|
||||
ERR_FAIL_COND_MSG(p_face_id >= 6, "Raster implementation of cubemap filter must process one side at a time.");
|
||||
|
||||
// TODO implement!
|
||||
CubemapFilterRasterPushConstant push_constant;
|
||||
push_constant.mip_level = p_mip_level;
|
||||
push_constant.face_id = p_face_id;
|
||||
|
||||
CubemapFilterMode mode = filter.use_high_quality ? FILTER_MODE_HIGH_QUALITY : FILTER_MODE_LOW_QUALITY;
|
||||
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, filter.raster_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, _get_uniform_set_from_texture(p_source_cubemap), 0);
|
||||
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, filter.uniform_set, 1);
|
||||
RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
|
||||
|
||||
RD::get_singleton()->draw_list_set_push_constant(draw_list, &push_constant, sizeof(CubemapFilterRasterPushConstant));
|
||||
|
||||
RD::get_singleton()->draw_list_draw(draw_list, true);
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
||||
void EffectsRD::sort_buffer(RID p_uniform_set, int p_size) {
|
||||
Sort::PushConstant push_constant;
|
||||
push_constant.total_elements = p_size;
|
||||
@ -1489,28 +1324,6 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) {
|
||||
|
||||
prefer_raster_effects = p_prefer_raster_effects;
|
||||
|
||||
{
|
||||
// Initialize roughness
|
||||
Vector<String> cubemap_roughness_modes;
|
||||
cubemap_roughness_modes.push_back("");
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
roughness.raster_shader.initialize(cubemap_roughness_modes);
|
||||
|
||||
roughness.shader_version = roughness.raster_shader.version_create();
|
||||
|
||||
roughness.raster_pipeline.setup(roughness.raster_shader.version_get_shader(roughness.shader_version, 0), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
|
||||
|
||||
} else {
|
||||
roughness.compute_shader.initialize(cubemap_roughness_modes);
|
||||
|
||||
roughness.shader_version = roughness.compute_shader.version_create();
|
||||
|
||||
roughness.compute_pipeline = RD::get_singleton()->compute_pipeline_create(roughness.compute_shader.version_get_shader(roughness.shader_version, 0));
|
||||
roughness.raster_pipeline.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
Vector<String> luminance_reduce_modes;
|
||||
luminance_reduce_modes.push_back("\n#define FIRST_PASS\n"); // LUMINANCE_REDUCE_FRAGMENT_FIRST
|
||||
@ -1544,22 +1357,6 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Initialize copier
|
||||
Vector<String> copy_modes;
|
||||
copy_modes.push_back("\n");
|
||||
|
||||
cube_to_dp.shader.initialize(copy_modes);
|
||||
|
||||
cube_to_dp.shader_version = cube_to_dp.shader.version_create();
|
||||
RID shader = cube_to_dp.shader.version_get_shader(cube_to_dp.shader_version, 0);
|
||||
RD::PipelineDepthStencilState dss;
|
||||
dss.enable_depth_test = true;
|
||||
dss.depth_compare_operator = RD::COMPARE_OP_ALWAYS;
|
||||
dss.enable_depth_write = true;
|
||||
cube_to_dp.pipeline.setup(shader, RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), dss, RD::PipelineColorBlendState(), 0);
|
||||
}
|
||||
|
||||
if (!prefer_raster_effects) {
|
||||
{
|
||||
// Initialize depth buffer for screen space effects
|
||||
@ -1720,92 +1517,6 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) {
|
||||
roughness_limiter.pipeline = RD::get_singleton()->compute_pipeline_create(roughness_limiter.shader.version_get_shader(roughness_limiter.shader_version, 0));
|
||||
}
|
||||
|
||||
{
|
||||
//Initialize cubemap downsampler
|
||||
Vector<String> cubemap_downsampler_modes;
|
||||
cubemap_downsampler_modes.push_back("");
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
cubemap_downsampler.raster_shader.initialize(cubemap_downsampler_modes);
|
||||
|
||||
cubemap_downsampler.shader_version = cubemap_downsampler.raster_shader.version_create();
|
||||
|
||||
cubemap_downsampler.raster_pipeline.setup(cubemap_downsampler.raster_shader.version_get_shader(cubemap_downsampler.shader_version, 0), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
|
||||
} else {
|
||||
cubemap_downsampler.compute_shader.initialize(cubemap_downsampler_modes);
|
||||
|
||||
cubemap_downsampler.shader_version = cubemap_downsampler.compute_shader.version_create();
|
||||
|
||||
cubemap_downsampler.compute_pipeline = RD::get_singleton()->compute_pipeline_create(cubemap_downsampler.compute_shader.version_get_shader(cubemap_downsampler.shader_version, 0));
|
||||
cubemap_downsampler.raster_pipeline.clear();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Initialize cubemap filter
|
||||
filter.use_high_quality = GLOBAL_GET("rendering/reflections/sky_reflections/fast_filter_high_quality");
|
||||
|
||||
Vector<String> cubemap_filter_modes;
|
||||
cubemap_filter_modes.push_back("\n#define USE_HIGH_QUALITY\n");
|
||||
cubemap_filter_modes.push_back("\n#define USE_LOW_QUALITY\n");
|
||||
cubemap_filter_modes.push_back("\n#define USE_HIGH_QUALITY\n#define USE_TEXTURE_ARRAY\n");
|
||||
cubemap_filter_modes.push_back("\n#define USE_LOW_QUALITY\n#define USE_TEXTURE_ARRAY\n");
|
||||
|
||||
if (filter.use_high_quality) {
|
||||
filter.coefficient_buffer = RD::get_singleton()->storage_buffer_create(sizeof(high_quality_coeffs));
|
||||
RD::get_singleton()->buffer_update(filter.coefficient_buffer, 0, sizeof(high_quality_coeffs), &high_quality_coeffs[0]);
|
||||
} else {
|
||||
filter.coefficient_buffer = RD::get_singleton()->storage_buffer_create(sizeof(low_quality_coeffs));
|
||||
RD::get_singleton()->buffer_update(filter.coefficient_buffer, 0, sizeof(low_quality_coeffs), &low_quality_coeffs[0]);
|
||||
}
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
filter.raster_shader.initialize(cubemap_filter_modes);
|
||||
|
||||
// array variants are not supported in raster
|
||||
filter.raster_shader.set_variant_enabled(FILTER_MODE_HIGH_QUALITY_ARRAY, false);
|
||||
filter.raster_shader.set_variant_enabled(FILTER_MODE_LOW_QUALITY_ARRAY, false);
|
||||
|
||||
filter.shader_version = filter.raster_shader.version_create();
|
||||
|
||||
for (int i = 0; i < FILTER_MODE_MAX; i++) {
|
||||
if (filter.raster_shader.is_variant_enabled(i)) {
|
||||
filter.raster_pipelines[i].setup(filter.raster_shader.version_get_shader(filter.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
|
||||
} else {
|
||||
filter.raster_pipelines[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
{
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(filter.coefficient_buffer);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
filter.uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.raster_shader.version_get_shader(filter.shader_version, filter.use_high_quality ? 0 : 1), 1);
|
||||
} else {
|
||||
filter.compute_shader.initialize(cubemap_filter_modes);
|
||||
filter.shader_version = filter.compute_shader.version_create();
|
||||
|
||||
for (int i = 0; i < FILTER_MODE_MAX; i++) {
|
||||
filter.compute_pipelines[i] = RD::get_singleton()->compute_pipeline_create(filter.compute_shader.version_get_shader(filter.shader_version, i));
|
||||
filter.raster_pipelines[i].clear();
|
||||
}
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
{
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(filter.coefficient_buffer);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
filter.uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.compute_shader.version_get_shader(filter.shader_version, filter.use_high_quality ? 0 : 1), 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!prefer_raster_effects) {
|
||||
Vector<String> specular_modes;
|
||||
specular_modes.push_back("\n#define MODE_MERGE\n");
|
||||
@ -2028,31 +1739,16 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) {
|
||||
}
|
||||
|
||||
EffectsRD::~EffectsRD() {
|
||||
if (RD::get_singleton()->uniform_set_is_valid(filter.image_uniform_set)) {
|
||||
RD::get_singleton()->free(filter.image_uniform_set);
|
||||
}
|
||||
|
||||
if (RD::get_singleton()->uniform_set_is_valid(filter.uniform_set)) {
|
||||
RD::get_singleton()->free(filter.uniform_set);
|
||||
}
|
||||
|
||||
RD::get_singleton()->free(default_sampler);
|
||||
RD::get_singleton()->free(default_mipmap_sampler);
|
||||
RD::get_singleton()->free(index_buffer); //array gets freed as dependency
|
||||
RD::get_singleton()->free(filter.coefficient_buffer);
|
||||
|
||||
FSR_upscale.shader.version_free(FSR_upscale.shader_version);
|
||||
TAA_resolve.shader.version_free(TAA_resolve.shader_version);
|
||||
if (prefer_raster_effects) {
|
||||
luminance_reduce_raster.shader.version_free(luminance_reduce_raster.shader_version);
|
||||
roughness.raster_shader.version_free(roughness.shader_version);
|
||||
cubemap_downsampler.raster_shader.version_free(cubemap_downsampler.shader_version);
|
||||
filter.raster_shader.version_free(filter.shader_version);
|
||||
} else {
|
||||
luminance_reduce.shader.version_free(luminance_reduce.shader_version);
|
||||
roughness.compute_shader.version_free(roughness.shader_version);
|
||||
cubemap_downsampler.compute_shader.version_free(cubemap_downsampler.shader_version);
|
||||
filter.compute_shader.version_free(filter.shader_version);
|
||||
}
|
||||
if (!prefer_raster_effects) {
|
||||
specular_merge.shader.version_free(specular_merge.shader_version);
|
||||
@ -2077,6 +1773,5 @@ EffectsRD::~EffectsRD() {
|
||||
RD::get_singleton()->free(ssil.importance_map_load_counter);
|
||||
RD::get_singleton()->free(ssil.projection_uniform_buffer);
|
||||
}
|
||||
cube_to_dp.shader.version_free(cube_to_dp.shader_version);
|
||||
sort.shader.version_free(sort.shader_version);
|
||||
}
|
||||
|
@ -33,13 +33,6 @@
|
||||
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/cube_to_dp.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/cubemap_downsampler.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/cubemap_downsampler_raster.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/cubemap_filter.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/cubemap_filter_raster.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/cubemap_roughness.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/cubemap_roughness_raster.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/fsr_upscale.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/luminance_reduce.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/luminance_reduce_raster.glsl.gen.h"
|
||||
@ -104,24 +97,6 @@ private:
|
||||
RID pipeline;
|
||||
} TAA_resolve;
|
||||
|
||||
struct CubemapRoughnessPushConstant {
|
||||
uint32_t face_id;
|
||||
uint32_t sample_count;
|
||||
float roughness;
|
||||
uint32_t use_direct_write;
|
||||
float face_size;
|
||||
float pad[3];
|
||||
};
|
||||
|
||||
struct CubemapRoughness {
|
||||
CubemapRoughnessPushConstant push_constant;
|
||||
CubemapRoughnessShaderRD compute_shader;
|
||||
CubemapRoughnessRasterShaderRD raster_shader;
|
||||
RID shader_version;
|
||||
RID compute_pipeline;
|
||||
PipelineCacheRD raster_pipeline;
|
||||
} roughness;
|
||||
|
||||
enum LuminanceReduceMode {
|
||||
LUMINANCE_REDUCE_READ,
|
||||
LUMINANCE_REDUCE,
|
||||
@ -167,19 +142,6 @@ private:
|
||||
PipelineCacheRD pipelines[LUMINANCE_REDUCE_FRAGMENT_MAX];
|
||||
} luminance_reduce_raster;
|
||||
|
||||
struct CopyToDPPushConstant {
|
||||
float z_far;
|
||||
float z_near;
|
||||
float texel_size[2];
|
||||
float screen_rect[4];
|
||||
};
|
||||
|
||||
struct CoptToDP {
|
||||
CubeToDpShaderRD shader;
|
||||
RID shader_version;
|
||||
PipelineCacheRD pipeline;
|
||||
} cube_to_dp;
|
||||
|
||||
struct SSEffectsDownsamplePushConstant {
|
||||
float pixel_size[2];
|
||||
float z_far;
|
||||
@ -419,49 +381,6 @@ private:
|
||||
|
||||
} roughness_limiter;
|
||||
|
||||
struct CubemapDownsamplerPushConstant {
|
||||
uint32_t face_size;
|
||||
uint32_t face_id;
|
||||
float pad[2];
|
||||
};
|
||||
|
||||
struct CubemapDownsampler {
|
||||
CubemapDownsamplerPushConstant push_constant;
|
||||
CubemapDownsamplerShaderRD compute_shader;
|
||||
CubemapDownsamplerRasterShaderRD raster_shader;
|
||||
RID shader_version;
|
||||
RID compute_pipeline;
|
||||
PipelineCacheRD raster_pipeline;
|
||||
} cubemap_downsampler;
|
||||
|
||||
enum CubemapFilterMode {
|
||||
FILTER_MODE_HIGH_QUALITY,
|
||||
FILTER_MODE_LOW_QUALITY,
|
||||
FILTER_MODE_HIGH_QUALITY_ARRAY,
|
||||
FILTER_MODE_LOW_QUALITY_ARRAY,
|
||||
FILTER_MODE_MAX,
|
||||
};
|
||||
|
||||
struct CubemapFilterRasterPushConstant {
|
||||
uint32_t mip_level;
|
||||
uint32_t face_id;
|
||||
float pad[2];
|
||||
};
|
||||
|
||||
struct CubemapFilter {
|
||||
CubemapFilterShaderRD compute_shader;
|
||||
CubemapFilterRasterShaderRD raster_shader;
|
||||
RID shader_version;
|
||||
RID compute_pipelines[FILTER_MODE_MAX];
|
||||
PipelineCacheRD raster_pipelines[FILTER_MODE_MAX];
|
||||
|
||||
RID uniform_set;
|
||||
RID image_uniform_set;
|
||||
RID coefficient_buffer;
|
||||
bool use_high_quality;
|
||||
|
||||
} filter;
|
||||
|
||||
enum SpecularMergeMode {
|
||||
SPECULAR_MERGE_ADD,
|
||||
SPECULAR_MERGE_SSR,
|
||||
@ -650,9 +569,6 @@ public:
|
||||
void fsr_upscale(RID p_source_rd_texture, RID p_secondary_texture, RID p_destination_texture, const Size2i &p_internal_size, const Size2i &p_size, float p_fsr_upscale_sharpness);
|
||||
void taa_resolve(RID p_frame, RID p_temp, RID p_depth, RID p_velocity, RID p_prev_velocity, RID p_history, Size2 p_resolution, float p_z_near, float p_z_far);
|
||||
|
||||
void cubemap_roughness(RID p_source_rd_texture, RID p_dest_texture, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);
|
||||
void cubemap_roughness_raster(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);
|
||||
void copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dst_framebuffer, const Rect2 &p_rect, const Vector2 &p_dst_size, float p_z_near, float p_z_far, bool p_dp_flip);
|
||||
void luminance_reduction(RID p_source_texture, const Size2i p_source_size, const Vector<RID> p_reduce, RID p_prev_luminance, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set = false);
|
||||
void luminance_reduction_raster(RID p_source_texture, const Size2i p_source_size, const Vector<RID> p_reduce, Vector<RID> p_fb, RID p_prev_luminance, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set = false);
|
||||
|
||||
@ -703,10 +619,6 @@ public:
|
||||
void screen_space_indirect_lighting(RID p_diffuse, RID p_destination, RID p_normal_buffer, RID p_depth_mipmaps_texture, RID p_ao, const Vector<RID> p_ao_slices, RID p_ao_pong, const Vector<RID> p_ao_pong_slices, RID p_importance_map, RID p_importance_map_pong, RID p_edges, const Vector<RID> p_edges_slices, const CameraMatrix &p_projection, const CameraMatrix &p_last_projection, const SSILSettings &p_settings, bool p_invalidate_uniform_sets, RID &r_gather_uniform_set, RID &r_importance_map_uniform_set, RID &r_projection_uniform_set);
|
||||
|
||||
void roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve);
|
||||
void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size);
|
||||
void cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size);
|
||||
void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);
|
||||
void cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level);
|
||||
|
||||
void screen_space_reflection(RID p_diffuse, RID p_normal_roughness, RS::EnvironmentSSRRoughnessQuality p_roughness_quality, RID p_blur_radius, RID p_blur_radius2, RID p_metallic, const Color &p_metallic_mask, RID p_depth, RID p_scale_depth, RID p_scale_normal, RID p_output, RID p_output_blur, const Size2i &p_screen_size, int p_max_steps, float p_fade_in, float p_fade_out, float p_tolerance, const CameraMatrix &p_camera);
|
||||
void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection);
|
||||
|
@ -5438,9 +5438,9 @@ void RendererSceneRenderRD::_render_shadow_pass(RID p_light, RID p_shadow_atlas,
|
||||
Rect2 atlas_rect_norm = atlas_rect;
|
||||
atlas_rect_norm.position /= float(atlas_size);
|
||||
atlas_rect_norm.size /= float(atlas_size);
|
||||
storage->get_effects()->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), light_projection.get_z_far(), false);
|
||||
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), light_projection.get_z_far(), false);
|
||||
atlas_rect_norm.position += Vector2(dual_paraboloid_offset) * atlas_rect_norm.size;
|
||||
storage->get_effects()->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), light_projection.get_z_far(), true);
|
||||
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), light_projection.get_z_far(), true);
|
||||
|
||||
//restore transform so it can be properly used
|
||||
light_instance_set_shadow_transform(p_light, CameraMatrix(), light_instance->transform, zfar, 0, 0, 0);
|
||||
|
@ -438,19 +438,19 @@ void RendererSceneSkyRD::ReflectionData::update_reflection_data(RendererStorageR
|
||||
}
|
||||
|
||||
void RendererSceneSkyRD::ReflectionData::create_reflection_fast_filter(RendererStorageRD *p_storage, bool p_use_arrays) {
|
||||
EffectsRD *effects = p_storage->get_effects();
|
||||
ERR_FAIL_NULL_MSG(effects, "Effects haven't been initialised");
|
||||
bool prefer_raster_effects = effects->get_prefer_raster_effects();
|
||||
RendererRD::CopyEffects *copy_effects = RendererRD::CopyEffects::get_singleton();
|
||||
ERR_FAIL_NULL_MSG(copy_effects, "Effects haven't been initialised");
|
||||
bool prefer_raster_effects = copy_effects->get_prefer_raster_effects();
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
RD::get_singleton()->draw_command_begin_label("Downsample radiance map");
|
||||
for (int k = 0; k < 6; k++) {
|
||||
effects->cubemap_downsample_raster(radiance_base_cubemap, downsampled_layer.mipmaps[0].framebuffers[k], k, downsampled_layer.mipmaps[0].size);
|
||||
copy_effects->cubemap_downsample_raster(radiance_base_cubemap, downsampled_layer.mipmaps[0].framebuffers[k], k, downsampled_layer.mipmaps[0].size);
|
||||
}
|
||||
|
||||
for (int i = 1; i < downsampled_layer.mipmaps.size(); i++) {
|
||||
for (int k = 0; k < 6; k++) {
|
||||
effects->cubemap_downsample_raster(downsampled_layer.mipmaps[i - 1].view, downsampled_layer.mipmaps[i].framebuffers[k], k, downsampled_layer.mipmaps[i].size);
|
||||
copy_effects->cubemap_downsample_raster(downsampled_layer.mipmaps[i - 1].view, downsampled_layer.mipmaps[i].framebuffers[k], k, downsampled_layer.mipmaps[i].size);
|
||||
}
|
||||
}
|
||||
RD::get_singleton()->draw_command_end_label(); // Downsample Radiance
|
||||
@ -459,24 +459,24 @@ void RendererSceneSkyRD::ReflectionData::create_reflection_fast_filter(RendererS
|
||||
RD::get_singleton()->draw_command_begin_label("filter radiance map into array heads");
|
||||
for (int i = 0; i < layers.size(); i++) {
|
||||
for (int k = 0; k < 6; k++) {
|
||||
effects->cubemap_filter_raster(downsampled_radiance_cubemap, layers[i].mipmaps[0].framebuffers[k], k, i);
|
||||
copy_effects->cubemap_filter_raster(downsampled_radiance_cubemap, layers[i].mipmaps[0].framebuffers[k], k, i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
RD::get_singleton()->draw_command_begin_label("filter radiance map into mipmaps directly");
|
||||
for (int j = 0; j < layers[0].mipmaps.size(); j++) {
|
||||
for (int k = 0; k < 6; k++) {
|
||||
effects->cubemap_filter_raster(downsampled_radiance_cubemap, layers[0].mipmaps[j].framebuffers[k], k, j);
|
||||
copy_effects->cubemap_filter_raster(downsampled_radiance_cubemap, layers[0].mipmaps[j].framebuffers[k], k, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
RD::get_singleton()->draw_command_end_label(); // Filter radiance
|
||||
} else {
|
||||
RD::get_singleton()->draw_command_begin_label("Downsample radiance map");
|
||||
effects->cubemap_downsample(radiance_base_cubemap, downsampled_layer.mipmaps[0].view, downsampled_layer.mipmaps[0].size);
|
||||
copy_effects->cubemap_downsample(radiance_base_cubemap, downsampled_layer.mipmaps[0].view, downsampled_layer.mipmaps[0].size);
|
||||
|
||||
for (int i = 1; i < downsampled_layer.mipmaps.size(); i++) {
|
||||
effects->cubemap_downsample(downsampled_layer.mipmaps[i - 1].view, downsampled_layer.mipmaps[i].view, downsampled_layer.mipmaps[i].size);
|
||||
copy_effects->cubemap_downsample(downsampled_layer.mipmaps[i - 1].view, downsampled_layer.mipmaps[i].view, downsampled_layer.mipmaps[i].size);
|
||||
}
|
||||
RD::get_singleton()->draw_command_end_label(); // Downsample Radiance
|
||||
Vector<RID> views;
|
||||
@ -490,26 +490,26 @@ void RendererSceneSkyRD::ReflectionData::create_reflection_fast_filter(RendererS
|
||||
}
|
||||
}
|
||||
RD::get_singleton()->draw_command_begin_label("Fast filter radiance");
|
||||
effects->cubemap_filter(downsampled_radiance_cubemap, views, p_use_arrays);
|
||||
copy_effects->cubemap_filter(downsampled_radiance_cubemap, views, p_use_arrays);
|
||||
RD::get_singleton()->draw_command_end_label(); // Filter radiance
|
||||
}
|
||||
}
|
||||
|
||||
void RendererSceneSkyRD::ReflectionData::create_reflection_importance_sample(RendererStorageRD *p_storage, bool p_use_arrays, int p_cube_side, int p_base_layer, uint32_t p_sky_ggx_samples_quality) {
|
||||
EffectsRD *effects = p_storage->get_effects();
|
||||
ERR_FAIL_NULL_MSG(effects, "Effects haven't been initialised");
|
||||
bool prefer_raster_effects = effects->get_prefer_raster_effects();
|
||||
RendererRD::CopyEffects *copy_effects = RendererRD::CopyEffects::get_singleton();
|
||||
ERR_FAIL_NULL_MSG(copy_effects, "Effects haven't been initialised");
|
||||
bool prefer_raster_effects = copy_effects->get_prefer_raster_effects();
|
||||
|
||||
if (prefer_raster_effects) {
|
||||
if (p_base_layer == 1) {
|
||||
RD::get_singleton()->draw_command_begin_label("Downsample radiance map");
|
||||
for (int k = 0; k < 6; k++) {
|
||||
effects->cubemap_downsample_raster(radiance_base_cubemap, downsampled_layer.mipmaps[0].framebuffers[k], k, downsampled_layer.mipmaps[0].size);
|
||||
copy_effects->cubemap_downsample_raster(radiance_base_cubemap, downsampled_layer.mipmaps[0].framebuffers[k], k, downsampled_layer.mipmaps[0].size);
|
||||
}
|
||||
|
||||
for (int i = 1; i < downsampled_layer.mipmaps.size(); i++) {
|
||||
for (int k = 0; k < 6; k++) {
|
||||
effects->cubemap_downsample_raster(downsampled_layer.mipmaps[i - 1].view, downsampled_layer.mipmaps[i].framebuffers[k], k, downsampled_layer.mipmaps[i].size);
|
||||
copy_effects->cubemap_downsample_raster(downsampled_layer.mipmaps[i - 1].view, downsampled_layer.mipmaps[i].framebuffers[k], k, downsampled_layer.mipmaps[i].size);
|
||||
}
|
||||
}
|
||||
RD::get_singleton()->draw_command_end_label(); // Downsample Radiance
|
||||
@ -518,7 +518,7 @@ void RendererSceneSkyRD::ReflectionData::create_reflection_importance_sample(Ren
|
||||
RD::get_singleton()->draw_command_begin_label("High Quality filter radiance");
|
||||
if (p_use_arrays) {
|
||||
for (int k = 0; k < 6; k++) {
|
||||
effects->cubemap_roughness_raster(
|
||||
copy_effects->cubemap_roughness_raster(
|
||||
downsampled_radiance_cubemap,
|
||||
layers[p_base_layer].mipmaps[0].framebuffers[k],
|
||||
k,
|
||||
@ -528,7 +528,7 @@ void RendererSceneSkyRD::ReflectionData::create_reflection_importance_sample(Ren
|
||||
}
|
||||
} else {
|
||||
for (int k = 0; k < 6; k++) {
|
||||
effects->cubemap_roughness_raster(
|
||||
copy_effects->cubemap_roughness_raster(
|
||||
downsampled_radiance_cubemap,
|
||||
layers[0].mipmaps[p_base_layer].framebuffers[k],
|
||||
k,
|
||||
@ -540,19 +540,19 @@ void RendererSceneSkyRD::ReflectionData::create_reflection_importance_sample(Ren
|
||||
} else {
|
||||
if (p_base_layer == 1) {
|
||||
RD::get_singleton()->draw_command_begin_label("Downsample radiance map");
|
||||
effects->cubemap_downsample(radiance_base_cubemap, downsampled_layer.mipmaps[0].view, downsampled_layer.mipmaps[0].size);
|
||||
copy_effects->cubemap_downsample(radiance_base_cubemap, downsampled_layer.mipmaps[0].view, downsampled_layer.mipmaps[0].size);
|
||||
|
||||
for (int i = 1; i < downsampled_layer.mipmaps.size(); i++) {
|
||||
effects->cubemap_downsample(downsampled_layer.mipmaps[i - 1].view, downsampled_layer.mipmaps[i].view, downsampled_layer.mipmaps[i].size);
|
||||
copy_effects->cubemap_downsample(downsampled_layer.mipmaps[i - 1].view, downsampled_layer.mipmaps[i].view, downsampled_layer.mipmaps[i].size);
|
||||
}
|
||||
RD::get_singleton()->draw_command_end_label(); // Downsample Radiance
|
||||
}
|
||||
|
||||
RD::get_singleton()->draw_command_begin_label("High Quality filter radiance");
|
||||
if (p_use_arrays) {
|
||||
effects->cubemap_roughness(downsampled_radiance_cubemap, layers[p_base_layer].views[0], p_cube_side, p_sky_ggx_samples_quality, float(p_base_layer) / (layers.size() - 1.0), layers[p_base_layer].mipmaps[0].size.x);
|
||||
copy_effects->cubemap_roughness(downsampled_radiance_cubemap, layers[p_base_layer].views[0], p_cube_side, p_sky_ggx_samples_quality, float(p_base_layer) / (layers.size() - 1.0), layers[p_base_layer].mipmaps[0].size.x);
|
||||
} else {
|
||||
effects->cubemap_roughness(
|
||||
copy_effects->cubemap_roughness(
|
||||
downsampled_radiance_cubemap,
|
||||
layers[0].views[p_base_layer],
|
||||
p_cube_side,
|
||||
@ -565,9 +565,9 @@ void RendererSceneSkyRD::ReflectionData::create_reflection_importance_sample(Ren
|
||||
}
|
||||
|
||||
void RendererSceneSkyRD::ReflectionData::update_reflection_mipmaps(RendererStorageRD *p_storage, int p_start, int p_end) {
|
||||
EffectsRD *effects = p_storage->get_effects();
|
||||
ERR_FAIL_NULL_MSG(effects, "Effects haven't been initialised");
|
||||
bool prefer_raster_effects = effects->get_prefer_raster_effects();
|
||||
RendererRD::CopyEffects *copy_effects = RendererRD::CopyEffects::get_singleton();
|
||||
ERR_FAIL_NULL_MSG(copy_effects, "Effects haven't been initialised");
|
||||
bool prefer_raster_effects = copy_effects->get_prefer_raster_effects();
|
||||
|
||||
RD::get_singleton()->draw_command_begin_label("Update Radiance Cubemap Array Mipmaps");
|
||||
for (int i = p_start; i < p_end; i++) {
|
||||
@ -577,11 +577,11 @@ void RendererSceneSkyRD::ReflectionData::update_reflection_mipmaps(RendererStora
|
||||
if (prefer_raster_effects) {
|
||||
for (int k = 0; k < 6; k++) {
|
||||
RID framebuffer = layers[i].mipmaps[j + 1].framebuffers[k];
|
||||
effects->cubemap_downsample_raster(view, framebuffer, k, size);
|
||||
copy_effects->cubemap_downsample_raster(view, framebuffer, k, size);
|
||||
}
|
||||
} else {
|
||||
RID texture = layers[i].views[j + 1];
|
||||
effects->cubemap_downsample(view, texture, size);
|
||||
copy_effects->cubemap_downsample(view, texture, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user