Author Topic: clipping a panel with a non-square rect  (Read 15920 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: clipping a panel with a non-square rect
« Reply #15 on: September 18, 2014, 04:19:42 PM »
This part in the vertex shader:
  1. o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
...and this in the fragment shader:
  1. half alpha = tex2D(_ClipTex, IN.worldPos * 0.5 + float2(0.5, 0.5)).a;
...doesn't work. You're transforming the vertex coordinate by the texture matrix, but the texture matrix isn't used in NGUI, and it's never set. I have a vague recollection of writing this a while back... for Unity perhaps? Where did you get this from?

cayou

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 90
    • View Profile
Re: clipping a panel with a non-square rect
« Reply #16 on: September 18, 2014, 04:36:26 PM »
We're getting this from the 3.5.6 version (the version we are using right now).
My college told me that this line:

  1. o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
  2.  
was already into the original AlphaClip shader (the original file we modified). It allows to get the coordinate on the UIPanel (if I'm right, I'm not a shader guy...).

Then the other line is used to be able to scale the alpha with the size of the Panel.

If you still can't figure out how's working with the latest version of NGUI, we will tomorrow try into an empty project with the latest version of NGUI those changes. If we manage to do it I'll post here the solution.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: clipping a panel with a non-square rect
« Reply #17 on: September 18, 2014, 04:49:44 PM »
3.5.6 is way out of date.

Anyway I've fixed the shader on my end, so you'll find this feature in the next update. Thanks!

badawe

  • Jr. Member
  • **
  • Thank You
  • -Given: 8
  • -Receive: 7
  • Posts: 70
    • View Profile
Re: clipping a panel with a non-square rect
« Reply #18 on: September 18, 2014, 04:54:50 PM »
Awesome news! Thank you guys :D

cayou

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 90
    • View Profile
Re: clipping a panel with a non-square rect
« Reply #19 on: September 19, 2014, 08:23:58 AM »
3.5.6 is way out of date.

Anyway I've fixed the shader on my end, so you'll find this feature in the next update. Thanks!

Good news, glad to help !

And the only reason to keep this version for our project is that updating it is most of the time not necessary (for the new features, most of the time) and it might causes bug/compilation errors.

PS: The 3.5.6 version is working pretty well with the Unity5 beta 4 version ;)

cayou

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 90
    • View Profile
Re: clipping a panel with a non-square rect
« Reply #20 on: September 19, 2014, 08:33:06 AM »
One note, I don't know if you have chosen to set the alpha to the sprite on the panel to 0 when the texture mask alpha is 0 or when it's set to 1.
IMO I would say that when the alpha mask is set to 1 it should set the alpha of the sprite behind to 0.
Maybe letting the user choosing this might be great as well.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: clipping a panel with a non-square rect
« Reply #21 on: September 22, 2014, 07:25:44 AM »
You know, I wonder if it would be entirely crazy to modify this to use a sliced sprite and generate an "invisible" sliced sprites to sample for alpha. Would be terribly sweet.

cayou

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 90
    • View Profile
Re: clipping a panel with a non-square rect
« Reply #22 on: September 22, 2014, 08:14:57 AM »
Like an alpha cutout classic shader?