Skip to content

Commit

Permalink
Mark v_treeIndex with flat
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Strepto committed Aug 30, 2022
1 parent 306cb77 commit 6053321
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions viewer/packages/rendering/src/glsl/sector/instancedMesh.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion viewer/packages/rendering/src/glsl/sector/mesh.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions viewer/packages/rendering/src/glsl/sector/mesh.vert
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ 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() {
v_color = color;
v_treeIndex = treeIndex;

mat4 treeIndexWorldTransform = determineMatrixOverride(
treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
transformOverrideTexture
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions viewer/packages/rendering/src/glsl/sector/primitives/circle.vert
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ 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() {
v_xy = vec2(position.x, position.y);
v_treeIndex = a_treeIndex;

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
transformOverrideTexture
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions viewer/packages/rendering/src/glsl/sector/primitives/cone.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -42,10 +42,10 @@ out vec3 v_normal;

void main() {
mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
transformOverrideTexture
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,10 +39,10 @@ out vec3 v_normal;
void main() {

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
transformOverrideTexture
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,10 +39,10 @@ out vec3 v_normal;
void main() {

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
transformOverrideTexture
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,10 +36,10 @@ void main() {
v_arcAngle = a_arcAngle;

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
a_treeIndex,
treeIndexTextureSize,
transformOverrideIndexTexture,
transformOverrideTextureSize,
transformOverrideTexture
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Loading

0 comments on commit 6053321

Please sign in to comment.