1

I am trying to mask a sprite by using shader graph.

Here is a picture of what I have so far:

enter image description here

my problem is that when I feed the mask texture into the shader it centers itself on the main texture, as you see in this image.

See the slightly transparent checkerboard to the right side of the character? I only want this operation to affect the parts where the checkerboard intercepts with the character.

For this I would need someway to displace and scale(?) the mask texture so that it detaches from the center of the main texture.

What nodes do I have to add to accomplish this, and where to connect them? Thanks.

flask
  • 127
  • 13
  • 1
    I have tried to help and read the question multiple times, but I still do not understand where the problem is. Can you paraphrase the issue or expand on the problem you are having? Maybe make Current and Expected images with a quick paint sketch? – Tomasz Juszczak Nov 16 '20 at 14:31
  • Thank you very much for the reply, I think your answer just about covers what I was looking for, thank you! There is one part I am not quite sure how to go about, the position and the scaling( because the maskTex can have different dimensions than the mainTex. Here is a better image of I am hoping to achieve: https://imgur.com/ux9BhEc , it seems that the method you show me solves it by changing the texture to clamp and using tiling and offset to change the position and scale. How do I get the values to input in the tiling and offset node? ( I have the transform of the mask) – flask Nov 16 '20 at 15:42
  • 1
    In order to set tiling and offset you can use parameters as you did for SpriteText and MaskText for each and then access them from C# script. – Tomasz Juszczak Nov 16 '20 at 19:28

1 Answers1

2

As I commended I do not fully understand the question, but I will give it a try!

You want to move the UV of the texture to only make it apply to part of the image, and disable wrapping!

This can be done by using UV node while using the same channel you have on the overlapping texture and then adding the offset to it.

enter image description here

In order to disable wrapping you need to disable it on texture itself enter image description here Change Wrap Mode to Clamp enter image description here Set offset to values below 1. Now you need to just calculate what offset value for you will be as 1 is the full width of the image.

EDIT: Instead of manually changing the UV texture you should use Tiling and Offset node which has easy scaling by changing tiling values.

enter image description here

Good luck :)

Tomasz Juszczak
  • 2,276
  • 15
  • 25