Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Texture point filtering + Flash

Discussion in 'Flash' started by keely, Dec 24, 2011.

  1. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Current Flash build doesn't seem to support point filtering (?)

    I would really like to know if:
    a) it can be enabled somehow in the developer preview
    b) it will be supported ever

    I have huge effort invested in a (future) Asset Store product which pretty much relies on point filtering. I was planning to take part in the Flash compo too. Even yes/no answer without any explanation would be very helpful at this point.
     
  2. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Code (csharp):
    1.  
    2. Shader "Flashy/Nearest" {
    3.     Properties {
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         _TexWidth ("Texture width", Float) = 128.0
    6.         _TexHeight ("Texture height", Float) = 128.0
    7.  
    8.     }
    9.     SubShader {
    10.         Tags { "Queue" = "Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    11.  
    12.         Pass {
    13.             ZWrite Off
    14.             Cull off
    15.             Blend SrcAlpha OneMinusSrcAlpha
    16.  
    17.             CGPROGRAM
    18.                 #pragma vertex vert
    19.                 #pragma fragment frag
    20.                 #include "UnityCG.cginc"
    21.  
    22.                 sampler2D _MainTex;
    23.                 float _TexWidth;
    24.                 float _TexHeight;
    25.  
    26.                 struct VertOut
    27.                 {
    28.                     float4 position : POSITION;
    29.                     float4 color : COLOR;
    30.                     float4 texcoord : TEXCOORD0;
    31.                 };
    32.  
    33.                 struct VertIn
    34.                 {
    35.                     float4 vertex : POSITION;
    36.                     float4 color : COLOR;
    37.                     float4 texcoord : TEXCOORD0;
    38.                 };
    39.  
    40.                 VertOut vert(VertIn input)
    41.                 {
    42.                     VertOut output;
    43.                     output.position = mul(UNITY_MATRIX_MVP,input.vertex);
    44.                     output.color = input.color;
    45.                     output.texcoord = float4( input.texcoord.xy, 0, 0);
    46.                     return output;
    47.                 }
    48.  
    49.                 struct FragOut
    50.                 {
    51.                     float4 color : COLOR;
    52.                 };
    53.                                
    54.                 FragOut frag(VertIn input)
    55.                 {
    56.                     FragOut output;
    57.                     half4 texcol = tex2D(_MainTex, float2(float(int(input.texcoord.x * _TexWidth) + 0.5) / _TexWidth, float(int(input.texcoord.y * _TexHeight) + 0.5) / _TexHeight));
    58.                     output.color = input.color * texcol;
    59.                     return output;
    60.                 }
    61.             ENDCG
    62.         }
    63.  
    64.     }
    65.     FallBack "Diffuse"
    66. }
    67.  
    68.  
    I know it's xmas eve and all that, but I just couldn't let this be. Gotta give me some points for dedication :)

    This is a CG shader that emulates Unity "point"-filtering and works in Flash builds too. You have to provide the texture width and height in shader properties.

    I never wrote CG shader before in my life so any suggestions appreciated.
     
    Last edited: Dec 24, 2011
  3. Evan-Greenwood

    Evan-Greenwood

    Joined:
    Aug 6, 2008
    Posts:
    98
    Thanks Keely!

    I was wondering about this too. It pretty much excluded me from the flash competition (though clearly I wasn't as dedicated as you about solving the problem).
     
  4. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Glad I could help. Too bad you didn't notice this in time to enter the contest :(
     
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    There's no deep technical reason why point filtering doesn't work yet. It's just a bit of a hassle to implement, that's all (technical reason: filtering mode needs to be in the shader itself, so we need to patch AGAL pixel shaders depending on what filtering is used).

    We'll see whether we can do it for the initial real release, or whether that would have to come later.
     
  6. jcarpay

    jcarpay

    Joined:
    Aug 15, 2008
    Posts:
    561
    Still not working out of the box in Unity 4.0.1
    Any change this is going to be supported properly in 4.1?

    Update: Point filtering is actually properly supported. It appeared something odd was going on with an imported FBX file.
     
    Last edited: Mar 13, 2013