From 6053321cab3764bb890ed87ba6d303cb690262f6 Mon Sep 17 00:00:00 2001 From: Nils Henrik Hals <3185998+Strepto@users.noreply.github.com> Date: Tue, 30 Aug 2022 10:40:55 +0200 Subject: [PATCH] Mark v_treeIndex with `flat` This uses `flat` to make the GPU not try to interpolate the value. Interpolation may on some GPUs cause "variance" of the same TreeIndex over a fragment. Even though the 1, 2, and 3 vertex Tree index is equal. --- .../rendering/src/glsl/sector/instancedMesh.frag | 2 +- .../rendering/src/glsl/sector/instancedMesh.vert | 10 +++++----- viewer/packages/rendering/src/glsl/sector/mesh.frag | 2 +- viewer/packages/rendering/src/glsl/sector/mesh.vert | 12 ++++++------ .../rendering/src/glsl/sector/primitives/circle.frag | 4 ++-- .../rendering/src/glsl/sector/primitives/circle.vert | 10 +++++----- .../rendering/src/glsl/sector/primitives/cone.frag | 2 +- .../rendering/src/glsl/sector/primitives/cone.vert | 10 +++++----- .../src/glsl/sector/primitives/eccentricCone.frag | 2 +- .../src/glsl/sector/primitives/eccentricCone.vert | 10 +++++----- .../src/glsl/sector/primitives/ellipsoidSegment.frag | 2 +- .../src/glsl/sector/primitives/ellipsoidSegment.vert | 10 +++++----- .../src/glsl/sector/primitives/generalCylinder.frag | 4 ++-- .../src/glsl/sector/primitives/generalCylinder.vert | 12 ++++++------ .../src/glsl/sector/primitives/generalring.frag | 2 +- .../src/glsl/sector/primitives/generalring.vert | 10 +++++----- .../src/glsl/sector/primitives/sphericalSegment.frag | 4 ++-- .../src/glsl/sector/primitives/sphericalSegment.vert | 2 +- .../src/glsl/sector/primitives/torusSegment.frag | 4 ++-- .../src/glsl/sector/primitives/torusSegment.vert | 12 ++++++------ .../src/glsl/sector/primitives/trapezium.frag | 4 ++-- .../src/glsl/sector/primitives/trapezium.vert | 10 +++++----- .../packages/rendering/src/glsl/sector/simple.frag | 2 +- .../packages/rendering/src/glsl/sector/simple.vert | 12 ++++++------ 24 files changed, 77 insertions(+), 77 deletions(-) diff --git a/viewer/packages/rendering/src/glsl/sector/instancedMesh.frag b/viewer/packages/rendering/src/glsl/sector/instancedMesh.frag index a240f866c96..82d442ae866 100644 --- a/viewer/packages/rendering/src/glsl/sector/instancedMesh.frag +++ b/viewer/packages/rendering/src/glsl/sector/instancedMesh.frag @@ -13,7 +13,7 @@ uniform sampler2D matCapTexture; uniform vec2 treeIndexTextureSize; uniform int renderMode; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_viewPosition; diff --git a/viewer/packages/rendering/src/glsl/sector/instancedMesh.vert b/viewer/packages/rendering/src/glsl/sector/instancedMesh.vert index be0051102d5..6eb366b534e 100644 --- a/viewer/packages/rendering/src/glsl/sector/instancedMesh.vert +++ b/viewer/packages/rendering/src/glsl/sector/instancedMesh.vert @@ -13,17 +13,17 @@ in mat4 a_instanceMatrix; in float a_treeIndex; in vec3 a_color; -out float v_treeIndex; +flat out float v_treeIndex; out vec3 v_color; out vec3 v_viewPosition; void main() { mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); diff --git a/viewer/packages/rendering/src/glsl/sector/mesh.frag b/viewer/packages/rendering/src/glsl/sector/mesh.frag index 8be2b2d2cd0..21750f71b64 100644 --- a/viewer/packages/rendering/src/glsl/sector/mesh.frag +++ b/viewer/packages/rendering/src/glsl/sector/mesh.frag @@ -13,7 +13,7 @@ uniform sampler2D matCapTexture; uniform vec2 treeIndexTextureSize; uniform int renderMode; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_viewPosition; diff --git a/viewer/packages/rendering/src/glsl/sector/mesh.vert b/viewer/packages/rendering/src/glsl/sector/mesh.vert index c69974283ff..655cb968996 100644 --- a/viewer/packages/rendering/src/glsl/sector/mesh.vert +++ b/viewer/packages/rendering/src/glsl/sector/mesh.vert @@ -10,10 +10,10 @@ uniform sampler2D transformOverrideTexture; in vec3 position; in vec3 color; -in float treeIndex; +in float treeIndex; out vec3 v_color; -out float v_treeIndex; +flat out float v_treeIndex; out vec3 v_viewPosition; void main() { @@ -21,10 +21,10 @@ void main() { v_treeIndex = treeIndex; mat4 treeIndexWorldTransform = determineMatrixOverride( - treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/circle.frag b/viewer/packages/rendering/src/glsl/sector/primitives/circle.frag index 9a677e1a2f5..be4afb401ec 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/circle.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/circle.frag @@ -12,7 +12,7 @@ uniform sampler2D matCapTexture; uniform vec2 treeIndexTextureSize; uniform int renderMode; -in float v_treeIndex; +flat in float v_treeIndex; in vec2 v_xy; in vec3 v_color; in vec3 v_normal; @@ -23,7 +23,7 @@ void main() { vec3 normal = normalize( v_normal ); if (dist > 0.25) discard; - + NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex); if (!determineVisibility(appearance, renderMode)) { discard; diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/circle.vert b/viewer/packages/rendering/src/glsl/sector/primitives/circle.vert index 8a784c0ec3b..3a64c34320a 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/circle.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/circle.vert @@ -19,7 +19,7 @@ in vec3 a_normal; out vec2 v_xy; out vec3 v_color; out vec3 v_normal; -out float v_treeIndex; +flat out float v_treeIndex; out vec3 vViewPosition; void main() { @@ -27,10 +27,10 @@ void main() { v_treeIndex = a_treeIndex; mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/cone.frag b/viewer/packages/rendering/src/glsl/sector/primitives/cone.frag index 54fd6732bbc..612eca21d6f 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/cone.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/cone.frag @@ -24,7 +24,7 @@ in float v_angle; in float v_arcAngle; in vec4 v_centerA; in vec4 v_V; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/cone.vert b/viewer/packages/rendering/src/glsl/sector/primitives/cone.vert index 909d2e056c7..2a2a13a4c93 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/cone.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/cone.vert @@ -25,7 +25,7 @@ in vec3 a_localXAxis; in float a_angle; in float a_arcAngle; -out float v_treeIndex; +flat out float v_treeIndex; // We pack the radii into w-components out vec4 v_centerB; // U, V, axis represent the 3x3 cone basis. @@ -42,10 +42,10 @@ out vec3 v_normal; void main() { mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/eccentricCone.frag b/viewer/packages/rendering/src/glsl/sector/primitives/eccentricCone.frag index c4dbd47bd4d..be54d2bd54b 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/eccentricCone.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/eccentricCone.frag @@ -23,7 +23,7 @@ in vec4 axis; in vec4 v_centerA; in vec4 v_centerB; in float height; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/eccentricCone.vert b/viewer/packages/rendering/src/glsl/sector/primitives/eccentricCone.vert index b8fc01ee1d0..b7ff8e85094 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/eccentricCone.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/eccentricCone.vert @@ -22,7 +22,7 @@ in float a_radiusB; in vec3 a_normal; in vec3 a_color; -out float v_treeIndex; +flat out float v_treeIndex; // We pack the radii into w-components out vec4 v_centerA; out vec4 v_centerB; @@ -39,10 +39,10 @@ out vec3 v_normal; void main() { mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/ellipsoidSegment.frag b/viewer/packages/rendering/src/glsl/sector/primitives/ellipsoidSegment.frag index 12456bd4822..be59a6d0cce 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/ellipsoidSegment.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/ellipsoidSegment.frag @@ -22,7 +22,7 @@ in float height; in vec4 U; in vec4 V; in vec4 sphereNormal; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/ellipsoidSegment.vert b/viewer/packages/rendering/src/glsl/sector/primitives/ellipsoidSegment.vert index 82b2fdc85aa..395ea924313 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/ellipsoidSegment.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/ellipsoidSegment.vert @@ -22,7 +22,7 @@ in float a_horizontalRadius; in float a_verticalRadius; in float a_height; -out float v_treeIndex; +flat out float v_treeIndex; // We pack vRadius as w-component of center out vec4 center; out float hRadius; @@ -39,10 +39,10 @@ out vec3 v_normal; void main() { mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/generalCylinder.frag b/viewer/packages/rendering/src/glsl/sector/primitives/generalCylinder.frag index b8a5abede4a..ffa6ddd9a98 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/generalCylinder.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/generalCylinder.frag @@ -29,7 +29,7 @@ in float v_arcAngle; in float v_surfacePointY; in vec4 v_planeA; in vec4 v_planeB; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; @@ -39,7 +39,7 @@ void main() { discard; } - vec4 color = determineColor(v_color, appearance); + vec4 color = determineColor(v_color, appearance); vec3 normal = normalize( v_normal ); float R1 = v_centerB.w; diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/generalCylinder.vert b/viewer/packages/rendering/src/glsl/sector/primitives/generalCylinder.vert index 6aa92bbb1bc..692e0158e7c 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/generalCylinder.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/generalCylinder.vert @@ -27,7 +27,7 @@ in vec3 a_localXAxis; in float a_angle; in float a_arcAngle; -out float v_treeIndex; +flat out float v_treeIndex; // We pack the radii into w-components out vec4 v_centerB; // U, V, axis represent the 3x3 cone basis. @@ -48,13 +48,13 @@ void main() { mat4 modelViewMatrix = viewMatrix * modelMatrix; mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); - + mat4 modelTransformOffset = inverseModelMatrix * treeIndexWorldTransform * modelMatrix; vec3 centerA = mul3(modelTransformOffset, a_centerA); diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/generalring.frag b/viewer/packages/rendering/src/glsl/sector/primitives/generalring.frag index 8e6f263502d..07f77f5cc36 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/generalring.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/generalring.frag @@ -17,7 +17,7 @@ in float v_oneMinusThicknessSqr; in vec2 v_xy; in float v_angle; in float v_arcAngle; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; in vec3 vViewPosition; diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/generalring.vert b/viewer/packages/rendering/src/glsl/sector/primitives/generalring.vert index 3fedd6419c7..5b126768360 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/generalring.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/generalring.vert @@ -19,7 +19,7 @@ in float a_arcAngle; in float a_thickness; in vec3 a_normal; -out float v_treeIndex; +flat out float v_treeIndex; out float v_oneMinusThicknessSqr; out vec2 v_xy; out float v_angle; @@ -36,10 +36,10 @@ void main() { v_arcAngle = a_arcAngle; mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/sphericalSegment.frag b/viewer/packages/rendering/src/glsl/sector/primitives/sphericalSegment.frag index e7b165f6ef2..f03220795af 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/sphericalSegment.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/sphericalSegment.frag @@ -22,7 +22,7 @@ in float height; in vec4 U; in vec4 V; in vec4 sphereNormal; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; @@ -32,7 +32,7 @@ void main() { discard; } - vec4 color = determineColor(v_color, appearance); + vec4 color = determineColor(v_color, appearance); vec3 normal = normalize(sphereNormal.xyz); float vRadius = center.w; diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/sphericalSegment.vert b/viewer/packages/rendering/src/glsl/sector/primitives/sphericalSegment.vert index 4f0cb0c7653..6c48c42f8a7 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/sphericalSegment.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/sphericalSegment.vert @@ -17,7 +17,7 @@ in float a_horizontalRadius; in float a_verticalRadius; in float a_height; -out float v_treeIndex; +flat out float v_treeIndex; // We pack vRadius as w-component of center out vec4 center; out float hRadius; diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/torusSegment.frag b/viewer/packages/rendering/src/glsl/sector/primitives/torusSegment.frag index 3f9ee06229b..81133c39e96 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/torusSegment.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/torusSegment.frag @@ -12,7 +12,7 @@ uniform sampler2D matCapTexture; uniform vec2 treeIndexTextureSize; uniform int renderMode; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; in vec3 vViewPosition; @@ -26,7 +26,7 @@ void main() { discard; } - vec4 color = determineColor(v_color, appearance); + vec4 color = determineColor(v_color, appearance); vec3 normal = normalize(v_normal); updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive); } diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/torusSegment.vert b/viewer/packages/rendering/src/glsl/sector/primitives/torusSegment.vert index 3f6782a6238..ccde5fa310a 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/torusSegment.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/torusSegment.vert @@ -18,7 +18,7 @@ in float a_arcAngle; in float a_radius; in float a_tubeRadius; -out float v_treeIndex; +flat out float v_treeIndex; out vec3 v_color; out vec3 v_normal; out vec3 vViewPosition; @@ -36,13 +36,13 @@ void main() { pos3.z = a_tubeRadius * sin(phi); mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); - + vec3 transformed = (a_instanceMatrix * vec4(pos3, 1.0)).xyz; // Calculate normal vectors if we're not picking diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/trapezium.frag b/viewer/packages/rendering/src/glsl/sector/primitives/trapezium.frag index 3f9ee06229b..81133c39e96 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/trapezium.frag +++ b/viewer/packages/rendering/src/glsl/sector/primitives/trapezium.frag @@ -12,7 +12,7 @@ uniform sampler2D matCapTexture; uniform vec2 treeIndexTextureSize; uniform int renderMode; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; in vec3 vViewPosition; @@ -26,7 +26,7 @@ void main() { discard; } - vec4 color = determineColor(v_color, appearance); + vec4 color = determineColor(v_color, appearance); vec3 normal = normalize(v_normal); updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.Primitive); } diff --git a/viewer/packages/rendering/src/glsl/sector/primitives/trapezium.vert b/viewer/packages/rendering/src/glsl/sector/primitives/trapezium.vert index 4a03a9385af..484a17d0e35 100644 --- a/viewer/packages/rendering/src/glsl/sector/primitives/trapezium.vert +++ b/viewer/packages/rendering/src/glsl/sector/primitives/trapezium.vert @@ -18,7 +18,7 @@ in vec3 a_vertex2; in vec3 a_vertex3; in vec3 a_vertex4; -out float v_treeIndex; +flat out float v_treeIndex; out vec3 v_color; out vec3 v_normal; out vec3 vViewPosition; @@ -33,10 +33,10 @@ void main() { } mat4 treeIndexWorldTransform = determineMatrixOverride( - a_treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + a_treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture ); diff --git a/viewer/packages/rendering/src/glsl/sector/simple.frag b/viewer/packages/rendering/src/glsl/sector/simple.frag index a1fdf46dd2e..6c8cbc89dc9 100644 --- a/viewer/packages/rendering/src/glsl/sector/simple.frag +++ b/viewer/packages/rendering/src/glsl/sector/simple.frag @@ -12,7 +12,7 @@ uniform sampler2D matCapTexture; uniform vec2 treeIndexTextureSize; uniform int renderMode; -in float v_treeIndex; +flat in float v_treeIndex; in vec3 v_color; in vec3 v_normal; in vec3 vViewPosition; diff --git a/viewer/packages/rendering/src/glsl/sector/simple.vert b/viewer/packages/rendering/src/glsl/sector/simple.vert index 6c2e7c76913..cfbf355fad2 100644 --- a/viewer/packages/rendering/src/glsl/sector/simple.vert +++ b/viewer/packages/rendering/src/glsl/sector/simple.vert @@ -19,18 +19,18 @@ in vec4 matrix1; in vec4 matrix2; in vec4 matrix3; -out float v_treeIndex; +flat out float v_treeIndex; out vec3 v_color; out vec3 v_normal; out vec3 vViewPosition; void main() { - + mat4 treeIndexWorldTransform = determineMatrixOverride( - treeIndex, - treeIndexTextureSize, - transformOverrideIndexTexture, - transformOverrideTextureSize, + treeIndex, + treeIndexTextureSize, + transformOverrideIndexTexture, + transformOverrideTextureSize, transformOverrideTexture );