Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove flat modifier, while maintaining TreeIndex precision #2536

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

NodeAppearance determineNodeAppearance(sampler2D nodeAppearanceTexture, vec2 textureSize, highp float treeIndex) {

float dataTextureWidth = textureSize.x;
float dataTextureHeight = textureSize.y;
highp int dataTextureWidth = int(textureSize.x);
highp int dataTextureHeight = int(textureSize.y);

int xTreeIndexTextureCoord = int(mod(treeIndex, dataTextureWidth));
int yTreeIndexTextureCoord = int(floor(treeIndex / dataTextureWidth));
highp int iTreeIndex = int(treeIndex);
highp int xTreeIndexTextureCoord = iTreeIndex % dataTextureWidth;
highp int yTreeIndexTextureCoord = iTreeIndex / dataTextureWidth;

vec4 texel = texelFetch(nodeAppearanceTexture, ivec2(xTreeIndexTextureCoord, yTreeIndexTextureCoord), 0);
float alphaUnwrapped = floor((texel.a * 255.0) + 0.5);
Expand Down
11 changes: 7 additions & 4 deletions viewer/packages/rendering/src/glsl/sector/instancedMesh.frag
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ precision highp float;
#pragma glslify: import('../base/determineVisibility.glsl');
#pragma glslify: import('../base/determineColor.glsl');
#pragma glslify: import('../base/isClipped.glsl')
#pragma glslify: import('../treeIndex/treeIndexPacking.glsl')

uniform sampler2D colorDataTexture;
uniform sampler2D matCapTexture;
uniform vec2 treeIndexTextureSize;
uniform int renderMode;

flat in float v_treeIndex;
in vec3 v_color;
in vec3 v_viewPosition;
in TreeIndexPacked v_treeIndexPacked;

void main() {
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
void main()
{
highp float treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
}
Expand All @@ -29,5 +32,5 @@ void main() {

vec4 color = determineColor(v_color, appearance);
vec3 normal = derivateNormal(v_viewPosition);
updateFragmentColor(renderMode, color, v_treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.InstancedMesh);
updateFragmentColor(renderMode, color, treeIndex, normal, gl_FragCoord.z, matCapTexture, GeometryType.InstancedMesh);
}
10 changes: 6 additions & 4 deletions viewer/packages/rendering/src/glsl/sector/instancedMesh.vert
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma glslify: import('../base/determineMatrixOverride.glsl')
#pragma glslify: import('../treeIndex/treeIndexPacking.glsl')

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
Expand All @@ -13,12 +14,14 @@ in mat4 a_instanceMatrix;
in float a_treeIndex;
in vec3 a_color;

flat out float v_treeIndex;
out vec3 v_color;
out vec3 v_viewPosition;

void main()
{
out TreeIndexPacked v_treeIndexPacked;

void main() {
v_treeIndexPacked = packTreeIndex(a_treeIndex);

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
Expand All @@ -32,6 +35,5 @@ void main()
vec3 transformed = (a_instanceMatrix * vec4(position, 1.0)).xyz;
vec4 modelViewPosition = viewMatrix * treeIndexWorldTransform * modelMatrix * vec4(transformed, 1.0);
v_viewPosition = modelViewPosition.xyz;
v_treeIndex = a_treeIndex;
gl_Position = projectionMatrix * modelViewPosition;
}
7 changes: 6 additions & 1 deletion viewer/packages/rendering/src/glsl/sector/mesh.frag
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ precision highp float;
#pragma glslify: import('../base/determineColor.glsl');
#pragma glslify: import('../base/determineVisibility.glsl');
#pragma glslify: import('../base/isClipped.glsl')
#pragma glslify: import('../treeIndex/treeIndexPacking.glsl')

uniform sampler2D colorDataTexture;
uniform sampler2D matCapTexture;
uniform vec2 treeIndexTextureSize;
uniform int renderMode;

flat in float v_treeIndex;

in vec3 v_color;
in vec3 v_viewPosition;

in TreeIndexPacked v_treeIndexPacked;

void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);

NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
6 changes: 4 additions & 2 deletions viewer/packages/rendering/src/glsl/sector/mesh.vert
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma glslify: import('../base/determineMatrixOverride.glsl')
#pragma glslify: import('../treeIndex/treeIndexPacking.glsl')

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
Expand All @@ -13,12 +14,13 @@ in vec3 color;
in float treeIndex;

out vec3 v_color;
flat out float v_treeIndex;
out vec3 v_viewPosition;
out TreeIndexPacked v_treeIndexPacked;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndexPacked = packTreeIndex(treeIndex);
v_color = color;
v_treeIndex = treeIndex;

mat4 treeIndexWorldTransform = determineMatrixOverride(
treeIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ precision highp float;
#pragma glslify: import('../../base/determineNodeAppearance.glsl');
#pragma glslify: import('../../base/determineVisibility.glsl');
#pragma glslify: import('../../base/determineColor.glsl');
#pragma glslify: import('../../base/isClipped.glsl')
#pragma glslify: import('../../base/isClipped.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');

uniform sampler2D colorDataTexture;
uniform sampler2D matCapTexture;
uniform vec2 treeIndexTextureSize;
uniform int renderMode;

flat in float v_treeIndex;
in vec2 v_xy;
in vec3 v_color;
in vec3 v_normal;
in vec3 vViewPosition;
in TreeIndexPacked v_treeIndexPacked;

void main() {
void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);
float dist = dot(v_xy, v_xy);
vec3 normal = normalize( v_normal );
if (dist > 0.25)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma glslify: import('../../base/determineMatrixOverride.glsl')
#pragma glslify: import('../../base/determineMatrixOverride.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');

uniform mat4 inverseModelMatrix;
uniform mat4 modelMatrix;
Expand All @@ -19,12 +20,13 @@ in vec3 a_normal;
out vec2 v_xy;
out vec3 v_color;
out vec3 v_normal;
flat out float v_treeIndex;
out vec3 vViewPosition;

out TreeIndexPacked v_treeIndexPacked;

void main() {
v_treeIndexPacked = packTreeIndex(a_treeIndex);
v_xy = vec2(position.x, position.y);
v_treeIndex = a_treeIndex;

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ precision highp float;
#pragma glslify: import('../../base/determineNodeAppearance.glsl');
#pragma glslify: import('../../base/determineVisibility.glsl');
#pragma glslify: import('../../base/determineColor.glsl');
#pragma glslify: import('../../base/isClipped.glsl')
#pragma glslify: import('../../base/isClipped.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');
#pragma glslify: import('../../math/constants.glsl')

uniform sampler2D colorDataTexture;
Expand All @@ -24,11 +25,13 @@ in float v_angle;
in float v_arcAngle;
in vec4 v_centerA;
in vec4 v_V;
flat in float v_treeIndex;
in vec3 v_color;
in vec3 v_normal;
in TreeIndexPacked v_treeIndexPacked;

void main() {
void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma glslify: import('../../math/mul3.glsl')
#pragma glslify: import('../../base/determineMatrixOverride.glsl')
#pragma glslify: import('../../base/determineMatrixOverride.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');

uniform mat4 inverseModelMatrix;
uniform mat4 modelMatrix;
Expand All @@ -25,7 +26,6 @@ in vec3 a_localXAxis;
in float a_angle;
in float a_arcAngle;

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 @@ -40,7 +40,10 @@ out float v_arcAngle;
out vec3 v_color;
out vec3 v_normal;

out TreeIndexPacked v_treeIndexPacked;

void main() {
v_treeIndexPacked = packTreeIndex(a_treeIndex);
mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
Expand Down Expand Up @@ -83,7 +86,6 @@ void main() {
surfacePoint = mul3(modelViewMatrix, surfacePoint);

// out data
v_treeIndex = a_treeIndex;
v_angle = a_angle;
v_arcAngle = a_arcAngle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ precision highp float;
#pragma glslify: import('../../base/determineNodeAppearance.glsl');
#pragma glslify: import('../../base/determineVisibility.glsl');
#pragma glslify: import('../../base/determineColor.glsl');
#pragma glslify: import('../../base/isClipped.glsl')
#pragma glslify: import('../../base/isClipped.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');
#pragma glslify: import('../../math/constants.glsl')

uniform sampler2D colorDataTexture;
Expand All @@ -23,11 +24,13 @@ in vec4 axis;
in vec4 v_centerA;
in vec4 v_centerB;
in float height;
flat in float v_treeIndex;
in vec3 v_color;
in vec3 v_normal;
in TreeIndexPacked v_treeIndexPacked;

void main() {
void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma glslify: import('../../math/mul3.glsl')
#pragma glslify: import('../../base/determineMatrixOverride.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');

uniform mat4 inverseModelMatrix;
uniform mat4 modelMatrix;
Expand All @@ -22,7 +23,6 @@ in float a_radiusB;
in vec3 a_normal;
in vec3 a_color;

flat out float v_treeIndex;
// We pack the radii into w-components
out vec4 v_centerA;
out vec4 v_centerB;
Expand All @@ -36,7 +36,10 @@ out float height;
out vec3 v_color;
out vec3 v_normal;

out TreeIndexPacked v_treeIndexPacked;

void main() {
v_treeIndexPacked = packTreeIndex(a_treeIndex);

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
Expand Down Expand Up @@ -116,7 +119,6 @@ void main() {
V.w = surfacePoint.y;
axis.w = surfacePoint.z;

v_treeIndex = a_treeIndex;
v_color = a_color;
v_normal = normalMatrix * normal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ precision highp float;
#pragma glslify: import('../../base/determineNodeAppearance.glsl');
#pragma glslify: import('../../base/determineVisibility.glsl');
#pragma glslify: import('../../base/determineColor.glsl');
#pragma glslify: import('../../base/isClipped.glsl')
#pragma glslify: import('../../base/isClipped.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');

uniform sampler2D colorDataTexture;
uniform sampler2D matCapTexture;
Expand All @@ -22,11 +23,13 @@ in float height;
in vec4 U;
in vec4 V;
in vec4 sphereNormal;
flat in float v_treeIndex;
in vec3 v_color;
in vec3 v_normal;
in TreeIndexPacked v_treeIndexPacked;

void main() {
void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma glslify: import('../../math/mul3.glsl')
#pragma glslify: import('../../base/determineMatrixOverride.glsl')
#pragma glslify: import('../../base/determineMatrixOverride.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');

uniform mat4 inverseModelMatrix;
uniform mat4 inverseNormalMatrix;
Expand All @@ -22,7 +23,6 @@ in float a_horizontalRadius;
in float a_verticalRadius;
in float a_height;

flat out float v_treeIndex;
// We pack vRadius as w-component of center
out vec4 center;
out float hRadius;
Expand All @@ -36,7 +36,10 @@ out vec4 sphereNormal;
out vec3 v_color;
out vec3 v_normal;

out TreeIndexPacked v_treeIndexPacked;

void main() {
v_treeIndexPacked = packTreeIndex(a_treeIndex);

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
Expand Down Expand Up @@ -90,7 +93,6 @@ void main() {
vec3 surfacePoint = centerOfSegment + mat3(lDir, left, up) * displacement;
vec3 transformed = surfacePoint;

v_treeIndex = a_treeIndex;
surfacePoint = mul3(modelViewMatrix, surfacePoint);
center.xyz = mul3(modelViewMatrix, centerWithOffset);
center.w = a_verticalRadius; // Pack radius into w-component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ precision highp float;
#pragma glslify: import('../../base/determineNodeAppearance.glsl');
#pragma glslify: import('../../base/determineVisibility.glsl');
#pragma glslify: import('../../base/determineColor.glsl');
#pragma glslify: import('../../base/isClipped.glsl')
#pragma glslify: import('../../base/isClipped.glsl');
#pragma glslify: import('../../treeIndex/treeIndexPacking.glsl');
#pragma glslify: import('../../math/constants.glsl')

// TODO general cylinder and cone are very similar and used
Expand All @@ -29,11 +30,13 @@ in float v_arcAngle;
in float v_surfacePointY;
in vec4 v_planeA;
in vec4 v_planeB;
flat in float v_treeIndex;
in vec3 v_color;
in vec3 v_normal;
in TreeIndexPacked v_treeIndexPacked;

void main() {
void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Loading