Search Unity

Limit rendertexture colour range

Discussion in 'Scripting' started by MarigoldFleur, Jan 10, 2013.

  1. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    I'm using Simple Pixelator (code to follow) to pixelate a scene to give it a proper pixel density relative to the rest of my game and I've run into a problem.



    In spite of this texture being solid black and white, it interprets certain angles as being grey. I would like my textures to maintain their exact colour depth. Is there a way this can be accomplished? Right now, this is the code I'm using:

    Code (csharp):
    1. //SimplePixelizer
    2. //Copyright © The Breemans Lounge Company
    3. //This script should be available for free in the Asset Store. if you found this script, or bought this script, from a third party seller please contact us
    4. //contact@breemanslounge.com
    5.  
    6. using UnityEngine;
    7. using System.Collections;
    8.  
    9. [ExecuteInEditMode]
    10. [AddComponentMenu("Image Effects/Pixelizer")]
    11. public class SimplePixelizer : MonoBehaviour { 
    12.     public int pixelize = 1;
    13.     protected void Start() {
    14.         if (!SystemInfo.supportsImageEffects) {
    15.             enabled = false;
    16.             return;
    17.         }
    18.     }
    19.     void OnRenderImage (RenderTexture source, RenderTexture destination) {     
    20.         RenderTexture buffer = RenderTexture.GetTemporary(source.width/pixelize, source.height/pixelize, 0);
    21.         buffer.filterMode = FilterMode.Point;
    22.         Graphics.Blit(source, buffer); 
    23.         Graphics.Blit(buffer, destination);
    24.         RenderTexture.ReleaseTemporary(buffer);
    25.     }
    26. }
     
  2. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    Bump. This is still causing me grief and Unity Answers hasn't been any help.
     
  3. anoon

    anoon

    Joined:
    Aug 8, 2012
    Posts:
    9
    Sorry, I don't have an answer for you, but another question:

    Is simple pixelizer only for UnityPro? I did not see any such disclaimer, but does not seem to work for me.

    Thanks.
     
  4. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    This code would only work with pro.
     
  5. svenskefan

    svenskefan

    Joined:
    Nov 26, 2008
    Posts:
    282
    Hi!
    It probably has to do with mipmapping, and you should try messing with the mipmapping settings for the rendertextures.
     
  6. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    RenderTexture doesn't have mipmaps enabled by default and none are generated in the code SimplePixelizer uses. Unfortunately, my Pro trial has long expired so this is moot until I decide to take the plunge and buy it.
     
  7. Gibbonator

    Gibbonator

    Joined:
    Jul 27, 2012
    Posts:
    204
    I think the problem is you don't have point sampling enabled for the first blit going from 'source' to 'buffer'. So you need to add:

    Code (csharp):
    1.  
    2. source.filterMode = FilterMode.Point;
    3.  
    If you end up getting Unity Pro hopefully that will fix it.