From 8a43b222c7090a207c57116b4701e7ff9686a262 Mon Sep 17 00:00:00 2001 From: Omar El Sheikh Date: Mon, 8 Nov 2021 12:11:48 -0500 Subject: [PATCH] Fix Vertex Attribute Specification Octahedral For octahedral compressed normals/tangents, we use vec4 in the shader regardless of whether a normal/tangent does/doesn't exist For the case where we only have a normal vector, we need to specify that there are only two components being used when calling glVertexAttrib Before we would always specify that there were 4 components, and used offsets to determine where in the vertex buffer to read data from but this doesn't work on all platforms --- drivers/gles2/rasterizer_storage_gles2.cpp | 3 ++- drivers/gles3/rasterizer_storage_gles3.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 28c0a65690a..1a6efc83e20 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -2309,7 +2309,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: // UNLESS tangent exists and is also compressed // then it will be oct16 encoded along with tangent attribs[i].normalized = GL_TRUE; - attribs[i].size = 4; + attribs[i].size = 2; attribs[i].type = GL_SHORT; attributes_stride += 4; } else { @@ -2330,6 +2330,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: case VS::ARRAY_TANGENT: { if (p_format & VS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) { attribs[i].enabled = false; + attribs[VS::ARRAY_NORMAL].size = 4; if (p_format & VS::ARRAY_COMPRESS_TANGENT && p_format & VS::ARRAY_COMPRESS_NORMAL) { // normal and tangent will each be oct16 (2 bytes each) // pack into single vec4 for memory bandwidth diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index c063e488b7a..76ae9f9fbad 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -3404,7 +3404,7 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: // UNLESS tangent exists and is also compressed // then it will be oct16 encoded along with tangent attribs[i].normalized = GL_TRUE; - attribs[i].size = 4; + attribs[i].size = 2; attribs[i].type = GL_SHORT; attributes_stride += 4; } else { @@ -3425,6 +3425,7 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: case VS::ARRAY_TANGENT: { if (p_format & VS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) { attribs[i].enabled = false; + attribs[VS::ARRAY_NORMAL].size = 4; if (p_format & VS::ARRAY_COMPRESS_TANGENT && p_format & VS::ARRAY_COMPRESS_NORMAL) { // normal and tangent will each be oct16 (2 bytes each) // pack into single vec4 for memory bandwidth