Page 1 of 1

Swapping Sprite's Texture with shader

PostPosted: Sat Jun 02, 2018 8:00 am
by skipadu
Hi,

I found one way to swap sprite's texture to a different one using the following:
https://github.com/RetryEntry/UnityAnimatorChangeSprite
It is working when switching texture for the object and animation works nicely without a problem.

I would like to learn to do this with Amplify Shader and get rid of other nonsense. Just want to swap the texture.
What node(s) I should use? If no texture is given, use the one already on the sprite renderer?

And it seems that because the shader I linked, is using surface shaders it does have some lightning info (?) and my sprite is getting a weird dark overlay on it.

Thanks in advance.

Re: Swapping Sprite's Texture with shader

PostPosted: Mon Jun 04, 2018 10:20 am
by Amplify_Borba
Hello, thank you for getting in touch and for your support.

In order to change a sampler's texture, you'll have to do so via script. If you need to do it within the shader, you will have to sample additional textures and making use of the Logical Operators, which isn't as performant as simply doing so by script, or making use of a texture atlas, as per our ReadFromAtlasTiled sample.

If you don't want your shader to be affected by Unity's default lighting, you'll need to swap its Shader Type either to Unlit or to the Default Sprites shader template, since both types do not make use of that information and expect you to add your custom lighting setup.

Please let me know if this helps, thanks!

Re: Swapping Sprite's Texture with shader

PostPosted: Fri Jun 08, 2018 7:34 pm
by skipadu
Thanks for the answer.

I did get it working by switching the sprite with the script.

So new to these shaders, so really not sure what should be done and where. But hopefully learning it piece by piece.

Re: Swapping Sprite's Texture with shader

PostPosted: Mon Jun 11, 2018 9:12 am
by Amplify_Borba
No problem, thank you for letting me know you've managed to get it working.

Have you had the chance to rate and review Amplify Shader Editor? It would be awesome if you could share your experience with the Unity community, the Unity Asset Store thrives on user interaction and direct feedback.
Every bit helps, your feedback is extremely valuable to us!

Feel free to get back in touch if you have further questions, thanks!