renderer_scene_render.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*************************************************************************/
  2. /* renderer_scene_render.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef RENDERINGSERVERSCENERENDER_H
  31. #define RENDERINGSERVERSCENERENDER_H
  32. #include "core/math/camera_matrix.h"
  33. #include "core/templates/paged_array.h"
  34. #include "servers/rendering/renderer_storage.h"
  35. class RendererSceneRender {
  36. public:
  37. /* SHADOW ATLAS API */
  38. virtual RID shadow_atlas_create() = 0;
  39. virtual void shadow_atlas_set_size(RID p_atlas, int p_size) = 0;
  40. virtual void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) = 0;
  41. virtual bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) = 0;
  42. virtual void directional_shadow_atlas_set_size(int p_size) = 0;
  43. virtual int get_directional_light_shadow_size(RID p_light_intance) = 0;
  44. virtual void set_directional_shadow_count(int p_count) = 0;
  45. /* SDFGI UPDATE */
  46. struct InstanceBase;
  47. virtual void sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) = 0;
  48. virtual int sdfgi_get_pending_region_count(RID p_render_buffers) const = 0;
  49. virtual AABB sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const = 0;
  50. virtual uint32_t sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const = 0;
  51. virtual void sdfgi_update_probes(RID p_render_buffers, RID p_environment, const PagedArray<RID> &p_directionals, const RID *p_positional_light_instances, uint32_t p_positional_light_count) = 0;
  52. /* SKY API */
  53. virtual RID sky_create() = 0;
  54. virtual void sky_set_radiance_size(RID p_sky, int p_radiance_size) = 0;
  55. virtual void sky_set_mode(RID p_sky, RS::SkyMode p_samples) = 0;
  56. virtual void sky_set_material(RID p_sky, RID p_material) = 0;
  57. virtual Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) = 0;
  58. /* ENVIRONMENT API */
  59. virtual RID environment_create() = 0;
  60. virtual void environment_set_background(RID p_env, RS::EnvironmentBG p_bg) = 0;
  61. virtual void environment_set_sky(RID p_env, RID p_sky) = 0;
  62. virtual void environment_set_sky_custom_fov(RID p_env, float p_scale) = 0;
  63. virtual void environment_set_sky_orientation(RID p_env, const Basis &p_orientation) = 0;
  64. virtual void environment_set_bg_color(RID p_env, const Color &p_color) = 0;
  65. virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0;
  66. virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0;
  67. virtual void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()) = 0;
  68. // FIXME: Disabled during Vulkan refactoring, should be ported.
  69. #if 0
  70. virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) = 0;
  71. #endif
  72. virtual void environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap) = 0;
  73. virtual void environment_glow_set_use_bicubic_upscale(bool p_enable) = 0;
  74. virtual void environment_glow_set_use_high_quality(bool p_enable) = 0;
  75. virtual void environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_light, float p_light_energy, float p_length, float p_detail_spread, float p_gi_inject, RS::EnvVolumetricFogShadowFilter p_shadow_filter) = 0;
  76. virtual void environment_set_volumetric_fog_volume_size(int p_size, int p_depth) = 0;
  77. virtual void environment_set_volumetric_fog_filter_active(bool p_enable) = 0;
  78. virtual void environment_set_volumetric_fog_directional_shadow_shrink_size(int p_shrink_size) = 0;
  79. virtual void environment_set_volumetric_fog_positional_shadow_shrink_size(int p_shrink_size) = 0;
  80. virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) = 0;
  81. virtual void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) = 0;
  82. virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) = 0;
  83. virtual void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) = 0;
  84. virtual void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, bool p_use_multibounce, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) = 0;
  85. virtual void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) = 0;
  86. virtual void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) = 0;
  87. virtual void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) = 0;
  88. virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction) = 0;
  89. virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_aerial_perspective) = 0;
  90. virtual Ref<Image> environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size) = 0;
  91. virtual bool is_environment(RID p_env) const = 0;
  92. virtual RS::EnvironmentBG environment_get_background(RID p_env) const = 0;
  93. virtual int environment_get_canvas_max_layer(RID p_env) const = 0;
  94. virtual RID camera_effects_create() = 0;
  95. virtual void camera_effects_set_dof_blur_quality(RS::DOFBlurQuality p_quality, bool p_use_jitter) = 0;
  96. virtual void camera_effects_set_dof_blur_bokeh_shape(RS::DOFBokehShape p_shape) = 0;
  97. virtual void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) = 0;
  98. virtual void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) = 0;
  99. virtual void shadows_quality_set(RS::ShadowQuality p_quality) = 0;
  100. virtual void directional_shadow_quality_set(RS::ShadowQuality p_quality) = 0;
  101. struct InstanceBase : public RendererStorage::InstanceBaseDependency {
  102. RS::InstanceType base_type;
  103. RID base;
  104. RID skeleton;
  105. RID material_override;
  106. RID mesh_instance; //only used for meshes and when skeleton/blendshapes exist
  107. Transform transform;
  108. float lod_bias;
  109. int depth_layer;
  110. uint32_t layer_mask;
  111. //RID sampled_light;
  112. Vector<RID> materials;
  113. Vector<RID> light_instances;
  114. Vector<RID> reflection_probe_instances;
  115. Vector<RID> gi_probe_instances;
  116. RS::ShadowCastingSetting cast_shadows;
  117. //fit in 32 bits
  118. bool mirror : 8;
  119. bool receive_shadows : 8;
  120. bool visible : 8;
  121. bool baked_light : 2; //this flag is only to know if it actually did use baked light
  122. bool dynamic_gi : 2; //this flag is only to know if it actually did use baked light
  123. bool redraw_if_visible : 4;
  124. float depth; //used for sorting
  125. InstanceBase *lightmap;
  126. Rect2 lightmap_uv_scale;
  127. int lightmap_slice_index;
  128. uint32_t lightmap_cull_index;
  129. Vector<Color> lightmap_sh; //spherical harmonic
  130. AABB aabb;
  131. AABB transformed_aabb;
  132. AABB prev_transformed_aabb;
  133. struct InstanceShaderParameter {
  134. int32_t index = -1;
  135. Variant value;
  136. Variant default_value;
  137. PropertyInfo info;
  138. };
  139. Map<StringName, InstanceShaderParameter> instance_shader_parameters;
  140. bool instance_allocated_shader_parameters = false;
  141. int32_t instance_allocated_shader_parameters_offset = -1;
  142. InstanceBase() {
  143. base_type = RS::INSTANCE_NONE;
  144. cast_shadows = RS::SHADOW_CASTING_SETTING_ON;
  145. receive_shadows = true;
  146. visible = true;
  147. depth_layer = 0;
  148. layer_mask = 1;
  149. instance_version = 0;
  150. baked_light = false;
  151. dynamic_gi = false;
  152. redraw_if_visible = false;
  153. lightmap_slice_index = 0;
  154. lightmap = nullptr;
  155. lightmap_cull_index = 0;
  156. lod_bias = 1.0;
  157. }
  158. virtual ~InstanceBase() {
  159. }
  160. };
  161. virtual RID light_instance_create(RID p_light) = 0;
  162. virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) = 0;
  163. virtual void light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb) = 0;
  164. virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_shadow_texel_size, float p_bias_scale = 1.0, float p_range_begin = 0, const Vector2 &p_uv_scale = Vector2()) = 0;
  165. virtual void light_instance_mark_visible(RID p_light_instance) = 0;
  166. virtual bool light_instances_can_render_shadow_cube() const {
  167. return true;
  168. }
  169. virtual RID reflection_atlas_create() = 0;
  170. virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) = 0;
  171. virtual int reflection_atlas_get_size(RID p_ref_atlas) const = 0;
  172. virtual RID reflection_probe_instance_create(RID p_probe) = 0;
  173. virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform) = 0;
  174. virtual void reflection_probe_release_atlas_index(RID p_instance) = 0;
  175. virtual bool reflection_probe_instance_needs_redraw(RID p_instance) = 0;
  176. virtual bool reflection_probe_instance_has_reflection(RID p_instance) = 0;
  177. virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) = 0;
  178. virtual bool reflection_probe_instance_postprocess_step(RID p_instance) = 0;
  179. virtual RID decal_instance_create(RID p_decal) = 0;
  180. virtual void decal_instance_set_transform(RID p_decal, const Transform &p_transform) = 0;
  181. virtual RID gi_probe_instance_create(RID p_gi_probe) = 0;
  182. virtual void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform) = 0;
  183. virtual bool gi_probe_needs_update(RID p_probe) const = 0;
  184. virtual void gi_probe_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RendererSceneRender::InstanceBase *> &p_dynamic_objects) = 0;
  185. virtual void gi_probe_set_quality(RS::GIProbeQuality) = 0;
  186. virtual void render_scene(RID p_render_buffers, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<InstanceBase *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_gi_probes, const PagedArray<RID> &p_decals, const PagedArray<InstanceBase *> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold) = 0;
  187. virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, const PagedArray<InstanceBase *> &p_instances, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0, float p_screen_lod_threshold = 0.0) = 0;
  188. virtual void render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<InstanceBase *> &p_instances, RID p_framebuffer, const Rect2i &p_region) = 0;
  189. virtual void render_sdfgi(RID p_render_buffers, int p_region, const PagedArray<InstanceBase *> &p_instances) = 0;
  190. virtual void render_sdfgi_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const PagedArray<RID> *p_positional_lights) = 0;
  191. virtual void render_particle_collider_heightfield(RID p_collider, const Transform &p_transform, const PagedArray<InstanceBase *> &p_instances) = 0;
  192. virtual void set_scene_pass(uint64_t p_pass) = 0;
  193. virtual void set_time(double p_time, double p_step) = 0;
  194. virtual void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) = 0;
  195. virtual RID render_buffers_create() = 0;
  196. virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_debanding) = 0;
  197. virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_limit) = 0;
  198. virtual bool screen_space_roughness_limiter_is_active() const = 0;
  199. virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) = 0;
  200. virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) = 0;
  201. virtual TypedArray<Image> bake_render_uv2(RID p_base, const Vector<RID> &p_material_overrides, const Size2i &p_image_size) = 0;
  202. virtual bool free(RID p_rid) = 0;
  203. virtual void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) = 0;
  204. virtual bool is_low_end() const = 0;
  205. virtual void update() = 0;
  206. virtual ~RendererSceneRender() {}
  207. };
  208. #endif // RENDERINGSERVERSCENERENDER_H