Author Topic: UITextures + Unlit/Texture shader no longer showing up after upgrading to 3.11  (Read 9426 times)

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
As an effect in our game we're using a simple script that will create a 500x500 texture, fill each pixel in that texture with a random color, then assign it to a UITexture object with an Until/Texture shader.  Here's a simplified version of our script:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BlitTest : MonoBehaviour {
  5.        
  6.         // Use this for initialization
  7.         void Start ()
  8.         {
  9.                 Texture2D texture = new Texture2D( 500, 500, TextureFormat.ARGB32, false );
  10.                 for( int x = 0; x < 500; x++ )
  11.                 {
  12.                         for( int y = 0; y < 500; y++ )
  13.                         {
  14.                                 texture.SetPixel( x, y, new Color( Random.Range( 0f, 1f ), Random.Range( 0f, 1f ), Random.Range( 0f, 1f ) ) );
  15.                         }
  16.                 }
  17.                 texture.Apply();
  18.                 GameObject.FindObjectOfType<UITexture>().mainTexture = texture;
  19.         }
  20. }
  21.  

When using NGUI 3.10, the results are as expected:


However, when we upgrade to NGUI 3.11, the UITexture no longer shows up in the game:



The only difference between the two screen shots is that the 2nd one uses NGUI 3.11 instead of 3.10.
I noticed in the readme that there's a lot of changes within NGUI as far as UV's, geometry, etc.  Could one of those be causing this issue, and is there a way to resolve it?  I can provide the test project I used for this demo if necessary.
Thanks
-Mo

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Did a quick test on my end. New scene, ALT+SHIFT+T, assigned this script to the object:
  1. using UnityEngine;
  2.  
  3. public class Test2 : MonoBehaviour
  4. {
  5.         void Start ()
  6.         {
  7.                 Texture2D texture = new Texture2D(128, 128, TextureFormat.RGBA32, false);
  8.                 for (int x = 0; x < 128; x++)
  9.                 {
  10.                         for (int y = 0; y < 128; y++)
  11.                         {
  12.                                 texture.SetPixel(x, y, new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)));
  13.                         }
  14.                 }
  15.                 texture.Apply();
  16.                 GetComponent<UITexture>().mainTexture = texture;
  17.         }
  18. }
  19.  
The main difference is I use Unlit/Transparent Colored as the shader.

Unlit/Texture is one sided, and the texture points in the opposite direction, so it effectively gets culled for you. You can rotate it 180 degrees, or use a double sided shader like Unlit/Transparent Colored.

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
Yup, using that shader does do it.  Is there a reason why the old shader broke though?  I'm trying to learn as much about how this stuff works as possible for future stuff.
Thanks!
-Mo

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I changed the orientation of NGUI's geometry to face along the Z, so the front face is pointing forward. This affects shaders that have back face culling enabled with the default orientation because the UI camera by default looks at the UI from behind rather than from the front. The reason I changed it is to make it more sense for world geometry (in-world UIs). The UI shaders should not be using culling (and none of NGUI's shaders do).