1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-14 13:41:12 +00:00

Align Vertex Buffer to 4 Bytes

With the octahedral compression, we had attributes of a size of 2 bytes
which potentially caused performance regressions on iOS/Mac

Now add padding to the normal/tangent buffer

For octahedral, normal will always be oct32 encoded
UNLESS tangent exists and is also compressed
then both will be oct16 encoded and packed into a vec4<GL_BYTE>
attribute
This commit is contained in:
Omar El Sheikh
2021-08-06 12:34:29 -04:00
parent 8db0bd4424
commit f0de7ec2b6
5 changed files with 59 additions and 56 deletions

View File

@@ -26,13 +26,11 @@ ARRAY_INDEX=8,
layout(location = 0) in highp vec4 vertex_attrib;
/* clang-format on */
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
layout(location = 1) in vec2 normal_attrib;
#else
layout(location = 1) in vec3 normal_attrib;
layout(location = 1) in vec4 normal_tangent_attrib;
#endif
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
layout(location = 2) in vec2 tangent_attrib;
// packed into normal_attrib zw component
#else
layout(location = 2) in vec4 tangent_attrib;
#endif
@@ -340,15 +338,15 @@ void main() {
#endif
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
vec3 normal = oct_to_vec3(normal_attrib);
vec3 normal = oct_to_vec3(normal_tangent_attrib.xy);
#else
vec3 normal = normal_attrib;
#endif
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
#ifdef ENABLE_OCTAHEDRAL_COMPRESSION
vec3 tangent = oct_to_vec3(vec2(tangent_attrib.x, abs(tangent_attrib.y) * 2.0 - 1.0));
float binormalf = sign(tangent_attrib.y);
vec3 tangent = oct_to_vec3(vec2(normal_tangent_attrib.z, abs(normal_tangent_attrib.w) * 2.0 - 1.0));
float binormalf = sign(normal_tangent_attrib.w);
#else
vec3 tangent = tangent_attrib.xyz;
float binormalf = tangent_attrib.a;