playMaker

Author Topic: Combine Textures  (Read 4146 times)

geoquav

  • Playmaker Newbie
  • *
  • Posts: 14
Combine Textures
« on: January 26, 2017, 09:12:59 AM »
I am looking for a way that I can combine two or more textures at runtime to create a new texture for my shader.

Example: I have a base character texture. I then have another texture for the chest armor. I want the player to be able to add or remove the chest armor at will. I also want this to change the appearance of the character.

From what I can tell this is possible with Texture2D:

https://docs.unity3d.com/ScriptReference/Texture2D.html

However, since I am not very great with coding outside of Playmaker I am struggling to get this to work.

Essentially what I am looking for is a Playmaker action that will allow me to add 2 textures (if possible of varying sizes with the pixel location defined by the user using SetPixel). That outputs a new texture that I can then add onto my shader I am currently using.

Is this within the scope of what Playmaker can do? Thank you.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Combine Textures
« Reply #1 on: March 30, 2017, 12:54:26 AM »
Hi, so I looked into doing this for you. I browsed some resources of other people trying to do it, and the results dont seem promising.

It seems like the best possible solution is the use a shader that can hold two different textures. One for the top layer that supports transparency and one for the bottom, for the background.

Seems combining textures, esp of different sizes during runtime is messy and possibly cpu heavy. Especially when face with a much easier possibility.


Here is one example of a custom shader: http://answers.unity3d.com/questions/915606/combining-2-textures-into-one.html

Here they discus using unitys decal shader: http://answers.unity3d.com/questions/473197/c-combining-two-textures.html


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Combine Textures
« Reply #2 on: March 30, 2017, 01:02:40 AM »
So i tried the legacy decal shader and it works good for this. Heck, i might use it :)

It allows for 2 textures that layer on top of each other very well. It can even still take an albedo to tint it, if you want. Very easy to adjust the textures during runtime with playmaker.

Does that solve your issue?

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Combine Textures
« Reply #3 on: March 30, 2017, 08:45:07 AM »
Ok, so I went ahead and wrote the combine textures action. Right now the alpha channel doesnt seem to combine quite right. Sorry, I dont think I can fix it. Maybe Jean would be able to take a look when he has time.

I included the script, along with two sample textures from photoshop. One for the background, and one for the "watermark", which has alpha on it.

In unity, you must set your texture to read/write, or it cannot be read.

1. Open the texture in the inspector
2. Change the texture type to normal (or other type that allows for read/write).
3 Click read/write box.
4. Choose alpha transparency style.
5. Click Apply.




jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Combine Textures
« Reply #4 on: March 31, 2017, 03:28:40 AM »
Hi,

 ok, it works, but few things to make it even better and more usable:

- a Proper Unity package will help getting everything properly inside Unity. I don't really recommand zipping your stuff, as they have none of the required settings applied to work.

- The Everyframe option is not needed and will affect performances a lot, prefer removing it and simply use that action once and only when needed

- Psd textures are bad and should be avoided at all costs, Prefer using regular png, then transparency is working fine. Photoshop can export to web, I use Sketch too and it's amazing for doing vector based UI and basics.

- The action could propose positioning ( top right, bottom left, center, etc), and offset in pixels, then it would become flexible.

- also check with non power of two textures, it gives odd results.

Plenty of work indeed :) If you struggle with this let me know, I can help out.


 Bye,

 Jean


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Combine Textures
« Reply #5 on: March 31, 2017, 07:57:22 AM »
Thanks Jean. I appreciate your guidance. I will try and make the changes and then post back here.