2019-06-22 16:34:26 +00:00
|
|
|
/*************************************************************************/
|
2020-02-11 13:01:43 +00:00
|
|
|
/* rasterizer_scene_high_end_rd.h */
|
2019-06-22 16:34:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2020-02-11 13:01:43 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2019-06-22 16:34:26 +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-01-21 17:24:22 +00:00
|
|
|
#ifndef RASTERIZER_SCENE_HIGHEND_RD_H
|
|
|
|
#define RASTERIZER_SCENE_HIGHEND_RD_H
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "servers/rendering/rasterizer_rd/rasterizer_scene_rd.h"
|
|
|
|
#include "servers/rendering/rasterizer_rd/rasterizer_storage_rd.h"
|
|
|
|
#include "servers/rendering/rasterizer_rd/render_pipeline_vertex_format_cache_rd.h"
|
|
|
|
#include "servers/rendering/rasterizer_rd/shaders/scene_high_end.glsl.gen.h"
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2020-01-21 17:24:22 +00:00
|
|
|
class RasterizerSceneHighEndRD : public RasterizerSceneRD {
|
2020-01-25 10:18:55 +00:00
|
|
|
enum {
|
|
|
|
SCENE_UNIFORM_SET = 0,
|
|
|
|
RADIANCE_UNIFORM_SET = 1,
|
|
|
|
VIEW_DEPENDANT_UNIFORM_SET = 2,
|
|
|
|
RENDER_BUFFERS_UNIFORM_SET = 3,
|
|
|
|
TRANSFORMS_UNIFORM_SET = 4,
|
|
|
|
MATERIAL_UNIFORM_SET = 5
|
|
|
|
};
|
|
|
|
|
2020-06-25 13:33:28 +00:00
|
|
|
enum {
|
|
|
|
SDFGI_MAX_CASCADES = 8,
|
|
|
|
MAX_GI_PROBES = 8
|
|
|
|
};
|
|
|
|
|
2019-09-15 09:58:38 +00:00
|
|
|
/* Scene Shader */
|
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
enum ShaderVersion {
|
|
|
|
SHADER_VERSION_DEPTH_PASS,
|
2019-09-07 01:51:27 +00:00
|
|
|
SHADER_VERSION_DEPTH_PASS_DP,
|
2019-08-18 22:40:52 +00:00
|
|
|
SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS,
|
2020-06-25 13:33:28 +00:00
|
|
|
SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_GIPROBE,
|
2019-10-11 02:14:56 +00:00
|
|
|
SHADER_VERSION_DEPTH_PASS_WITH_MATERIAL,
|
2020-06-25 13:33:28 +00:00
|
|
|
SHADER_VERSION_DEPTH_PASS_WITH_SDF,
|
2019-08-18 22:40:52 +00:00
|
|
|
SHADER_VERSION_COLOR_PASS,
|
2020-06-25 13:33:28 +00:00
|
|
|
SHADER_VERSION_COLOR_PASS_WITH_FORWARD_GI,
|
2019-08-18 22:40:52 +00:00
|
|
|
SHADER_VERSION_COLOR_PASS_WITH_SEPARATE_SPECULAR,
|
|
|
|
SHADER_VERSION_LIGHTMAP_COLOR_PASS,
|
|
|
|
SHADER_VERSION_LIGHTMAP_COLOR_PASS_WITH_SEPARATE_SPECULAR,
|
|
|
|
SHADER_VERSION_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct {
|
2020-01-21 17:24:22 +00:00
|
|
|
SceneHighEndShaderRD scene_shader;
|
2019-08-18 22:40:52 +00:00
|
|
|
ShaderCompilerRD compiler;
|
|
|
|
} shader;
|
|
|
|
|
|
|
|
RasterizerStorageRD *storage;
|
|
|
|
|
|
|
|
/* Material */
|
|
|
|
|
|
|
|
struct ShaderData : public RasterizerStorageRD::ShaderData {
|
|
|
|
enum BlendMode { //used internally
|
|
|
|
BLEND_MODE_MIX,
|
|
|
|
BLEND_MODE_ADD,
|
|
|
|
BLEND_MODE_SUB,
|
|
|
|
BLEND_MODE_MUL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum DepthDraw {
|
|
|
|
DEPTH_DRAW_DISABLED,
|
|
|
|
DEPTH_DRAW_OPAQUE,
|
|
|
|
DEPTH_DRAW_ALWAYS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum DepthTest {
|
|
|
|
DEPTH_TEST_DISABLED,
|
|
|
|
DEPTH_TEST_ENABLED
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Cull {
|
|
|
|
CULL_DISABLED,
|
|
|
|
CULL_FRONT,
|
|
|
|
CULL_BACK
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CullVariant {
|
|
|
|
CULL_VARIANT_NORMAL,
|
|
|
|
CULL_VARIANT_REVERSED,
|
|
|
|
CULL_VARIANT_DOUBLE_SIDED,
|
|
|
|
CULL_VARIANT_MAX
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
bool valid;
|
|
|
|
RID version;
|
|
|
|
uint32_t vertex_input_mask;
|
2020-03-27 18:21:27 +00:00
|
|
|
RenderPipelineVertexFormatCacheRD pipelines[CULL_VARIANT_MAX][RS::PRIMITIVE_MAX][SHADER_VERSION_MAX];
|
2019-08-18 22:40:52 +00:00
|
|
|
|
|
|
|
String path;
|
|
|
|
|
|
|
|
Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
|
|
|
Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms;
|
|
|
|
|
|
|
|
Vector<uint32_t> ubo_offsets;
|
|
|
|
uint32_t ubo_size;
|
|
|
|
|
|
|
|
String code;
|
|
|
|
Map<StringName, RID> default_texture_params;
|
|
|
|
|
|
|
|
DepthDraw depth_draw;
|
|
|
|
DepthTest depth_test;
|
|
|
|
|
|
|
|
bool uses_point_size;
|
|
|
|
bool uses_alpha;
|
|
|
|
bool uses_blend_alpha;
|
|
|
|
bool uses_depth_pre_pass;
|
|
|
|
bool uses_discard;
|
|
|
|
bool uses_roughness;
|
|
|
|
bool uses_normal;
|
|
|
|
|
|
|
|
bool unshaded;
|
|
|
|
bool uses_vertex;
|
|
|
|
bool uses_sss;
|
2020-04-08 01:51:52 +00:00
|
|
|
bool uses_transmittance;
|
2019-08-18 22:40:52 +00:00
|
|
|
bool uses_screen_texture;
|
|
|
|
bool uses_depth_texture;
|
|
|
|
bool uses_normal_texture;
|
|
|
|
bool uses_time;
|
|
|
|
bool writes_modelview_or_projection;
|
|
|
|
bool uses_world_coordinates;
|
|
|
|
|
|
|
|
uint64_t last_pass = 0;
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
|
|
|
virtual void set_code(const String &p_Code);
|
|
|
|
virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
|
|
|
|
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
|
2020-04-17 02:52:00 +00:00
|
|
|
void get_instance_param_list(List<RasterizerStorage::InstanceShaderParam> *p_param_list) const;
|
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
virtual bool is_param_texture(const StringName &p_param) const;
|
|
|
|
virtual bool is_animated() const;
|
|
|
|
virtual bool casts_shadows() const;
|
|
|
|
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
|
|
|
ShaderData();
|
|
|
|
virtual ~ShaderData();
|
|
|
|
};
|
|
|
|
|
|
|
|
RasterizerStorageRD::ShaderData *_create_shader_func();
|
|
|
|
static RasterizerStorageRD::ShaderData *_create_shader_funcs() {
|
2020-01-21 17:24:22 +00:00
|
|
|
return static_cast<RasterizerSceneHighEndRD *>(singleton)->_create_shader_func();
|
2019-08-18 22:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct MaterialData : public RasterizerStorageRD::MaterialData {
|
|
|
|
uint64_t last_frame;
|
|
|
|
ShaderData *shader_data;
|
|
|
|
RID uniform_buffer;
|
|
|
|
RID uniform_set;
|
|
|
|
Vector<RID> texture_cache;
|
|
|
|
Vector<uint8_t> ubo_data;
|
|
|
|
uint64_t last_pass = 0;
|
|
|
|
uint32_t index = 0;
|
|
|
|
RID next_pass;
|
|
|
|
uint8_t priority;
|
|
|
|
virtual void set_render_priority(int p_priority);
|
|
|
|
virtual void set_next_pass(RID p_pass);
|
|
|
|
virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty);
|
|
|
|
virtual ~MaterialData();
|
|
|
|
};
|
|
|
|
|
|
|
|
RasterizerStorageRD::MaterialData *_create_material_func(ShaderData *p_shader);
|
|
|
|
static RasterizerStorageRD::MaterialData *_create_material_funcs(RasterizerStorageRD::ShaderData *p_shader) {
|
2020-01-21 17:24:22 +00:00
|
|
|
return static_cast<RasterizerSceneHighEndRD *>(singleton)->_create_material_func(static_cast<ShaderData *>(p_shader));
|
2019-08-18 22:40:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 20:54:03 +00:00
|
|
|
/* Push Constant */
|
|
|
|
|
|
|
|
struct PushConstant {
|
2019-09-07 01:51:27 +00:00
|
|
|
uint32_t index;
|
2020-05-01 12:34:23 +00:00
|
|
|
uint32_t pad;
|
|
|
|
float bake_uv2_offset[2];
|
2019-08-20 20:54:03 +00:00
|
|
|
};
|
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
/* Framebuffer */
|
|
|
|
|
2020-01-25 10:18:55 +00:00
|
|
|
struct RenderBufferDataHighEnd : public RenderBufferData {
|
2019-08-18 22:40:52 +00:00
|
|
|
//for rendering, may be MSAAd
|
2020-04-12 18:33:57 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
RID color;
|
|
|
|
RID depth;
|
2020-01-25 10:18:55 +00:00
|
|
|
RID specular;
|
2020-06-25 13:33:28 +00:00
|
|
|
RID normal_roughness_buffer;
|
|
|
|
RID giprobe_buffer;
|
|
|
|
|
|
|
|
RID ambient_buffer;
|
|
|
|
RID reflection_buffer;
|
2020-04-12 18:33:57 +00:00
|
|
|
|
|
|
|
RS::ViewportMSAA msaa;
|
|
|
|
RD::TextureSamples texture_samples;
|
|
|
|
|
|
|
|
RID color_msaa;
|
|
|
|
RID depth_msaa;
|
|
|
|
RID specular_msaa;
|
2020-06-25 13:33:28 +00:00
|
|
|
RID normal_roughness_buffer_msaa;
|
2020-04-12 18:33:57 +00:00
|
|
|
RID roughness_buffer_msaa;
|
2020-06-25 13:33:28 +00:00
|
|
|
RID giprobe_buffer_msaa;
|
2020-04-12 18:33:57 +00:00
|
|
|
|
2019-10-03 20:39:08 +00:00
|
|
|
RID depth_fb;
|
2020-01-25 10:18:55 +00:00
|
|
|
RID depth_normal_roughness_fb;
|
2020-06-25 13:33:28 +00:00
|
|
|
RID depth_normal_roughness_giprobe_fb;
|
2019-08-18 22:40:52 +00:00
|
|
|
RID color_fb;
|
2020-01-25 10:18:55 +00:00
|
|
|
RID color_specular_fb;
|
2020-04-02 02:24:52 +00:00
|
|
|
RID specular_only_fb;
|
2019-08-18 22:40:52 +00:00
|
|
|
int width, height;
|
|
|
|
|
2020-06-25 13:33:28 +00:00
|
|
|
RID render_sdfgi_uniform_set;
|
2020-01-25 10:18:55 +00:00
|
|
|
void ensure_specular();
|
2020-06-25 13:33:28 +00:00
|
|
|
void ensure_gi();
|
|
|
|
void ensure_giprobe();
|
2019-08-18 22:40:52 +00:00
|
|
|
void clear();
|
2020-03-27 18:21:27 +00:00
|
|
|
virtual void configure(RID p_color_buffer, RID p_depth_buffer, int p_width, int p_height, RS::ViewportMSAA p_msaa);
|
2019-08-18 22:40:52 +00:00
|
|
|
|
2020-01-25 10:18:55 +00:00
|
|
|
RID uniform_set;
|
|
|
|
|
|
|
|
~RenderBufferDataHighEnd();
|
2019-08-18 22:40:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual RenderBufferData *_create_render_buffer_data();
|
2020-06-25 13:33:28 +00:00
|
|
|
void _allocate_normal_roughness_texture(RenderBufferDataHighEnd *rb);
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-09-07 01:51:27 +00:00
|
|
|
RID shadow_sampler;
|
2019-08-26 20:43:58 +00:00
|
|
|
RID render_base_uniform_set;
|
2020-01-25 10:18:55 +00:00
|
|
|
RID view_dependant_uniform_set;
|
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
uint64_t lightmap_texture_array_version = 0xFFFFFFFF;
|
|
|
|
|
2020-01-25 10:18:55 +00:00
|
|
|
virtual void _base_uniforms_changed();
|
|
|
|
void _render_buffers_clear_uniform_set(RenderBufferDataHighEnd *rb);
|
|
|
|
virtual void _render_buffers_uniform_set_changed(RID p_render_buffers);
|
2020-01-26 23:09:40 +00:00
|
|
|
virtual RID _render_buffers_get_normal_texture(RID p_render_buffers);
|
2020-06-25 13:33:28 +00:00
|
|
|
virtual RID _render_buffers_get_ambient_texture(RID p_render_buffers);
|
|
|
|
virtual RID _render_buffers_get_reflection_texture(RID p_render_buffers);
|
2020-01-25 10:18:55 +00:00
|
|
|
|
2019-10-03 20:39:08 +00:00
|
|
|
void _update_render_base_uniform_set();
|
2020-06-25 13:33:28 +00:00
|
|
|
void _setup_view_dependant_uniform_set(RID p_shadow_atlas, RID p_reflection_atlas, RID *p_gi_probe_cull_result, int p_gi_probe_cull_count);
|
2020-01-25 10:18:55 +00:00
|
|
|
void _update_render_buffers_uniform_set(RID p_render_buffers);
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
struct LightmapData {
|
|
|
|
float normal_xform[12];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LightmapCaptureData {
|
|
|
|
float sh[9 * 4];
|
|
|
|
};
|
|
|
|
|
2019-09-14 03:37:42 +00:00
|
|
|
enum {
|
2020-06-25 13:33:28 +00:00
|
|
|
INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6,
|
|
|
|
INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7,
|
2020-05-01 12:34:23 +00:00
|
|
|
INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 8,
|
|
|
|
INSTANCE_DATA_FLAG_USE_LIGHTMAP = 1 << 9,
|
|
|
|
INSTANCE_DATA_FLAG_USE_SH_LIGHTMAP = 1 << 10,
|
|
|
|
INSTANCE_DATA_FLAG_USE_GIPROBE = 1 << 11,
|
2019-09-14 03:37:42 +00:00
|
|
|
INSTANCE_DATA_FLAG_MULTIMESH = 1 << 12,
|
|
|
|
INSTANCE_DATA_FLAG_MULTIMESH_FORMAT_2D = 1 << 13,
|
|
|
|
INSTANCE_DATA_FLAG_MULTIMESH_HAS_COLOR = 1 << 14,
|
|
|
|
INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15,
|
|
|
|
INSTANCE_DATA_FLAGS_MULTIMESH_STRIDE_SHIFT = 16,
|
|
|
|
INSTANCE_DATA_FLAGS_MULTIMESH_STRIDE_MASK = 0x7,
|
2019-09-23 21:53:05 +00:00
|
|
|
INSTANCE_DATA_FLAG_SKELETON = 1 << 19,
|
2019-09-14 03:37:42 +00:00
|
|
|
};
|
|
|
|
|
2019-09-07 01:51:27 +00:00
|
|
|
struct InstanceData {
|
|
|
|
float transform[16];
|
|
|
|
float normal_transform[16];
|
|
|
|
uint32_t flags;
|
2020-04-17 02:52:00 +00:00
|
|
|
uint32_t instance_uniforms_ofs; //instance_offset in instancing/skeleton buffer
|
2019-09-07 01:51:27 +00:00
|
|
|
uint32_t gi_offset; //GI information when using lightmapping (VCT or lightmap)
|
|
|
|
uint32_t mask;
|
2020-05-01 12:34:23 +00:00
|
|
|
float lightmap_uv_scale[4];
|
2019-09-07 01:51:27 +00:00
|
|
|
};
|
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
struct SceneState {
|
|
|
|
struct UBO {
|
|
|
|
float projection_matrix[16];
|
|
|
|
float inv_projection_matrix[16];
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
float camera_matrix[16];
|
|
|
|
float inv_camera_matrix[16];
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
float viewport_size[2];
|
|
|
|
float screen_pixel_size[2];
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
float time;
|
|
|
|
float reflection_multiplier;
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2020-04-08 01:51:52 +00:00
|
|
|
uint32_t pancake_shadows;
|
2020-04-10 09:30:36 +00:00
|
|
|
uint32_t pad;
|
|
|
|
|
|
|
|
float directional_penumbra_shadow_kernel[128]; //32 vec4s
|
|
|
|
float directional_soft_shadow_kernel[128];
|
|
|
|
float penumbra_shadow_kernel[128];
|
|
|
|
float soft_shadow_kernel[128];
|
2020-04-08 01:51:52 +00:00
|
|
|
|
2020-04-10 09:30:36 +00:00
|
|
|
uint32_t directional_penumbra_shadow_samples;
|
|
|
|
uint32_t directional_soft_shadow_samples;
|
|
|
|
uint32_t penumbra_shadow_samples;
|
|
|
|
uint32_t soft_shadow_samples;
|
2020-04-09 18:11:15 +00:00
|
|
|
|
2019-08-26 20:43:58 +00:00
|
|
|
float ambient_light_color_energy[4];
|
|
|
|
|
|
|
|
float ambient_color_sky_mix;
|
|
|
|
uint32_t use_ambient_light;
|
|
|
|
uint32_t use_ambient_cubemap;
|
|
|
|
uint32_t use_reflection_cubemap;
|
|
|
|
|
|
|
|
float radiance_inverse_xform[12];
|
2019-09-07 01:51:27 +00:00
|
|
|
|
|
|
|
float shadow_atlas_pixel_size[2];
|
|
|
|
float directional_shadow_pixel_size[2];
|
|
|
|
|
|
|
|
uint32_t directional_light_count;
|
|
|
|
float dual_paraboloid_side;
|
|
|
|
float z_far;
|
2020-01-21 17:24:22 +00:00
|
|
|
float z_near;
|
2020-01-25 10:18:55 +00:00
|
|
|
|
|
|
|
uint32_t ssao_enabled;
|
|
|
|
float ssao_light_affect;
|
|
|
|
float ssao_ao_affect;
|
2020-01-26 23:09:40 +00:00
|
|
|
uint32_t roughness_limiter_enabled;
|
2020-01-25 10:18:55 +00:00
|
|
|
|
2020-06-25 13:33:28 +00:00
|
|
|
float roughness_limiter_amount;
|
|
|
|
float roughness_limiter_limit;
|
|
|
|
uint32_t roughness_limiter_pad[2];
|
|
|
|
|
2020-01-25 10:18:55 +00:00
|
|
|
float ao_color[4];
|
2020-05-01 12:34:23 +00:00
|
|
|
|
2020-06-25 13:33:28 +00:00
|
|
|
float sdf_to_bounds[16];
|
|
|
|
|
|
|
|
int32_t sdf_offset[3];
|
2020-05-01 12:34:23 +00:00
|
|
|
uint32_t material_uv2_mode;
|
2020-06-25 13:33:28 +00:00
|
|
|
|
|
|
|
int32_t sdf_size[3];
|
|
|
|
uint32_t gi_upscale_for_msaa;
|
2020-08-13 01:21:01 +00:00
|
|
|
|
|
|
|
uint32_t volumetric_fog_enabled;
|
|
|
|
float volumetric_fog_inv_length;
|
|
|
|
float volumetric_fog_detail_spread;
|
|
|
|
uint32_t volumetric_fog_pad;
|
2020-08-14 01:07:49 +00:00
|
|
|
|
|
|
|
// Fog
|
|
|
|
|
|
|
|
uint32_t fog_enabled;
|
|
|
|
float fog_density;
|
|
|
|
float fog_height;
|
|
|
|
float fog_height_density;
|
|
|
|
|
|
|
|
float fog_light_color[3];
|
|
|
|
float fog_sun_scatter;
|
2019-08-18 22:40:52 +00:00
|
|
|
};
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
UBO ubo;
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
RID uniform_buffer;
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
LightmapData *lightmaps;
|
|
|
|
uint32_t max_lightmaps;
|
|
|
|
RID lightmap_buffer;
|
|
|
|
|
|
|
|
LightmapCaptureData *lightmap_captures;
|
|
|
|
uint32_t max_lightmap_captures;
|
|
|
|
RID lightmap_capture_buffer;
|
|
|
|
|
2019-09-07 01:51:27 +00:00
|
|
|
RID instance_buffer;
|
|
|
|
InstanceData *instances;
|
|
|
|
uint32_t max_instances;
|
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
bool used_screen_texture = false;
|
|
|
|
bool used_normal_texture = false;
|
|
|
|
bool used_depth_texture = false;
|
|
|
|
bool used_sss = false;
|
|
|
|
uint32_t current_shader_index = 0;
|
|
|
|
uint32_t current_material_index = 0;
|
2020-05-01 12:34:23 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
} scene_state;
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
/* Render List */
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
struct RenderList {
|
|
|
|
int max_elements;
|
|
|
|
|
|
|
|
struct Element {
|
|
|
|
RasterizerScene::InstanceBase *instance;
|
|
|
|
MaterialData *material;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
//from least significant to most significant in sort, TODO: should be endian swapped on big endian
|
2019-09-07 01:51:27 +00:00
|
|
|
uint64_t geometry_index : 20;
|
|
|
|
uint64_t material_index : 15;
|
|
|
|
uint64_t shader_index : 12;
|
|
|
|
uint64_t uses_instancing : 1;
|
2020-06-25 13:33:28 +00:00
|
|
|
uint64_t uses_forward_gi : 1;
|
2019-09-07 01:51:27 +00:00
|
|
|
uint64_t uses_lightmap : 1;
|
|
|
|
uint64_t depth_layer : 4;
|
|
|
|
uint64_t priority : 8;
|
2019-08-18 22:40:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint64_t sort_key;
|
|
|
|
};
|
|
|
|
uint32_t surface_index;
|
|
|
|
};
|
|
|
|
|
|
|
|
Element *base_elements;
|
|
|
|
Element **elements;
|
|
|
|
|
|
|
|
int element_count;
|
|
|
|
int alpha_element_count;
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
element_count = 0;
|
|
|
|
alpha_element_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//should eventually be replaced by radix
|
|
|
|
|
|
|
|
struct SortByKey {
|
|
|
|
_FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
|
|
|
|
return A->sort_key < B->sort_key;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void sort_by_key(bool p_alpha) {
|
|
|
|
SortArray<Element *, SortByKey> sorter;
|
|
|
|
if (p_alpha) {
|
|
|
|
sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
|
|
|
|
} else {
|
|
|
|
sorter.sort(elements, element_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SortByDepth {
|
|
|
|
_FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
|
|
|
|
return A->instance->depth < B->instance->depth;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void sort_by_depth(bool p_alpha) { //used for shadows
|
|
|
|
|
|
|
|
SortArray<Element *, SortByDepth> sorter;
|
|
|
|
if (p_alpha) {
|
|
|
|
sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
|
|
|
|
} else {
|
|
|
|
sorter.sort(elements, element_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SortByReverseDepthAndPriority {
|
|
|
|
_FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
|
|
|
|
uint32_t layer_A = uint32_t(A->priority);
|
|
|
|
uint32_t layer_B = uint32_t(B->priority);
|
|
|
|
if (layer_A == layer_B) {
|
|
|
|
return A->instance->depth > B->instance->depth;
|
|
|
|
} else {
|
|
|
|
return layer_A < layer_B;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void sort_by_reverse_depth_and_priority(bool p_alpha) { //used for alpha
|
|
|
|
|
|
|
|
SortArray<Element *, SortByReverseDepthAndPriority> sorter;
|
|
|
|
if (p_alpha) {
|
|
|
|
sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
|
|
|
|
} else {
|
|
|
|
sorter.sort(elements, element_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Element *add_element() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (element_count + alpha_element_count >= max_elements) {
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-18 22:40:52 +00:00
|
|
|
elements[element_count] = &base_elements[element_count];
|
|
|
|
return elements[element_count++];
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Element *add_alpha_element() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (element_count + alpha_element_count >= max_elements) {
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-18 22:40:52 +00:00
|
|
|
int idx = max_elements - alpha_element_count - 1;
|
|
|
|
elements[idx] = &base_elements[idx];
|
|
|
|
alpha_element_count++;
|
|
|
|
return elements[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
element_count = 0;
|
|
|
|
alpha_element_count = 0;
|
|
|
|
elements = memnew_arr(Element *, max_elements);
|
|
|
|
base_elements = memnew_arr(Element, max_elements);
|
2020-05-14 14:41:43 +00:00
|
|
|
for (int i = 0; i < max_elements; i++) {
|
2019-08-18 22:40:52 +00:00
|
|
|
elements[i] = &base_elements[i]; // assign elements
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-18 22:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderList() {
|
|
|
|
max_elements = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~RenderList() {
|
|
|
|
memdelete_arr(elements);
|
|
|
|
memdelete_arr(base_elements);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RenderList render_list;
|
|
|
|
|
2020-01-21 17:24:22 +00:00
|
|
|
static RasterizerSceneHighEndRD *singleton;
|
2019-08-18 22:40:52 +00:00
|
|
|
uint64_t render_pass;
|
|
|
|
double time;
|
|
|
|
RID default_shader;
|
|
|
|
RID default_material;
|
2019-10-04 01:59:14 +00:00
|
|
|
RID overdraw_material_shader;
|
|
|
|
RID overdraw_material;
|
|
|
|
RID wireframe_material_shader;
|
|
|
|
RID wireframe_material;
|
2019-08-18 22:40:52 +00:00
|
|
|
RID default_shader_rd;
|
2020-06-25 13:33:28 +00:00
|
|
|
RID default_shader_sdfgi_rd;
|
2020-01-25 10:18:55 +00:00
|
|
|
RID default_radiance_uniform_set;
|
|
|
|
RID default_render_buffers_uniform_set;
|
2019-08-18 22:40:52 +00:00
|
|
|
|
2019-09-14 03:37:42 +00:00
|
|
|
RID default_vec4_xform_buffer;
|
|
|
|
RID default_vec4_xform_uniform_set;
|
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
enum PassMode {
|
|
|
|
PASS_MODE_COLOR,
|
|
|
|
PASS_MODE_COLOR_SPECULAR,
|
|
|
|
PASS_MODE_COLOR_TRANSPARENT,
|
|
|
|
PASS_MODE_SHADOW,
|
2019-09-07 01:51:27 +00:00
|
|
|
PASS_MODE_SHADOW_DP,
|
2019-08-18 22:40:52 +00:00
|
|
|
PASS_MODE_DEPTH,
|
|
|
|
PASS_MODE_DEPTH_NORMAL_ROUGHNESS,
|
2020-06-25 13:33:28 +00:00
|
|
|
PASS_MODE_DEPTH_NORMAL_ROUGHNESS_GIPROBE,
|
2019-10-11 02:14:56 +00:00
|
|
|
PASS_MODE_DEPTH_MATERIAL,
|
2020-06-25 13:33:28 +00:00
|
|
|
PASS_MODE_SDF,
|
2019-08-18 22:40:52 +00:00
|
|
|
};
|
|
|
|
|
2020-06-25 13:33:28 +00:00
|
|
|
void _setup_environment(RID p_environment, RID p_render_buffers, const CameraMatrix &p_cam_projection, const Transform &p_cam_transform, RID p_reflection_probe, bool p_no_fog, const Size2 &p_screen_pixel_size, RID p_shadow_atlas, bool p_flip_y, const Color &p_default_bg_color, float p_znear, float p_zfar, bool p_opaque_render_buffers = false, bool p_pancake_shadows = false);
|
2020-05-01 12:34:23 +00:00
|
|
|
void _setup_lightmaps(InstanceBase **p_lightmap_cull_result, int p_lightmap_cull_count, const Transform &p_cam_transform);
|
2019-08-18 22:40:52 +00:00
|
|
|
|
2020-06-25 13:33:28 +00:00
|
|
|
void _fill_instances(RenderList::Element **p_elements, int p_element_count, bool p_for_depth, bool p_has_sdfgi = false, bool p_has_opaque_gi = false);
|
2020-05-01 12:34:23 +00:00
|
|
|
void _render_list(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderList::Element **p_elements, int p_element_count, bool p_reverse_cull, PassMode p_pass_mode, bool p_no_gi, RID p_radiance_uniform_set, RID p_render_buffers_uniform_set, bool p_force_wireframe = false, const Vector2 &p_uv_offset = Vector2());
|
2020-06-25 13:33:28 +00:00
|
|
|
_FORCE_INLINE_ void _add_geometry(InstanceBase *p_instance, uint32_t p_surface, RID p_material, PassMode p_pass_mode, uint32_t p_geometry_index, bool p_using_sdfgi = false);
|
|
|
|
_FORCE_INLINE_ void _add_geometry_with_material(InstanceBase *p_instance, uint32_t p_surface, MaterialData *p_material, RID p_material_rid, PassMode p_pass_mode, uint32_t p_geometry_index, bool p_using_sdfgi = false);
|
|
|
|
|
|
|
|
void _fill_render_list(InstanceBase **p_cull_result, int p_cull_count, PassMode p_pass_mode, bool p_using_sdfgi = false);
|
2019-08-18 22:40:52 +00:00
|
|
|
|
2020-06-25 13:33:28 +00:00
|
|
|
Map<Size2i, RID> sdfgi_framebuffer_size_cache;
|
2019-08-18 22:40:52 +00:00
|
|
|
|
|
|
|
protected:
|
2020-07-22 23:39:09 +00:00
|
|
|
virtual void _render_scene(RID p_render_buffer, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, int p_directional_light_count, RID *p_gi_probe_cull_result, int p_gi_probe_cull_count, InstanceBase **p_lightmap_cull_result, int p_lightmap_cull_count, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, const Color &p_default_bg_color);
|
2020-04-08 01:51:52 +00:00
|
|
|
virtual void _render_shadow(RID p_framebuffer, InstanceBase **p_cull_result, int p_cull_count, const CameraMatrix &p_projection, const Transform &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake);
|
2019-10-11 02:14:56 +00:00
|
|
|
virtual void _render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region);
|
2020-05-01 12:34:23 +00:00
|
|
|
virtual void _render_uv2(InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region);
|
2020-06-25 13:33:28 +00:00
|
|
|
virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, InstanceBase **p_cull_result, int p_cull_count, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture);
|
2020-10-08 00:29:49 +00:00
|
|
|
virtual void _render_particle_collider_heightfield(RID p_fb, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, InstanceBase **p_cull_result, int p_cull_count);
|
2019-08-18 22:40:52 +00:00
|
|
|
|
|
|
|
public:
|
2020-01-12 01:26:52 +00:00
|
|
|
virtual void set_time(double p_time, double p_step);
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2019-08-18 22:40:52 +00:00
|
|
|
virtual bool free(RID p_rid);
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2020-01-21 17:24:22 +00:00
|
|
|
RasterizerSceneHighEndRD(RasterizerStorageRD *p_storage);
|
|
|
|
~RasterizerSceneHighEndRD();
|
2019-06-11 18:43:37 +00:00
|
|
|
};
|
2020-01-21 17:24:22 +00:00
|
|
|
#endif // RASTERIZER_SCENE_HIGHEND_RD_H
|