Browse Source

Shaders: ANGLE, for fucks sake!

pull/518/head
Vladimír Vondruš 5 years ago
parent
commit
fd3bd7e737
  1. 20
      src/Magnum/Shaders/Flat.vert
  2. 3
      src/Magnum/Shaders/MeshVisualizer.frag
  3. 3
      src/Magnum/Shaders/MeshVisualizer.geom
  4. 11
      src/Magnum/Shaders/MeshVisualizer.vert
  5. 3
      src/Magnum/Shaders/Phong.frag
  6. 17
      src/Magnum/Shaders/Phong.vert
  7. 20
      src/Magnum/Shaders/Vector.vert
  8. 20
      src/Magnum/Shaders/VertexColor.vert

20
src/Magnum/Shaders/Flat.vert

@ -112,7 +112,9 @@ layout(std140
) uniform TransformationProjection { ) uniform TransformationProjection {
highp highp
#ifdef TWO_DIMENSIONS #ifdef TWO_DIMENSIONS
mat3 /* Can't be a mat3 because of ANGLE, see DrawUniform in Phong.vert for
details */
mat3x4
#elif defined(THREE_DIMENSIONS) #elif defined(THREE_DIMENSIONS)
mat4 mat4
#else #else
@ -237,15 +239,13 @@ void main() {
#define drawId drawOffset #define drawId drawOffset
#endif #endif
highp const #ifdef TWO_DIMENSIONS
#ifdef TWO_DIMENSIONS highp const mat3 transformationProjectionMatrix = mat3(transformationProjectionMatrices[drawId]);
mat3 #elif defined(THREE_DIMENSIONS)
#elif defined(THREE_DIMENSIONS) highp const mat4 transformationProjectionMatrix = transformationProjectionMatrices[drawId];
mat4 #else
#else #error
#error #endif
#endif
transformationProjectionMatrix = transformationProjectionMatrices[drawId];
#ifdef TEXTURE_TRANSFORMATION #ifdef TEXTURE_TRANSFORMATION
mediump const mat3 textureMatrix = mat3(textureTransformations[drawId].rotationScaling.xy, 0.0, textureTransformations[drawId].rotationScaling.zw, 0.0, textureTransformations[drawId].textureTransformation_offset, 1.0); mediump const mat3 textureMatrix = mat3(textureTransformations[drawId].rotationScaling.xy, 0.0, textureTransformations[drawId].rotationScaling.zw, 0.0, textureTransformations[drawId].textureTransformation_offset, 1.0);
#ifdef TEXTURE_ARRAYS #ifdef TEXTURE_ARRAYS

3
src/Magnum/Shaders/MeshVisualizer.frag

@ -131,7 +131,8 @@ uniform highp uint drawOffset
always before any code. */ always before any code. */
struct DrawUniform { struct DrawUniform {
#ifdef THREE_DIMENSIONS #ifdef THREE_DIMENSIONS
highp mat3 normalMatrix; /* actually mat3x4 */ /* Can't be a mat3 because of ANGLE, see Phong.vert for details */
highp mat3x4 normalMatrix;
#elif !defined(TWO_DIMENSIONS) #elif !defined(TWO_DIMENSIONS)
#error #error
#endif #endif

3
src/Magnum/Shaders/MeshVisualizer.geom

@ -103,7 +103,8 @@ uniform highp uint drawOffset
always before any code. */ always before any code. */
struct DrawUniform { struct DrawUniform {
#ifdef THREE_DIMENSIONS #ifdef THREE_DIMENSIONS
highp mat3 normalMatrix; /* actually mat3x4 */ /* Can't be a mat3 because of ANGLE, see Phong.vert for details */
highp mat3x4 normalMatrix;
#elif !defined(TWO_DIMENSIONS) #elif !defined(TWO_DIMENSIONS)
#error #error
#endif #endif

11
src/Magnum/Shaders/MeshVisualizer.vert

@ -132,7 +132,9 @@ layout(std140
, binding = 1 , binding = 1
#endif #endif
) uniform TransformationProjection { ) uniform TransformationProjection {
highp mat3 transformationProjectionMatrices[DRAW_COUNT]; /* Can't be a mat3 because of ANGLE, see DrawUniform in Phong.vert for
details */
highp mat3x4 transformationProjectionMatrices[DRAW_COUNT];
}; };
#elif defined(THREE_DIMENSIONS) #elif defined(THREE_DIMENSIONS)
layout(std140 layout(std140
@ -159,7 +161,8 @@ layout(std140
always before any code. */ always before any code. */
struct DrawUniform { struct DrawUniform {
#ifdef THREE_DIMENSIONS #ifdef THREE_DIMENSIONS
highp mat3 normalMatrix; /* actually mat3x4 */ /* Can't be a mat3 because of ANGLE, see Phong.vert for details */
highp mat3x4 normalMatrix;
#elif !defined(TWO_DIMENSIONS) #elif !defined(TWO_DIMENSIONS)
#error #error
#endif #endif
@ -322,14 +325,14 @@ void main() {
#endif #endif
#ifdef TWO_DIMENSIONS #ifdef TWO_DIMENSIONS
highp const mat3 transformationProjectionMatrix = transformationProjectionMatrices[drawId]; highp const mat3 transformationProjectionMatrix = mat3(transformationProjectionMatrices[drawId]);
#elif defined(THREE_DIMENSIONS) #elif defined(THREE_DIMENSIONS)
highp const mat4 transformationMatrix = transformationMatrices[drawId]; highp const mat4 transformationMatrix = transformationMatrices[drawId];
#else #else
#error #error
#endif #endif
#if defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(BITANGENT_FROM_TANGENT_DIRECTION) || defined(NORMAL_DIRECTION) #if defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(BITANGENT_FROM_TANGENT_DIRECTION) || defined(NORMAL_DIRECTION)
mediump const mat3 normalMatrix = draws[drawId].normalMatrix; mediump const mat3 normalMatrix = mat3(draws[drawId].normalMatrix);
#endif #endif
mediump const uint materialId = draws[drawId].draw_materialIdReserved & 0xffffu; mediump const uint materialId = draws[drawId].draw_materialIdReserved & 0xffffu;
lowp float colorMapOffset = materials[materialId].material_colorMapOffset; lowp float colorMapOffset = materials[materialId].material_colorMapOffset;

3
src/Magnum/Shaders/Phong.frag

@ -167,7 +167,8 @@ uniform highp uint drawOffset
/* Keep in sync with Phong.vert. Can't "outsource" to a common file because /* Keep in sync with Phong.vert. Can't "outsource" to a common file because
the #extension directive needs to be always before any code. */ the #extension directive needs to be always before any code. */
struct DrawUniform { struct DrawUniform {
mediump mat3 normalMatrix; /* actually mat3x4 */ /* Can't be a mat3 because of ANGLE, see Phong.vert for details */
mediump mat3x4 normalMatrix;
highp uvec4 materialIdReservedObjectIdLightOffsetLightCount; highp uvec4 materialIdReservedObjectIdLightOffsetLightCount;
#define draw_materialIdReserved materialIdReservedObjectIdLightOffsetLightCount.x #define draw_materialIdReserved materialIdReservedObjectIdLightOffsetLightCount.x
#define draw_objectId materialIdReservedObjectIdLightOffsetLightCount.y #define draw_objectId materialIdReservedObjectIdLightOffsetLightCount.y

17
src/Magnum/Shaders/Phong.vert

@ -130,7 +130,20 @@ uniform highp uint drawOffset
/* Keep in sync with Phong.frag. Can't "outsource" to a common file because /* Keep in sync with Phong.frag. Can't "outsource" to a common file because
the #extension directive needs to be always before any code. */ the #extension directive needs to be always before any code. */
struct DrawUniform { struct DrawUniform {
mediump mat3 normalMatrix; /* actually mat3x4 */ /* Of all drivers, I made the crucial mistake of expecting ANGLE to have
non-broken uniform packing. Of course everything including random phone
drivers worked, except ANGLE with a D3D backend, which blew up when
seeing `mat3` here. With all the coding guidelines, rules and automated
bullying from Clang Tidy in place over at Google, it seems the false
sense of security is so strong that they don't even bother testing what
they wrote. Or, how to code, the Google way:
1. Thoroughly document the packing rules and how the translation of
every GLSL type to the D3D equivalent is performed:
https://chromium.googlesource.com/angle/angle/+/refs/heads/main/src/libANGLE/renderer/d3d/d3d11/UniformBlockToStructuredBufferTranslation.md#std140-limitation
2. Forget to actually implement and test the damn thing.
*/
mediump mat3x4 normalMatrix;
highp uvec4 materialIdReservedObjectIdLightOffsetLightCount; highp uvec4 materialIdReservedObjectIdLightOffsetLightCount;
#define draw_materialIdReserved materialIdReservedObjectIdLightOffsetLightCount.x #define draw_materialIdReserved materialIdReservedObjectIdLightOffsetLightCount.x
#define draw_objectId materialIdReservedObjectIdLightOffsetLightCount.y #define draw_objectId materialIdReservedObjectIdLightOffsetLightCount.y
@ -336,7 +349,7 @@ void main() {
highp const mat4 transformationMatrix = transformationMatrices[drawId]; highp const mat4 transformationMatrix = transformationMatrices[drawId];
#if LIGHT_COUNT #if LIGHT_COUNT
mediump const mat3 normalMatrix = draws[drawId].normalMatrix; mediump const mat3 normalMatrix = mat3(draws[drawId].normalMatrix);
#endif #endif
#ifdef TEXTURE_TRANSFORMATION #ifdef TEXTURE_TRANSFORMATION
mediump const mat3 textureMatrix = mat3(textureTransformations[drawId].rotationScaling.xy, 0.0, textureTransformations[drawId].rotationScaling.zw, 0.0, textureTransformations[drawId].textureTransformation_offset, 1.0); mediump const mat3 textureMatrix = mat3(textureTransformations[drawId].rotationScaling.xy, 0.0, textureTransformations[drawId].rotationScaling.zw, 0.0, textureTransformations[drawId].textureTransformation_offset, 1.0);

20
src/Magnum/Shaders/Vector.vert

@ -96,7 +96,9 @@ layout(std140
) uniform TransformationProjection { ) uniform TransformationProjection {
highp highp
#ifdef TWO_DIMENSIONS #ifdef TWO_DIMENSIONS
mat3 /* Can't be a mat3 because of ANGLE, see DrawUniform in Phong.vert for
details */
mat3x4
#elif defined(THREE_DIMENSIONS) #elif defined(THREE_DIMENSIONS)
mat4 mat4
#else #else
@ -162,15 +164,13 @@ void main() {
#define drawId drawOffset #define drawId drawOffset
#endif #endif
highp const #ifdef TWO_DIMENSIONS
#ifdef TWO_DIMENSIONS highp const mat3 transformationProjectionMatrix = mat3(transformationProjectionMatrices[drawId]);
mat3 #elif defined(THREE_DIMENSIONS)
#elif defined(THREE_DIMENSIONS) highp const mat4 transformationProjectionMatrix = transformationProjectionMatrices[drawId];
mat4 #else
#else #error
#error #endif
#endif
transformationProjectionMatrix = transformationProjectionMatrices[drawId];
#ifdef TEXTURE_TRANSFORMATION #ifdef TEXTURE_TRANSFORMATION
mediump const mat3 textureMatrix = mat3(textureTransformations[drawId].rotationScaling.xy, 0.0, textureTransformations[drawId].rotationScaling.zw, 0.0, textureTransformations[drawId].textureTransformation_offset, 1.0); mediump const mat3 textureMatrix = mat3(textureTransformations[drawId].rotationScaling.xy, 0.0, textureTransformations[drawId].rotationScaling.zw, 0.0, textureTransformations[drawId].textureTransformation_offset, 1.0);
#endif #endif

20
src/Magnum/Shaders/VertexColor.vert

@ -85,7 +85,9 @@ layout(std140
) uniform TransformationProjection { ) uniform TransformationProjection {
highp highp
#ifdef TWO_DIMENSIONS #ifdef TWO_DIMENSIONS
mat3 /* Can't be a mat3 because of ANGLE, see DrawUniform in Phong.vert for
details */
mat3x4
#elif defined(THREE_DIMENSIONS) #elif defined(THREE_DIMENSIONS)
mat4 mat4
#else #else
@ -131,15 +133,13 @@ void main() {
#define drawId drawOffset #define drawId drawOffset
#endif #endif
highp const #ifdef TWO_DIMENSIONS
#ifdef TWO_DIMENSIONS highp const mat3 transformationProjectionMatrix = mat3(transformationProjectionMatrices[drawId]);
mat3 #elif defined(THREE_DIMENSIONS)
#elif defined(THREE_DIMENSIONS) highp const mat4 transformationProjectionMatrix = transformationProjectionMatrices[drawId];
mat4 #else
#else #error
#error #endif
#endif
transformationProjectionMatrix = transformationProjectionMatrices[drawId];
#endif #endif
#ifdef TWO_DIMENSIONS #ifdef TWO_DIMENSIONS

Loading…
Cancel
Save