Author Topic: Texture.GetPixels AFTER shading applied  (Read 5580 times)

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Texture.GetPixels AFTER shading applied
« on: August 15, 2014, 05:13:16 AM »
Hi!

This might not be considered a "pure" NGUI-question but in case it's because of how UITexture works, I ask here anyways... :)

Basically, I want to "print" a Texture2D (UITexture.mainTexture), but not the raw, default texture, but the texture AFTER the shading has been applied (like alpha, texture-flip etc., everything that get's applied in a shader). I seriously have no clue at all how to go about this: Accessing the texture from the material (tested without success)?...

Any thoughts? Thanks!

Edit. Or is it just so easy that I wait for end of frame using a coroutine?
  1. yield  return new WaitForEndOfFrame();
  2.  

Edit2. Nope.

Edit3. To have a fallback-solution I read (which I knew would work, but want to avoid) the pixels directly from screen like this:
  1. int previousDepth = depth;
  2.                 depth = int.MaxValue;
  3.  
  4.                 yield return new WaitForEndOfFrame();
  5.  
  6.                 tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
  7.                 tex.Apply();
  8.  
  9.                 depth = previousDepth;
  10.                
  11.                 yield return new WaitForEndOfFrame(); //<-- symbolic to be in correct state when "done"
  12.  

Problem with this is that:

1. It flickers (barely noticeable though) and
2. It's more of a hack (I hate hacks).
3. It relies on the texture being at front.
4. It's just hard to maintain.
« Last Edit: August 15, 2014, 07:03:05 AM by helmesjo »

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
Re: Texture.GetPixels AFTER shading applied
« Reply #1 on: August 15, 2014, 06:50:33 AM »
you would want to draw the texture to a render texture (unity pro only), you could then save the render texture to PNG or draw it else where, upto you

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: Texture.GetPixels AFTER shading applied
« Reply #2 on: August 15, 2014, 07:03:26 AM »
you would want to draw the texture to a render texture (unity pro only), you could then save the render texture to PNG or draw it else where, upto you

Thanks, I'll check that out!