Advertisement

Padding UVs using vertex shader

Started by February 27, 2018 02:19 AM
2 comments, last by MJP 6 years, 11 months ago

I was wondering if it's possible to pad UVs by slightly scaling each triangles uniformly. 

This is on a lower end mobile so I have no access to geometry shaders.

My idea was just to compute the centre of the triangle and store that in a UV or tangent data.

In the vertex shader I would just do 

normalise(vertexPos - triangleCentre) * _ScaleFactor.

 

Then I would blend this "under" the original UV map. This way the bits poking out would only appear on the outer edges.

Has anyone done this? I feel at a cost of precomputing triangle centres it could be faster than a pixel dilation.

Is there a reason you can't pre-scale the UVs in your asset pipeline, instead of doing this on the fly?

On low-end hardware its generally advisable to bake a much as possible ahead of time.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Advertisement

You can't scale a "triangle" in a vertex shader if you have shared vertices with an index buffer. The vertex shader will only run once per-vertex, so if a vertex is scaled according to one triangle it will be incorrect for any other triangles that share the same vertex. You can split all of your vertices, but you can end up with a lot of extra vertices depending on your scenes.

This topic is closed to new replies.

Advertisement