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

LineTexBucket: fix out of short range (#220, #529) #532

Closed
wants to merge 5 commits into from

Conversation

Gustl22
Copy link

@Gustl22 Gustl22 commented Apr 26, 2018

As I mentioned in #220 the lineLength often was out of Short range.
So shapes weren't displayed correctly or reversed.

I added a distance value to shader, which now replaces the position calculations of texture. lineLength is further needed to avoid minor artifacts at vertices.

In rarely special cases the distance could have a value greater than the Shorts range as it's an euclidean distance out of two Short values. So I added a workaround to split line in those cases.

Works fine with #529, too.

@Gustl22
Copy link
Author

Gustl22 commented Apr 27, 2018

I rethought my implementation and found a solution which works without additional distance values.

// use linelength mod texture step (mod is always positiv)
vec4 c = texture2D(tex, vec2(mod(v_st.s, step), (v_st.t + 1.0) * 0.5));
float fuzz = fwidth(c.a);
gl_FragColor = (c * u_color) * smoothstep(0.5 - fuzz, 0.5 + fuzz, c.a);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick comment: please let's keep any formatting changes separately in own PR.
It's important to be able to review now and in the future any core changes easily.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the spaces I added?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, any improvements in format, refactor, names, comments can perfectly exist separately.
In the future (and now) when we come back to search for a commit's changes, it's very important to see the commit's changes for its specific purpose and only them, not searching in many diffs where exactly is the actual code that changed map rendering.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'm a bit lazy in such matters.

Copy link
Author

@Gustl22 Gustl22 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments I added were needed to understand what's going on. Next time I'll try to add the not affected ones separately.

I'll add formatting PR when this is merged.

Gustl22 added 2 commits April 27, 2018 09:43
# Conflicts:
#	vtm/resources/assets/shaders/linetex_layer_tex.glsl
@devemux86 devemux86 added the bug label Apr 30, 2018
@devemux86
Copy link
Collaborator

Don't like the result inside maps where the functionality is more important than overlays.
e.g. now the oneway textures "run" like crazy during zoom, while on master they progress very smoothly.

devemux86 pushed a commit that referenced this pull request Apr 30, 2018
@devemux86
Copy link
Collaborator

devemux86 commented Apr 30, 2018

I merged the PR in branch issue_532 rebased on master to avoid any conflicts.
Can continue working there.

float step = 2.0;
if (u_mode == 2.0) { // dashed texture
step = 1.0;
}
vec4 c = texture2D(tex, vec2(abs(mod(v_st.s + 1.0, step)), (v_st.t + 1.0) * 0.5));
// use linelength mod texture step (mod is always positiv)
vec4 c = texture2D(tex, vec2(mod(v_st.s, step), (v_st.t + 1.0) * 0.5));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the remove of the "+ 1.0" in mod?

Copy link
Author

@Gustl22 Gustl22 May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The better question is, why there was a "+ 1.0" ?
v_st.s is the interpolated lineLength value between two vertices, which is divided with u_pscale.
Theoretically v_st.s can have a range from -∞ to +∞. So it makes no sense to add 1 as it is taken modulo anyway and then has (dependent on dash flag) a range from 0 to 1 or 2.
The only reason could be that texture is shifted so it looks better at the beginning, but I didn't noticed any better look. If leaving + 1.0 we should comment that it has no further meaning.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the answer is found in #536. 🙂

@Gustl22
Copy link
Author

Gustl22 commented May 1, 2018

Don't like the result inside maps where the functionality is more important than overlays.
e.g. now the oneway textures "run" like crazy during zoom, while on master they progress very smoothly.

Valid objection: The reason is that we now start to count lineLength from Short.MIN_VALUE to use full range.
The good thing is, we can revert the first initialization to 0. When the Short max value is reached, lineLength is reset to min value anyway. But this does not affect one way textures inside base map as they never reach this value cause of clipping. I'll do a PR.

@devemux86
Copy link
Collaborator

I tried that before above comment and the result is a bit strange.
Some oneway symbols remain fixed, some move around them.

@devemux86
Copy link
Collaborator

BTW there is not anything about "objections" here, just that each and every change needs extensive testing in all library uses so that not break any existing functionality.

@Gustl22
Copy link
Author

Gustl22 commented May 1, 2018

I'm not a native speaker as you can see 😜
So maybe "objection" was the wrong expression for this.
My intent always is to improve this nice library without regression :D

@devemux86
Copy link
Collaborator

The PR concept is certainly nice and seems to solve the "reverse" issue and probably others.
Just wanted to remind (to all of us) that need in each case to make many tests. 🙂

So here since the map textures didn't seem to have issues (?) because of native tiling, we need to not affect them with that change that seems more relevant to overlays.
Like some adjustment is needed where the former code can still work for them?

@Gustl22
Copy link
Author

Gustl22 commented May 1, 2018

I tried that before above comment and the result is a bit strange.
Some oneway symbols remain fixed, some move around them.

This is the reason of + 1.0, to avoid static line symbols at the beginning, so it does start with a gap and not a symbol (like I mentioned before). Will revert this.

So here since the map textures didn't seem to have issues (?)

It could have, if lineLength in one tile is larger than Short value. E.g. a spiral. But it's very unlikely.

we need to not affect them with that change

It wouldn't be affected, if reverting + 1.0. It does then exactly the same than before (until it hits the critical Short limit). The former code is inherited. To differ these cases is a bit exaggerated in my opinion.

@Gustl22
Copy link
Author

Gustl22 commented May 1, 2018

See #536

@devemux86
Copy link
Collaborator

Very nice, with #536 the regression inside map textures seems fixed!

@devemux86 devemux86 added this to the 0.10.0 milestone May 1, 2018
devemux86 pushed a commit that referenced this pull request May 1, 2018
@devemux86
Copy link
Collaborator

Thanks, all seem working now!
Merged via 77cfad5.

@Gustl22
Copy link
Author

Gustl22 commented May 1, 2018

@devemux86: Thank you for reviewing and bring out the bugs!

@devemux86
Copy link
Collaborator

That's the magic of open source projects: users cooperation. 🙂
Thanks for the continuous improvements and fixes!

@Gustl22 Gustl22 deleted the issue_220 branch May 1, 2018 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants