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 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ uniform sampler2D matCapTexture;
uniform vec2 treeIndexTextureSize;
uniform int renderMode;

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

void main() {
in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
Strepto marked this conversation as resolved.
Show resolved Hide resolved
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
11 changes: 7 additions & 4 deletions viewer/packages/rendering/src/glsl/sector/instancedMesh.vert
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ 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 highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndexHundreds = floor(a_treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(a_treeIndex, 100.0));

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
Expand All @@ -32,6 +36,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;
}
6 changes: 5 additions & 1 deletion viewer/packages/rendering/src/glsl/sector/mesh.frag
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ uniform sampler2D matCapTexture;
uniform vec2 treeIndexTextureSize;
uniform int renderMode;

flat in float v_treeIndex;

in vec3 v_color;
in vec3 v_viewPosition;

in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);

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
Expand Up @@ -13,12 +13,14 @@ in vec3 color;
in float treeIndex;

out vec3 v_color;
flat out float v_treeIndex;
out vec3 v_viewPosition;
out highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndexHundreds = floor(treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(treeIndex, 100.0));
v_color = color;
v_treeIndex = treeIndex;

mat4 treeIndexWorldTransform = determineMatrixOverride(
treeIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ 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;

void main() {
in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);
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
Expand Up @@ -19,12 +19,15 @@ 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 highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndexHundreds = floor(a_treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(a_treeIndex, 100.0));
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 @@ -24,11 +24,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;

void main() {
in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 +39,12 @@ out float v_arcAngle;
out vec3 v_color;
out vec3 v_normal;

out highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndexHundreds = floor(a_treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(a_treeIndex, 100.0));
mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
treeIndexTextureSize,
Expand Down Expand Up @@ -83,7 +87,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 @@ -23,11 +23,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;

void main() {
in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 +35,12 @@ out float height;
out vec3 v_color;
out vec3 v_normal;

out highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndexHundreds = floor(a_treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(a_treeIndex, 100.0));

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
Expand Down Expand Up @@ -116,7 +120,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 @@ -22,11 +22,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;

void main() {
in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 +35,12 @@ out vec4 sphereNormal;
out vec3 v_color;
out vec3 v_normal;

out highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndexHundreds = floor(a_treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(a_treeIndex, 100.0));

mat4 treeIndexWorldTransform = determineMatrixOverride(
a_treeIndex,
Expand Down Expand Up @@ -90,7 +94,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 @@ -29,11 +29,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;

void main() {
in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 @@ -43,7 +42,12 @@ out float v_arcAngle;
out vec3 v_color;
out vec3 v_normal;

out highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndexHundreds = floor(a_treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(a_treeIndex, 100.0));

mat4 modelViewMatrix = viewMatrix * modelMatrix;

Expand Down Expand Up @@ -86,7 +90,6 @@ void main() {
surfacePoint = mul3(modelViewMatrix, surfacePoint);

// varying 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 @@ -17,12 +17,14 @@ in float v_oneMinusThicknessSqr;
in vec2 v_xy;
in float v_angle;
in float v_arcAngle;
flat in float v_treeIndex;
in vec3 v_color;
in vec3 v_normal;
in vec3 vViewPosition;

void main() {
in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ in float a_arcAngle;
in float a_thickness;
in vec3 a_normal;

flat out float v_treeIndex;
out float v_oneMinusThicknessSqr;
out vec2 v_xy;
out float v_angle;
Expand All @@ -28,8 +27,12 @@ out vec3 v_color;
out vec3 v_normal;
out vec3 vViewPosition;

out highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndex = a_treeIndex;
v_treeIndexHundreds = floor(a_treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(a_treeIndex, 100.0));
v_oneMinusThicknessSqr = (1.0 - a_thickness) * (1.0 - a_thickness);
v_xy = vec2(position.x, position.y);
v_angle = a_angle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,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;

void main() {
in highp float v_treeIndexHundreds;
in mediump float v_treeIndexSubHundreds;
void main()
{
highp float v_treeIndex = round(v_treeIndexHundreds) * 100.0 + round(v_treeIndexSubHundreds);
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);
if (!determineVisibility(appearance, renderMode)) {
discard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 @@ -32,8 +31,12 @@ out vec4 sphereNormal;
out vec3 v_color;
out vec3 v_normal;

out highp float v_treeIndexHundreds;
out mediump float v_treeIndexSubHundreds;

void main() {
v_treeIndex = a_treeIndex;
v_treeIndexHundreds = floor(a_treeIndex / 100.0);
v_treeIndexSubHundreds = round(mod(a_treeIndex, 100.0));
v_color = a_color;

mat4 modelViewMatrix = viewMatrix * modelMatrix;
Expand Down
Loading