0
\$\begingroup\$

I need help coming up with dynamic uv values (general formula) so that my texture looks continuous through all levels of my quadtree. level 0-1 works perfectly, level 1 subdivision looks great. but continuing to level 2 and onwards is where I realized my current method isn’t going to work. I need to come up with UV values unique to each quad at different levels.

here is a working example of my code: https://codepen.io/miguel007/pen/KKeMxQY?editors=0011

line 233 in the createLodChildQuads function is where I’m doing the UV modification.

Move the red player to activate Quadtree levels. Control the red player (W,A,S,E,R,F)

level 0

enter image description here

level 1

enter image description here

level 2

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ It looks to me like you're using the default texture coordinates (0, 0)-(1, 1) for every plane geometry you create. You'll need to modify your code to give distinct texture coordinates to each child quad, or modify your shader to use world space position rather than texture coordinate attributes as the sample point to use for looking up into your texture. \$\endgroup\$ Commented Nov 3, 2022 at 15:01
  • \$\begingroup\$ Want to edit your question to show and describe the problem you're grappling with now? That gives it better visibility than sitting in a comment. \$\endgroup\$ Commented Nov 4, 2022 at 18:54
  • \$\begingroup\$ @DMGregory see the updated edit. \$\endgroup\$ Commented Nov 4, 2022 at 20:00

1 Answer 1

0
\$\begingroup\$

so I figured out the answer to this problem 4 days ago.

pseudo code

//this allows for the correct scaling of each mesh uv for any level. var scaling = currentMeshDimensions/rootMeshDimensions var u_ = u * scaling var v_ = v * scaling // function to normalize input 0-1 function norm(val, max, min) { return (val - min) / (max - min); } var wp = currentMesh.getWorldPosition() var xn = norm(wp.x,rootMeshDimensions/2,-rootMeshDimensions/2) var yn = norm(wp.y,rootMeshDimensions/2,-rootMeshDimensions/2) var n = scaling/2 u = u_ + (xn-n) v = v_ + (yn-n) ``` 
\$\endgroup\$
1
  • 1
    \$\begingroup\$ This answer would be even better if you briefly explained how this code solves your problem, so a future reader can learn from your strategy, even if their code isn't identical. \$\endgroup\$ Commented Nov 15, 2022 at 3:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.