Improved shadow rendering efficiency
-Do not bind attributes that are not needed -Improve a bit more how meshoptimizer interacts with Godot
This commit is contained in:
parent
7ad29ed64e
commit
7bf90c7888
5 changed files with 59 additions and 18 deletions
|
@ -236,18 +236,6 @@ void EditorSceneImporterMesh::generate_lods() {
|
|||
}
|
||||
uint32_t vertex_count = vertices.size();
|
||||
const Vector3 *vertices_ptr = vertices.ptr();
|
||||
AABB aabb;
|
||||
{
|
||||
for (uint32_t j = 0; j < vertex_count; j++) {
|
||||
if (j == 0) {
|
||||
aabb.position = vertices_ptr[j];
|
||||
} else {
|
||||
aabb.expand_to(vertices_ptr[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float longest_axis_size = aabb.get_longest_axis_size();
|
||||
|
||||
int min_indices = 10;
|
||||
int index_target = indices.size() / 2;
|
||||
|
@ -263,7 +251,7 @@ void EditorSceneImporterMesh::generate_lods() {
|
|||
}
|
||||
new_indices.resize(new_len);
|
||||
Surface::LOD lod;
|
||||
lod.distance = error * longest_axis_size;
|
||||
lod.distance = error;
|
||||
lod.indices = new_indices;
|
||||
surfaces.write[i].lods.push_back(lod);
|
||||
index_target /= 2;
|
||||
|
|
|
@ -2718,7 +2718,7 @@ RID RendererSceneRenderForward::_setup_sdfgi_render_pass_uniform_set(RID p_albed
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
sdfgi_pass_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, default_shader_rd, RENDER_PASS_UNIFORM_SET);
|
||||
sdfgi_pass_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, default_shader_sdfgi_rd, RENDER_PASS_UNIFORM_SET);
|
||||
return sdfgi_pass_uniform_set;
|
||||
}
|
||||
|
||||
|
@ -2909,6 +2909,7 @@ RendererSceneRenderForward::RendererSceneRenderForward(RendererStorageRD *p_stor
|
|||
actions.renames["DIFFUSE_LIGHT"] = "diffuse_light";
|
||||
actions.renames["SPECULAR_LIGHT"] = "specular_light";
|
||||
|
||||
actions.usage_defines["NORMAL"] = "#define NORMAL_USED\n";
|
||||
actions.usage_defines["TANGENT"] = "#define TANGENT_USED\n";
|
||||
actions.usage_defines["BINORMAL"] = "@TANGENT";
|
||||
actions.usage_defines["RIM"] = "#define LIGHT_RIM_USED\n";
|
||||
|
|
|
@ -9,7 +9,13 @@ VERSION_DEFINES
|
|||
/* INPUT ATTRIBS */
|
||||
|
||||
layout(location = 0) in vec3 vertex_attrib;
|
||||
|
||||
//only for pure render depth when normal is not used
|
||||
|
||||
#ifdef NORMAL_USED
|
||||
layout(location = 1) in vec3 normal_attrib;
|
||||
#endif
|
||||
|
||||
#if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED)
|
||||
layout(location = 2) in vec4 tangent_attrib;
|
||||
#endif
|
||||
|
@ -18,7 +24,9 @@ layout(location = 2) in vec4 tangent_attrib;
|
|||
layout(location = 3) in vec4 color_attrib;
|
||||
#endif
|
||||
|
||||
#ifdef UV_USED
|
||||
layout(location = 4) in vec2 uv_attrib;
|
||||
#endif
|
||||
|
||||
#if defined(UV2_USED) || defined(USE_LIGHTMAP) || defined(MODE_RENDER_MATERIAL)
|
||||
layout(location = 5) in vec2 uv2_attrib;
|
||||
|
@ -51,13 +59,18 @@ layout(location = 11) in vec4 weight_attrib;
|
|||
/* Varyings */
|
||||
|
||||
layout(location = 0) out vec3 vertex_interp;
|
||||
|
||||
#ifdef NORMAL_USED
|
||||
layout(location = 1) out vec3 normal_interp;
|
||||
#endif
|
||||
|
||||
#if defined(COLOR_USED)
|
||||
layout(location = 2) out vec4 color_interp;
|
||||
#endif
|
||||
|
||||
#ifdef UV_USED
|
||||
layout(location = 3) out vec2 uv_interp;
|
||||
#endif
|
||||
|
||||
#if defined(UV2_USED) || defined(USE_LIGHTMAP)
|
||||
layout(location = 4) out vec2 uv2_interp;
|
||||
|
@ -138,7 +151,9 @@ void main() {
|
|||
}
|
||||
|
||||
vec3 vertex = vertex_attrib;
|
||||
#ifdef NORMAL_USED
|
||||
vec3 normal = normal_attrib * 2.0 - 1.0;
|
||||
#endif
|
||||
|
||||
#if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED)
|
||||
vec3 tangent = tangent_attrib.xyz * 2.0 - 1.0;
|
||||
|
@ -171,7 +186,10 @@ void main() {
|
|||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UV_USED
|
||||
uv_interp = uv_attrib;
|
||||
#endif
|
||||
|
||||
#if defined(UV2_USED) || defined(USE_LIGHTMAP)
|
||||
uv2_interp = uv2_attrib;
|
||||
|
@ -215,9 +233,12 @@ VERTEX_SHADER_CODE
|
|||
#if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED)
|
||||
|
||||
vertex = (modelview * vec4(vertex, 1.0)).xyz;
|
||||
#ifdef NORMAL_USED
|
||||
normal = modelview_normal * normal;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED)
|
||||
|
||||
binormal = modelview_normal * binormal;
|
||||
|
@ -238,7 +259,9 @@ VERTEX_SHADER_CODE
|
|||
#endif
|
||||
|
||||
vertex_interp = vertex;
|
||||
#ifdef NORMAL_USED
|
||||
normal_interp = normal;
|
||||
#endif
|
||||
|
||||
#if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED)
|
||||
tangent_interp = tangent;
|
||||
|
@ -250,7 +273,6 @@ VERTEX_SHADER_CODE
|
|||
#ifdef MODE_DUAL_PARABOLOID
|
||||
|
||||
vertex_interp.z *= scene_data.dual_paraboloid_side;
|
||||
normal_interp.z *= scene_data.dual_paraboloid_side;
|
||||
|
||||
dp_clip = vertex_interp.z; //this attempts to avoid noise caused by objects sent to the other parabolloid side due to bias
|
||||
|
||||
|
@ -301,13 +323,18 @@ VERSION_DEFINES
|
|||
/* Varyings */
|
||||
|
||||
layout(location = 0) in vec3 vertex_interp;
|
||||
|
||||
#ifdef NORMAL_USED
|
||||
layout(location = 1) in vec3 normal_interp;
|
||||
#endif
|
||||
|
||||
#if defined(COLOR_USED)
|
||||
layout(location = 2) in vec4 color_interp;
|
||||
#endif
|
||||
|
||||
#ifdef UV_USED
|
||||
layout(location = 3) in vec2 uv_interp;
|
||||
#endif
|
||||
|
||||
#if defined(UV2_USED) || defined(USE_LIGHTMAP)
|
||||
layout(location = 4) in vec2 uv2_interp;
|
||||
|
@ -1799,6 +1826,8 @@ void main() {
|
|||
vec3 binormal = vec3(0.0);
|
||||
vec3 tangent = vec3(0.0);
|
||||
#endif
|
||||
|
||||
#ifdef NORMAL_USED
|
||||
vec3 normal = normalize(normal_interp);
|
||||
|
||||
#if defined(DO_SIDE_CHECK)
|
||||
|
@ -1807,7 +1836,11 @@ void main() {
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif //NORMAL_USED
|
||||
|
||||
#ifdef UV_USED
|
||||
vec2 uv = uv_interp;
|
||||
#endif
|
||||
|
||||
#if defined(UV2_USED) || defined(USE_LIGHTMAP)
|
||||
vec2 uv2 = uv2_interp;
|
||||
|
@ -1994,6 +2027,7 @@ FRAGMENT_SHADER_CODE
|
|||
#endif //not render depth
|
||||
/////////////////////// LIGHTING //////////////////////////////
|
||||
|
||||
#ifdef NORMAL_USED
|
||||
if (scene_data.roughness_limiter_enabled) {
|
||||
//http://www.jp.square-enix.com/tech/library/pdf/ImprovedGeometricSpecularAA.pdf
|
||||
float roughness2 = roughness * roughness;
|
||||
|
@ -2003,6 +2037,7 @@ FRAGMENT_SHADER_CODE
|
|||
float filteredRoughness2 = min(1.0, roughness2 + kernelRoughness2);
|
||||
roughness = sqrt(filteredRoughness2);
|
||||
}
|
||||
#endif
|
||||
//apply energy conservation
|
||||
|
||||
vec3 specular_light = vec3(0.0, 0.0, 0.0);
|
||||
|
|
|
@ -5,6 +5,12 @@
|
|||
|
||||
#include "cluster_data_inc.glsl"
|
||||
|
||||
#if !defined(MODE_RENDER_DEPTH) || defined(MODE_RENDER_MATERIAL) || defined(MODE_RENDER_SDF) || defined(MODE_RENDER_NORMAL_ROUGHNESS) || defined(MODE_RENDER_GIPROBE) || defined(TANGENT_USED) || defined(NORMALMAP_USED)
|
||||
#ifndef NORMAL_USED
|
||||
#define NORMAL_USED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
layout(push_constant, binding = 0, std430) uniform DrawCall {
|
||||
uint instance_index;
|
||||
uint pad; //16 bits minimum size
|
||||
|
|
17
thirdparty/meshoptimizer/simplifier.cpp
vendored
17
thirdparty/meshoptimizer/simplifier.cpp
vendored
|
@ -6,6 +6,7 @@
|
|||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef TRACE
|
||||
#define TRACE 0
|
||||
#endif
|
||||
|
@ -332,8 +333,11 @@ struct Vector3
|
|||
{
|
||||
float x, y, z;
|
||||
};
|
||||
// -- GODOT start --
|
||||
//static void rescalePositions(Vector3* result, const float* vertex_positions_data, size_t vertex_count, size_t vertex_positions_stride)
|
||||
static float rescalePositions(Vector3* result, const float* vertex_positions_data, size_t vertex_count, size_t vertex_positions_stride)
|
||||
// -- GODOT end --
|
||||
|
||||
static void rescalePositions(Vector3* result, const float* vertex_positions_data, size_t vertex_count, size_t vertex_positions_stride)
|
||||
{
|
||||
size_t vertex_stride_float = vertex_positions_stride / sizeof(float);
|
||||
|
||||
|
@ -371,6 +375,10 @@ static void rescalePositions(Vector3* result, const float* vertex_positions_data
|
|||
result[i].y = (result[i].y - minv[1]) * scale;
|
||||
result[i].z = (result[i].z - minv[2]) * scale;
|
||||
}
|
||||
// -- GODOT start --
|
||||
return extent;
|
||||
// -- GODOT end --
|
||||
|
||||
}
|
||||
|
||||
struct Quadric
|
||||
|
@ -1190,7 +1198,10 @@ size_t meshopt_simplify(unsigned int *destination, const unsigned int *indices,
|
|||
#endif
|
||||
|
||||
Vector3* vertex_positions = allocator.allocate<Vector3>(vertex_count);
|
||||
rescalePositions(vertex_positions, vertex_positions_data, vertex_count, vertex_positions_stride);
|
||||
// -- GODOT start --
|
||||
//rescalePositions(vertex_positions, vertex_positions_data, vertex_count, vertex_positions_stride);
|
||||
float extent = rescalePositions(vertex_positions, vertex_positions_data, vertex_count, vertex_positions_stride);
|
||||
// -- GODOT end --
|
||||
|
||||
Quadric* vertex_quadrics = allocator.allocate<Quadric>(vertex_count);
|
||||
memset(vertex_quadrics, 0, vertex_count * sizeof(Quadric));
|
||||
|
@ -1294,7 +1305,7 @@ size_t meshopt_simplify(unsigned int *destination, const unsigned int *indices,
|
|||
|
||||
// -- GODOT start --
|
||||
if (r_resulting_error) {
|
||||
*r_resulting_error = sqrt(worst_error);
|
||||
*r_resulting_error = sqrt(worst_error) * extent;
|
||||
}
|
||||
// -- GODOT end --
|
||||
|
||||
|
|
Loading…
Reference in a new issue