Aedif / TokenVariants

GNU General Public License v3.0
17 stars 12 forks source link

Bug(?) with Shape Size vs WebGL Max Texture Size #119

Closed Dumbhuman closed 11 months ago

Dumbhuman commented 11 months ago

This could likely be just user error on my part, so apologies if this bug report is a waste of time. It's also pretty rare I'll ever actually need shapes this large and I'd guess I'm stretching things far beyond the intended scope, but the specific numbers made me curious as to whether there was a bug involved.

I had the idea of setting up some ranges for weapons with a green line for the normal range and yellow for the max. Worked well on a 100 grid scene for a thrown dagger (20'/60'): image

When I got up to bow ranges, I ran into a rendering problem: image

After some testing it seems the maximum shape radius I can render is 4095 pixels (the token below is 100 pixels so 4045 + 50): image

When the radius is 4096 (which fails to render for me), that's a 8,192 diameter which also happens to be exactly half of my browser's supposed max texture size of 16,384: image

I imagine the width of the border could be pushing the actual image just above 8,192 pixels, but I'm not sure why that wouldn't render for me unless the overall dimensions are being doubled somewhere under the hood. Here you can see the shape render error happening on top of a single tile that's a 12000 x 12000 pixel image: image

It's been a long time since I ran a battle where the maximum distance of a Shortbow or Longbow mattered, so I'd guess this is literally an edge case (and probably not the most efficient way to do range-finding regardless).

Aedif commented 11 months ago

It's not a bug per se. You see shapes and text are rendered at twice the resolution to keep them looking sharp. Didn't matter in the contexts I was using these types of overlays but I guess it was relevant here.

I might add an option to let you specify the resolution when rendering shapes but that would merely be kicking the can down the road. Eventually you'd still run texture size limits.

That said... I think there might be a way to to get around this texture size limit entirely... by not rendering a texture for these primitive shapes to begin with... I'll think about this.

Dumbhuman commented 11 months ago

I kind of expected that black box was a reminder of how far "out of the box" my use case was, especially when I saw the numbers involved. I'm glad it's not unexpected behavior for the module though (even if it's unexpected user behavior).

It definitely makes sense to increase the resolution, especially on text, for the intended scope. Since Foundry can zoom up to (I think) 300% by default, I'm sure the extra detail is appreciated there, especially for text.

I wouldn't worry too much about solutions for this specific use unless you think they're likely to also improve performance in other areas.

Aedif commented 11 months ago

Not rendering these primitive shapes (rectangle, ellipse, torus) into textures is significantly more efficient.

It ended up beeing a bit more difficulet than I antiticipated but I have arrived at a working solution. Will need to do more testing, but I'm confident this texture size limitation can be avoided.

https://github.com/Aedif/TokenVariants/assets/7693704/8d13ba2b-78df-44ea-939f-8f11ad523aff

Dumbhuman commented 11 months ago

This also sounds like very good news. I'm sure if it's got a breaking point, I'll stumble upon it with some other silly idea of mine.

Aedif commented 11 months ago

Shape size should as of 4.47.0 for all practical purposes be unlimited.