Search Unity

Alpha Textures without Alpha Cutout? Please help

Discussion in 'Shaders' started by Cellenseres, Oct 25, 2017.

  1. Cellenseres

    Cellenseres

    Joined:
    Mar 30, 2015
    Posts:
    68
    Hey Guys, I really need your help.

    I'm working on a Game for (New) Nintendo 3DS right now but Unity for N3DS has limited Shader support.

    This shaders are supported: Stereoscopic Rendering, Vertex Shaders, Fragment Shaders (Limited), Lightmap, Fog, Gamma Pipeline

    This shaders are not supported: Standard Shaders, Surface Shaders, Compute Shaders, Pixel Lighting, HDR Rendering, Linear Rendering, Image Effects

    Unity for Nintendo 3DS has vertex shader support based on OpenGL ES 2.0.

    I want to add some models to my game which need Shaders with AlphaCutout, which isn't supported by Unity for N3DS.
    The Shader I use looks like this:


    The same problem happens when I use "Legacy Shaders/Transparent/VertexLit". The Alpha works but all Textures are transparent and everything shines through it.
    Example:


    I really need help with that :S Is there a workaround to get Alpha to work without making the whole Texture transparent? Without AlphaCutout?

    I've tried this without luck: https://forum.unity.com/threads/alpha-value-in-fragment-shader.366876/

    Is there a way to get a working alpha to work like in "Legacy Shaders/Transparent/VertexLit" without making the rest transparent?


    This is the shader I use the most of the time:
    Code (CSharp):
    1.    // Simplified VertexLit shader by Cellenseres.
    2. // - no per-material color
    3. // - no specular
    4. // - no emission
    5. Shader "N3DS/DoubleSided/VertexLitCullOff"
    6.   {
    7.   Properties
    8.    {
    9.       _MainTex ("Base (RGB)", 2D) = "white" {}
    10.   }
    11.  
    12.   SubShader
    13.   {
    14.       Tags { "RenderType"="Opaque" }
    15.       Cull Off
    16.       LOD 80
    17.  
    18.       // Non-lightmapped
    19.       Pass {
    20.           Tags { "LightMode" = "Vertex" }
    21.      
    22.           Material
    23.           {
    24.               Diffuse (1,1,1,1)
    25.               Ambient (1,1,1,1)
    26.           }
    27.           Lighting On
    28.           SetTexture [_MainTex] {
    29.               constantColor (1,1,1,1)
    30.               Combine texture * primary DOUBLE, constant // UNITY_OPAQUE_ALPHA_FFP
    31.           }
    32.       }
    33.  
    34.       // Lightmapped, encoded as dLDR
    35.       Pass
    36.        {
    37.           Tags { "LightMode" = "VertexLM" }
    38.           Cull Off
    39.  
    40.           BindChannels {
    41.               Bind "Vertex", vertex
    42.               Bind "normal", normal
    43.               Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
    44.               Bind "texcoord", texcoord1 // main uses 1st uv
    45.           }
    46.      
    47.           SetTexture [unity_Lightmap] {
    48.               matrix [unity_LightmapMatrix]
    49.               combine texture
    50.           }
    51.           SetTexture [_MainTex] {
    52.               constantColor (1,1,1,1)
    53.               combine texture * previous DOUBLE, constant // UNITY_OPAQUE_ALPHA_FFP
    54.           }
    55.       }
    56.  
    57.       // Lightmapped, encoded as RGBM
    58.       Pass
    59.       {
    60.           Tags { "LightMode" = "VertexLMRGBM" }
    61.           Cull Off
    62.  
    63.           BindChannels {
    64.               Bind "Vertex", vertex
    65.               Bind "normal", normal
    66.               Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
    67.               Bind "texcoord", texcoord1 // main uses 1st uv
    68.           }
    69.      
    70.           SetTexture [unity_Lightmap] {
    71.               matrix [unity_LightmapMatrix]
    72.               combine texture * texture alpha DOUBLE
    73.           }
    74.           SetTexture [_MainTex] {
    75.               constantColor (1,1,1,1)
    76.               combine texture * previous QUAD, constant // UNITY_OPAQUE_ALPHA_FFP
    77.           }
    78.       }
    79.  
    80.       // Pass to render object as a shadow caster
    81.       Pass
    82.       {
    83.           Name "ShadowCaster"
    84.           Tags { "LightMode" = "ShadowCaster" }
    85.           ZWrite On ZTest LEqual Cull Off
    86.  
    87.           CGPROGRAM
    88.           #pragma vertex vert
    89.           #pragma fragment frag
    90.           #pragma multi_compile_shadowcaster
    91.           #include "UnityCG.cginc"
    92.  
    93.           struct v2f {
    94.               V2F_SHADOW_CASTER;
    95.           };
    96.  
    97.           v2f vert( appdata_base v )
    98.           {
    99.               v2f o;
    100.               TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
    101.               return o;
    102.           }
    103.  
    104.           float4 frag( v2f i ) : SV_Target
    105.           {
    106.               SHADOW_CASTER_FRAGMENT(i)
    107.           }
    108.           ENDCG
    109.       }
    110.   }
    111.   }
     
    Last edited: Oct 26, 2017
  2. Cellenseres

    Cellenseres

    Joined:
    Mar 30, 2015
    Posts:
    68
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Unfortunately, not really. The 3DS's GPU does appear to be capable of alpha test, and this really is the only answer to how to achieve the look you want. The next closest solution is to break up your meshes into multiple parts or at least multiple materials and only use the transparent materials on those areas that need it. This will solve the issue of the snowflake, but not the tree. The tree relies heavily only proper depth sorting which only alpha test can achieve.

    Have you contacted Unity directly about this? Or posted in a 3DS specific forum (which I assume exists but certainly wouldn't be public)?
     
    Galactic_Muffin likes this.
  4. Cellenseres

    Cellenseres

    Joined:
    Mar 30, 2015
    Posts:
    68
    Heyho,
    I've posted in the 3DS specific forum already but it takes a loooong time to get a answer there.
    The 3DS is absolutly capable to use Alpha Test, but it's not implemented in Unity for N3DS yet.
    That's why I thought there's a workaround to achieve the same effect as alpha test.
    I hope they'll implement Alpha Test in the next version of Unity for N3DS. Dunno if I can contact Unity directly for that.

    EDIT:
    I tried to break up some meshes into multiple parts and it looks ... better.
    like in this video

    Unfortunately it only works for more simple Objects.
    I tried some other (like the tree) but the transparency and sorting fu**s up for more complicated models I want to use.
     
    Last edited: Oct 27, 2017
    Galactic_Muffin likes this.