Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ChrisX930 · Oct 25, 2017 at 07:07 AM · unity 5shadersalphafragment

Fragment Shader with Alpha in Texture

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: alt text

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: alt text

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?

Video of some tests on Hardware: https://www.youtube.com/edit?o=U&video_id=QIi-JE9eU-E

This is the shader I use the most of the time:

    // Simplified VertexLit shader by Cellenseres.
 // - no per-material color
 // - no specular
 // - no emission
 
 Shader "N3DS/DoubleSided/VertexLitCullOff" 
  {
  Properties
   {
      _MainTex ("Base (RGB)", 2D) = "white" {}
  }
  
  SubShader 
  {
      Tags { "RenderType"="Opaque" }
      Cull Off
      LOD 80
      
      // Non-lightmapped
      Pass {
          Tags { "LightMode" = "Vertex" }
          
          Material 
          {
              Diffuse (1,1,1,1)
              Ambient (1,1,1,1)
          } 
          Lighting On
          SetTexture [_MainTex] {
              constantColor (1,1,1,1)
              Combine texture * primary DOUBLE, constant // UNITY_OPAQUE_ALPHA_FFP
          } 
      }
      
      // Lightmapped, encoded as dLDR
      Pass
       {
          Tags { "LightMode" = "VertexLM" }
          Cull Off
  
          BindChannels {
              Bind "Vertex", vertex
              Bind "normal", normal
              Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
              Bind "texcoord", texcoord1 // main uses 1st uv
          }
          
          SetTexture [unity_Lightmap] {
              matrix [unity_LightmapMatrix]
              combine texture
          }
          SetTexture [_MainTex] {
              constantColor (1,1,1,1)
              combine texture * previous DOUBLE, constant // UNITY_OPAQUE_ALPHA_FFP
          }
      }
      
      // Lightmapped, encoded as RGBM
      Pass 
      {
          Tags { "LightMode" = "VertexLMRGBM" }
          Cull Off
  
          BindChannels {
              Bind "Vertex", vertex
              Bind "normal", normal
              Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
              Bind "texcoord", texcoord1 // main uses 1st uv
          }
          
          SetTexture [unity_Lightmap] {
              matrix [unity_LightmapMatrix]
              combine texture * texture alpha DOUBLE
          }
          SetTexture [_MainTex] {
              constantColor (1,1,1,1)
              combine texture * previous QUAD, constant // UNITY_OPAQUE_ALPHA_FFP
          }
      }    
      
      // Pass to render object as a shadow caster
      Pass 
      {
          Name "ShadowCaster"
          Tags { "LightMode" = "ShadowCaster" }
          ZWrite On ZTest LEqual Cull Off
  
          CGPROGRAM
          #pragma vertex vert
          #pragma fragment frag
          #pragma multi_compile_shadowcaster
          #include "UnityCG.cginc"
  
          struct v2f { 
              V2F_SHADOW_CASTER;
          };
  
          v2f vert( appdata_base v )
          {
              v2f o;
              TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
              return o;
          }
  
          float4 frag( v2f i ) : SV_Target
          {
              SHADOW_CASTER_FRAGMENT(i)
          }
          ENDCG
      }    
  }
  }
 


img1-2.png (244.4 kB)
img-3-4.png (489.6 kB)
Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChrisX930 · Oct 25, 2017 at 01:17 PM 0
Share

/push Really need some help with that

avatar image andrew-lukasik · Oct 25, 2017 at 01:36 PM 0
Share

http://answers.unity3d.com/storage/temp/104380-img-3-4.png This looks more like mesh (triangle order) sorting issue - not shader specific necessarily

avatar image ChrisX930 andrew-lukasik · Oct 25, 2017 at 03:17 PM 0
Share

How can I edit that? When I use Legacy Shaders/Transparent/Cutout/Diffuse, it looks correct. With Legacy Shaders/Transparent/VertexLit it doesn't.

it should look like: alt text

but it looks like: alt text

is there a way to create a workaround for that?

Alpha Cutout isn't supported by the hardware yet :S

avatar image andrew-lukasik ChrisX930 · Oct 25, 2017 at 04:00 PM 0
Share

These issues here are all as old as computer graphics itself. You can find people posting about this and giving advice probably from like early 2000 onward. It's generally referred as "transparency sorting" or "alpha blending" + "sorting issues"

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

151 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it more qualitative to calculate light direction manually or using WorldSpaceLightDir(vertex)? 1 Answer

How can I make shadows pixelated in fragment function? 1 Answer

Multiply Shader with Alpha 0 Answers

using two shaders together 1 Answer

shader problem 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges