Author Topic: Bind two textures to shader  (Read 5439 times)

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
Bind two textures to shader
« 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

« Last Edit: March 02, 2014, 06:03:48 AM by kittikun »

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
Re: Using two textures with NGUI
« Reply #1 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

 
« Last Edit: March 02, 2014, 01:59:46 AM by kittikun »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bind two textures to shader
« Reply #2 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.

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
Re: Bind two textures to shader
« Reply #3 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
« Last Edit: March 07, 2014, 03:11:58 AM by kittikun »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bind two textures to shader
« Reply #4 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.

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
Re: Bind two textures to shader
« Reply #5 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