Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: kittikun on March 02, 2014, 01:06:39 AM

Title: Bind two textures to shader
Post by: kittikun on March 02, 2014, 01:06:39 AM
Hi,

I need to use a mask for my sprites and am trying to use a custom shader to achieve this. The idea is to use the same atlas (that would contain the mask and the image itself) then transfer two sets of UVs for each sprite.

The custom shader would then read from the two textures and proceed accordingly.

I was thinking about creating a variation of UIGemetry and UIDrawCall but it looks clearly tedious to achieve.

Worse case, I will probably just use a custom Mesh and plug the atlas system into it

Any recommendation for this kind of operations ?

Thanks

Title: Re: Using two textures with NGUI
Post by: kittikun on March 02, 2014, 01:43:59 AM
It seems that setting UIWidget:fillGeometry to false would allow me to define custom geometry without breaving UIwidget interface but I would still need to edit UIGeometry, UIPanel and UIDrawCall to add uv2 support to it and this could be hell to maintain with new NGUI versions

 
Title: Re: Bind two textures to shader
Post by: ArenMook on March 02, 2014, 06:50:08 PM
Create a custom widget type -- easiest to derive it from the UISprite. Give it a Material field that you set. Overwrite the material property to return your material instead, which should be created using the atlas texture for the main texture and your other texture for the secondary one (or you can just have it set on the material itself if you want).

You will of course also need to create a custom shader to use that other texture specified in your material.
Title: Re: Bind two textures to shader
Post by: kittikun on March 07, 2014, 02:44:11 AM
I have tried and this won't work since the UV will be mapped to the main sprite UV. Even if I do use a second texture i won't know how to read it entirely (0 to 1) with tex2D
Title: Re: Bind two textures to shader
Post by: ArenMook on March 07, 2014, 09:14:30 AM
The UVs will be whatever you want them to be. You set them inside OnFill.

Secondary UV coordinates are not used by NGUI. You would need to calculate them in the shader, or use the primary texture's UVs.
Title: Re: Bind two textures to shader
Post by: kittikun on March 10, 2014, 07:08:35 AM
In the end, I decided to hide the second set of UV in the color field, not the most elegant solution but at least it worked