mirror of
https://github.com/godotengine/godot.git
synced 2025-10-31 21:51:22 +00:00
Implemented AMD's FSR as a computer shader for upscaling 3D scenes
This commit is contained in:
parent
5efe80f308
commit
20deb0917d
39 changed files with 4807 additions and 150 deletions
|
|
@ -1227,6 +1227,100 @@ RendererStorageRD::CanvasTexture::~CanvasTexture() {
|
|||
clear_sets();
|
||||
}
|
||||
|
||||
void RendererStorageRD::sampler_rd_configure_custom(float p_mipmap_bias) {
|
||||
for (int i = 1; i < RS::CANVAS_ITEM_TEXTURE_FILTER_MAX; i++) {
|
||||
for (int j = 1; j < RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX; j++) {
|
||||
RD::SamplerState sampler_state;
|
||||
switch (i) {
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST: {
|
||||
sampler_state.mag_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
sampler_state.min_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
sampler_state.max_lod = 0;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR: {
|
||||
sampler_state.mag_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
sampler_state.min_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
sampler_state.max_lod = 0;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: {
|
||||
sampler_state.mag_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
sampler_state.min_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
if (GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter")) {
|
||||
sampler_state.mip_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
} else {
|
||||
sampler_state.mip_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
}
|
||||
sampler_state.lod_bias = p_mipmap_bias;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: {
|
||||
sampler_state.mag_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
sampler_state.min_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
if (GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter")) {
|
||||
sampler_state.mip_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
} else {
|
||||
sampler_state.mip_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
}
|
||||
sampler_state.lod_bias = p_mipmap_bias;
|
||||
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC: {
|
||||
sampler_state.mag_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
sampler_state.min_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
if (GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter")) {
|
||||
sampler_state.mip_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
} else {
|
||||
sampler_state.mip_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
}
|
||||
sampler_state.lod_bias = p_mipmap_bias;
|
||||
sampler_state.use_anisotropy = true;
|
||||
sampler_state.anisotropy_max = 1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"));
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC: {
|
||||
sampler_state.mag_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
sampler_state.min_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
if (GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter")) {
|
||||
sampler_state.mip_filter = RD::SAMPLER_FILTER_NEAREST;
|
||||
} else {
|
||||
sampler_state.mip_filter = RD::SAMPLER_FILTER_LINEAR;
|
||||
}
|
||||
sampler_state.lod_bias = p_mipmap_bias;
|
||||
sampler_state.use_anisotropy = true;
|
||||
sampler_state.anisotropy_max = 1 << int(GLOBAL_GET("rendering/textures/default_filters/anisotropic_filtering_level"));
|
||||
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
switch (j) {
|
||||
case RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED: {
|
||||
sampler_state.repeat_u = RD::SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
|
||||
sampler_state.repeat_v = RD::SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
|
||||
sampler_state.repeat_w = RD::SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
|
||||
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED: {
|
||||
sampler_state.repeat_u = RD::SAMPLER_REPEAT_MODE_REPEAT;
|
||||
sampler_state.repeat_v = RD::SAMPLER_REPEAT_MODE_REPEAT;
|
||||
sampler_state.repeat_w = RD::SAMPLER_REPEAT_MODE_REPEAT;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR: {
|
||||
sampler_state.repeat_u = RD::SAMPLER_REPEAT_MODE_MIRRORED_REPEAT;
|
||||
sampler_state.repeat_v = RD::SAMPLER_REPEAT_MODE_MIRRORED_REPEAT;
|
||||
sampler_state.repeat_w = RD::SAMPLER_REPEAT_MODE_MIRRORED_REPEAT;
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
|
||||
if (custom_rd_samplers[i][j].is_valid()) {
|
||||
RD::get_singleton()->free(custom_rd_samplers[i][j]);
|
||||
}
|
||||
|
||||
custom_rd_samplers[i][j] = RD::get_singleton()->sampler_create(sampler_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RID RendererStorageRD::canvas_texture_allocate() {
|
||||
return canvas_texture_owner.allocate_rid();
|
||||
}
|
||||
|
|
@ -9774,6 +9868,9 @@ RendererStorageRD::RendererStorageRD() {
|
|||
}
|
||||
}
|
||||
|
||||
//custom sampler
|
||||
sampler_rd_configure_custom(0.0f);
|
||||
|
||||
//default rd buffers
|
||||
{
|
||||
Vector<uint8_t> buffer;
|
||||
|
|
@ -10104,6 +10201,15 @@ RendererStorageRD::~RendererStorageRD() {
|
|||
}
|
||||
}
|
||||
|
||||
//custom samplers
|
||||
for (int i = 1; i < RS::CANVAS_ITEM_TEXTURE_FILTER_MAX; i++) {
|
||||
for (int j = 0; j < RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX; j++) {
|
||||
if (custom_rd_samplers[i][j].is_valid()) {
|
||||
RD::get_singleton()->free(custom_rd_samplers[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//def buffers
|
||||
for (int i = 0; i < DEFAULT_RD_BUFFER_MAX; i++) {
|
||||
RD::get_singleton()->free(mesh_default_rd_buffers[i]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue