0
\$\begingroup\$

I'm currently attempting to copy a small texture onto a larger texture, but I want to have control over how large and at what UV position the smaller texture is copied over.

I've made some progress on this and can scale and offset the texture, but the issue is that the scaling is not from the center of the offset.

Does anyone have any ideas on how to do this?

---EDIT---

enter image description here

As you can see above, the capsule is at the center of the outlined box. When I scale the coordinates, you can see the red splotches representing where I'm standing scale towards the center/capsule. Now, to do this, the offset is set to (0.5, 0.5).

If I move the outlined box to the upper left corner, the offset no longer scales from the circle. It scales from the upper left corner with an offset of (0, 0). To get it to scale from the center, I need an offset of (0.125, 0.125) which is counter intuitive. I'm handling the offset and scaling manually, but I'd ideally like to automate the process and calculate it all based on position.

enter image description here

Here's the code I'm working with:

float2 newUV = i.uv - float2(_XMod, _YMod);
newUV = newUV.xy * float2(_ScaleX, _ScaleY) + float2(0.5f, 0.5f);
\$\endgroup\$
  • \$\begingroup\$ Can you show us what you're doing now, and how the result differs from what you want? \$\endgroup\$ – DMGregory Dec 23 '18 at 0:12
  • \$\begingroup\$ @DMGregory Just updated the OP with relevant information. \$\endgroup\$ – David King Dec 23 '18 at 2:32

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.