2019-11-05 11:01:00 +00:00
|
|
|
/*************************************************************************/
|
2020-12-04 18:26:24 +00:00
|
|
|
/* effects_rd.h */
|
2019-11-05 11:01:00 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-03 20:27:34 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2019-11-05 11:01:00 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2020-12-04 18:26:24 +00:00
|
|
|
#ifndef EFFECTS_RD_H
|
|
|
|
#define EFFECTS_RD_H
|
2019-07-27 13:23:24 +00:00
|
|
|
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-19 23:11:13 +00:00
|
|
|
#include "core/math/projection.h"
|
2020-12-04 18:26:24 +00:00
|
|
|
#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
|
2021-11-23 21:16:03 +00:00
|
|
|
#include "servers/rendering/renderer_rd/shaders/fsr_upscale.glsl.gen.h"
|
2020-12-04 18:26:24 +00:00
|
|
|
#include "servers/rendering/renderer_rd/shaders/luminance_reduce.glsl.gen.h"
|
2021-07-20 11:40:16 +00:00
|
|
|
#include "servers/rendering/renderer_rd/shaders/luminance_reduce_raster.glsl.gen.h"
|
2020-12-04 18:26:24 +00:00
|
|
|
#include "servers/rendering/renderer_rd/shaders/roughness_limiter.glsl.gen.h"
|
|
|
|
#include "servers/rendering/renderer_rd/shaders/sort.glsl.gen.h"
|
|
|
|
#include "servers/rendering/renderer_rd/shaders/subsurface_scattering.glsl.gen.h"
|
2022-04-04 14:10:22 +00:00
|
|
|
#include "servers/rendering/renderer_rd/shaders/taa_resolve.glsl.gen.h"
|
2021-05-07 13:19:04 +00:00
|
|
|
#include "servers/rendering/renderer_scene_render.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
|
|
|
|
#include "servers/rendering_server.h"
|
2019-07-27 13:23:24 +00:00
|
|
|
|
2020-12-04 18:26:24 +00:00
|
|
|
class EffectsRD {
|
2021-07-27 13:33:47 +00:00
|
|
|
private:
|
|
|
|
bool prefer_raster_effects;
|
|
|
|
|
2021-11-23 21:16:03 +00:00
|
|
|
enum FSRUpscalePass {
|
|
|
|
FSR_UPSCALE_PASS_EASU = 0,
|
|
|
|
FSR_UPSCALE_PASS_RCAS = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FSRUpscalePushConstant {
|
|
|
|
float resolution_width;
|
|
|
|
float resolution_height;
|
|
|
|
float upscaled_width;
|
|
|
|
float upscaled_height;
|
|
|
|
float sharpness;
|
|
|
|
int pass;
|
|
|
|
int _unused0, _unused1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FSRUpscale {
|
|
|
|
FSRUpscalePushConstant push_constant;
|
|
|
|
FsrUpscaleShaderRD shader;
|
|
|
|
RID shader_version;
|
|
|
|
RID pipeline;
|
|
|
|
} FSR_upscale;
|
|
|
|
|
2022-04-04 14:10:22 +00:00
|
|
|
struct TAAResolvePushConstant {
|
|
|
|
float resolution_width;
|
|
|
|
float resolution_height;
|
|
|
|
float disocclusion_threshold;
|
|
|
|
float disocclusion_scale;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TAAResolve {
|
|
|
|
TAAResolvePushConstant push_constant;
|
|
|
|
TaaResolveShaderRD shader;
|
|
|
|
RID shader_version;
|
|
|
|
RID pipeline;
|
|
|
|
} TAA_resolve;
|
|
|
|
|
2020-01-12 01:26:52 +00:00
|
|
|
enum LuminanceReduceMode {
|
|
|
|
LUMINANCE_REDUCE_READ,
|
|
|
|
LUMINANCE_REDUCE,
|
|
|
|
LUMINANCE_REDUCE_WRITE,
|
|
|
|
LUMINANCE_REDUCE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LuminanceReducePushConstant {
|
|
|
|
int32_t source_size[2];
|
|
|
|
float max_luminance;
|
|
|
|
float min_luminance;
|
|
|
|
float exposure_adjust;
|
|
|
|
float pad[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LuminanceReduce {
|
|
|
|
LuminanceReducePushConstant push_constant;
|
|
|
|
LuminanceReduceShaderRD shader;
|
|
|
|
RID shader_version;
|
|
|
|
RID pipelines[LUMINANCE_REDUCE_MAX];
|
|
|
|
} luminance_reduce;
|
|
|
|
|
2021-07-20 11:40:16 +00:00
|
|
|
enum LuminanceReduceRasterMode {
|
|
|
|
LUMINANCE_REDUCE_FRAGMENT_FIRST,
|
|
|
|
LUMINANCE_REDUCE_FRAGMENT,
|
|
|
|
LUMINANCE_REDUCE_FRAGMENT_FINAL,
|
|
|
|
LUMINANCE_REDUCE_FRAGMENT_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LuminanceReduceRasterPushConstant {
|
|
|
|
int32_t source_size[2];
|
|
|
|
int32_t dest_size[2];
|
|
|
|
float exposure_adjust;
|
|
|
|
float min_luminance;
|
|
|
|
float max_luminance;
|
2021-07-26 11:31:15 +00:00
|
|
|
uint32_t pad1;
|
2021-07-20 11:40:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LuminanceReduceFragment {
|
|
|
|
LuminanceReduceRasterPushConstant push_constant;
|
|
|
|
LuminanceReduceRasterShaderRD shader;
|
|
|
|
RID shader_version;
|
|
|
|
PipelineCacheRD pipelines[LUMINANCE_REDUCE_FRAGMENT_MAX];
|
|
|
|
} luminance_reduce_raster;
|
|
|
|
|
2020-01-26 23:09:40 +00:00
|
|
|
struct RoughnessLimiterPushConstant {
|
|
|
|
int32_t screen_size[2];
|
|
|
|
float curve;
|
|
|
|
uint32_t pad;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RoughnessLimiter {
|
|
|
|
RoughnessLimiterPushConstant push_constant;
|
|
|
|
RoughnessLimiterShaderRD shader;
|
|
|
|
RID shader_version;
|
|
|
|
RID pipeline;
|
|
|
|
|
|
|
|
} roughness_limiter;
|
|
|
|
|
2020-04-04 02:42:26 +00:00
|
|
|
struct SubSurfaceScatteringPushConstant {
|
|
|
|
int32_t screen_size[2];
|
|
|
|
float camera_z_far;
|
|
|
|
float camera_z_near;
|
|
|
|
|
|
|
|
uint32_t vertical;
|
|
|
|
uint32_t orthogonal;
|
|
|
|
float unit_size;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
float depth_scale;
|
|
|
|
uint32_t pad[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SubSurfaceScattering {
|
|
|
|
SubSurfaceScatteringPushConstant push_constant;
|
|
|
|
SubsurfaceScatteringShaderRD shader;
|
|
|
|
RID shader_version;
|
|
|
|
RID pipelines[3]; //3 quality levels
|
|
|
|
} sss;
|
|
|
|
|
2020-08-19 13:38:24 +00:00
|
|
|
enum SortMode {
|
|
|
|
SORT_MODE_BLOCK,
|
|
|
|
SORT_MODE_STEP,
|
|
|
|
SORT_MODE_INNER,
|
|
|
|
SORT_MODE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Sort {
|
|
|
|
struct PushConstant {
|
|
|
|
uint32_t total_elements;
|
|
|
|
uint32_t pad[3];
|
|
|
|
int32_t job_params[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
SortShaderRD shader;
|
|
|
|
RID shader_version;
|
|
|
|
RID pipelines[SORT_MODE_MAX];
|
|
|
|
} sort;
|
|
|
|
|
2019-07-27 13:23:24 +00:00
|
|
|
RID default_sampler;
|
2020-01-10 00:40:26 +00:00
|
|
|
RID default_mipmap_sampler;
|
2019-07-27 13:23:24 +00:00
|
|
|
RID index_buffer;
|
|
|
|
RID index_array;
|
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<RID, RID> texture_to_uniform_set_cache;
|
|
|
|
HashMap<RID, RID> input_to_uniform_set_cache;
|
2019-07-27 13:23:24 +00:00
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
HashMap<RID, RID> image_to_uniform_set_cache;
|
2020-04-02 02:24:52 +00:00
|
|
|
|
|
|
|
struct TexturePair {
|
|
|
|
RID texture1;
|
|
|
|
RID texture2;
|
|
|
|
_FORCE_INLINE_ bool operator<(const TexturePair &p_pair) const {
|
|
|
|
if (texture1 == p_pair.texture1) {
|
|
|
|
return texture2 < p_pair.texture2;
|
|
|
|
} else {
|
|
|
|
return texture1 < p_pair.texture1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-08 05:37:09 +00:00
|
|
|
struct TextureSamplerPair {
|
|
|
|
RID texture;
|
|
|
|
RID sampler;
|
|
|
|
_FORCE_INLINE_ bool operator<(const TextureSamplerPair &p_pair) const {
|
|
|
|
if (texture == p_pair.texture) {
|
|
|
|
return sampler < p_pair.sampler;
|
|
|
|
} else {
|
|
|
|
return texture < p_pair.texture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
RBMap<TexturePair, RID> texture_pair_to_uniform_set_cache;
|
|
|
|
RBMap<RID, RID> texture_to_compute_uniform_set_cache;
|
|
|
|
RBMap<TexturePair, RID> texture_pair_to_compute_uniform_set_cache;
|
|
|
|
RBMap<TexturePair, RID> image_pair_to_compute_uniform_set_cache;
|
|
|
|
RBMap<TextureSamplerPair, RID> texture_sampler_to_compute_uniform_set_cache;
|
2020-01-12 01:26:52 +00:00
|
|
|
|
|
|
|
RID _get_uniform_set_from_image(RID p_texture);
|
2020-01-10 00:40:26 +00:00
|
|
|
RID _get_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
|
2020-01-12 01:26:52 +00:00
|
|
|
RID _get_compute_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
|
2019-07-27 13:23:24 +00:00
|
|
|
|
|
|
|
public:
|
2021-07-27 13:33:47 +00:00
|
|
|
bool get_prefer_raster_effects();
|
|
|
|
|
2021-11-23 21:16:03 +00:00
|
|
|
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);
|
2022-04-04 14:10:22 +00:00
|
|
|
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);
|
2020-01-10 00:40:26 +00:00
|
|
|
|
2020-01-12 01:26:52 +00:00
|
|
|
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);
|
2021-07-20 11:40:16 +00:00
|
|
|
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);
|
|
|
|
|
2020-01-26 23:09:40 +00:00
|
|
|
void roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve);
|
|
|
|
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-19 23:11:13 +00:00
|
|
|
void sub_surface_scattering(RID p_diffuse, RID p_diffuse2, RID p_depth, const Projection &p_camera, const Size2i &p_screen_size, float p_scale, float p_depth_scale, RS::SubSurfaceScatteringQuality p_quality);
|
2020-04-02 02:24:52 +00:00
|
|
|
|
2020-08-19 13:38:24 +00:00
|
|
|
void sort_buffer(RID p_uniform_set, int p_size);
|
|
|
|
|
2021-07-20 11:40:16 +00:00
|
|
|
EffectsRD(bool p_prefer_raster_effects);
|
2020-12-04 18:26:24 +00:00
|
|
|
~EffectsRD();
|
2019-07-27 13:23:24 +00:00
|
|
|
};
|
|
|
|
|
2022-07-23 21:41:51 +00:00
|
|
|
#endif // EFFECTS_RD_H
|