How do I render a viewport texture to an irregular Polygon2D?

Godot Version

v4.5.stable.official [876b29033]

Question

Minimum Reproduction Project: https://github.com/kit-solent/godot-thing

I want to use a SubViewport with a Camera2D child to record a part of my map and display it elsewhere on the map. This works when rendering the viewport texture to a regular sprite but I need it to display on an irregular polygon. Currently there most of the viewport texture gets smeared out to the edges of the polygon as the image below shows.


I’d love to better understand how positioning works when rendering a texture to a polygon like this. The docs havn’t been particularly helpful and I’m unsure as to what position system/transforms will allow me to work with a SubViewport. Thanks in advance for any help.

You can edit the Polygon2D’s UV coordinates, though a subviewport texture may not give you a preview to reference. Seems like the Polygon2D uses pixel UV coordinates, not the usual 3D 0.0 to 1.0 values.

By pixel UV coordinates do you mean that UV positions on the Polygon2D are measured in pixels from the top left of it’s bounding box? If the ViewportTexture worked in the same way then surely the pixels would just get coppied over linearly without the smearing. I’ve tried setting the Polygon2D’s uv property to match its points property but that didn’t fix it. Is this something that could be fixed with a custom shader?