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

Two sided cutout shader for U3, wanted

Discussion in 'Shaders' started by angel_m, Jun 15, 2011.

  1. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    I am looking for a two sided transparent cutout shader compatible with Unity 3. The samples from the Comunity I have found are not for U3 or they don't work with shadows.
    Any idea where can I get it? I don´t mind to pay (reasonably) for it.
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
  3. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Thanks but it is not a good solution for my case.
     
  4. spinaljack

    spinaljack

    Joined:
    Mar 18, 2010
    Posts:
    992
    add cull off to the shader you're using

    e.g.

    Code (csharp):
    1.  
    2. // Unlit alpha-cutout shader.
    3. // - no lighting
    4. // - no lightmap support
    5. // - no per-material color
    6.  
    7. Shader "Unlit/Transparent Cutout" {
    8. Properties {
    9.     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    10.     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    11. }
    12.  
    13. SubShader {
    14.     Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    15.     LOD 100
    16.    
    17.     Pass {
    18.             [B][U]Cull Off[/U][/B]
    19.         Lighting Off
    20.         Alphatest Greater [_Cutoff]
    21.         SetTexture [_MainTex] { combine texture }
    22.     }
    23. }
    24. }
    25.  
     
    Last edited: Jun 15, 2011
  5. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Can you explain your case in more detail? I know of very few situations where doubling geometry is not the best solution.
     
  6. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Daniel is right,

    the only time you would want to render backfaces via the shader, rather than modeling them in, is when you would have to render the backfaces in a seperate pass anyway. (to work around sorting issues or concave geometry). Even if your object is transparent you can often force the order of the draw within a mesh by how you construct it in your modeling program.
     
  7. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    If you're working with cloth, for instance, doubling the geometry is not a very good idea. Download the standard shader sources from Unity's site, locate the one you need, open it in an editor and add "Cull Off" where appropriate (search the forums for the details, as this has been answered many times before). Also rename the shader in the source file. Then import it into your project, select it for use in your material, and you're ready to go.
     
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You're forgetting skinned meshes. Thats double the verts to push to the gpu if you double up.
     
  9. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Thanks to everybody.
    My case is a single complex model with different materials (one of them the transparent cutout) and doubling the whole geometry is not very convenient.
     
  10. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Hi Angel,

    When you say Transparent Cut out did you want it to work like any of surfaces in this screenshot ?

    The gold surface is opaque and clips to fully transparent, The Clear surface has varying levels of transparency on only clips at a certain threshold.

    PeterB and Hippocoder have some good points

    It is possible to just turn of culling, as long as you don't mind the lighting on the backfaces being the same as the front faces and some shadow receiving issues . Often you don't notice the lighting artifact If its on cloth. because the back faces lighting as if they were flipped has the same effect as light transfer. ( light passing through thin materials)

    I keep forgetting that unity does its skinning on the cpu in which case doubling the verts on skinned mesh like cloth would be a less efficient way of doing things compared to a multipass shader. just depends on whether you want to spend time on skinning or a second draw call.

    If you are happy with your surfaces other than the back face issue, let me know which shader you are using and i'll set up a multi pass version for you.

    Kind regards,
    Brn
     

    Attached Files:

  11. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    I think my case is very simple. I am using the standard "Transparent/Cutout/Diffuse" shader. I want to be able to "see" the textured back faces of the model but it would be sufficient to cast shadows only from one of them ( front or back faces).
    Thanks.
     
  12. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Cloth and large skinned models are good examples of situations where doubling geometry is either not possible or detrimental. I don't do a whole lot of 3D modelling, but all the programs I have used make it incredibly simple to duplicate and flip the normals of all or a subset of a model's polygons.

    When you say "different materials", are you referring to multiple submeshes, or is there one mesh whose materials you are switching at runtime? Either way, how does this reduce the viability of duplicating geometry? If I'm sounding doggedly curious, it's because I don't understand the rationale behind doing a lot of work in one place in order to avoid the tiniest bit of work in another. If there's a good reason for doing this, I'd really like to know it. I've seen a lot of people take your stance, but–with the exception of skinning and cloth–I haven't seen any indication that they aren't just being obstinate.
     
  13. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Maybe you are right, Daniel but I prefer to try the shader mod,the model needs too much tweaks to achieve the desired result because it is a single mesh with several materials applied in different polygons, and I am not a 3D expert preciselly, thanks for your advice anyway.

    Another question: I have downloaded the standard shaders sources but in the pack is not included any Transparent shader. The Transparent cutout shader in the Inspector doesn't allow to be edited, so I don´t know how can I try it...
    I have Unity Pro 3.3.
     
  14. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Unfortunately, most of Unity's shaders have different file names from their shader names. All of the transparent shader files start with "Alpha".
     
  15. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Hi Angel_m

    based on your spec's above here is a package that will do what you are after. No normal maps spec or anything fancy.

    Use the Transparent/Cutout/Diffuse Double sided shader on your material, the other is there just to generate a pass. Make sure both are added to your project. Best of luck.

    Kind regards,
    brn
     

    Attached Files:

    Last edited: Jun 18, 2011
    lauraaa and DevilZ1976 like this.
  16. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Thank you very much.
     
  17. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    No problem :)
     
  18. sumon23

    sumon23

    Joined:
    Aug 31, 2012
    Posts:
    1
    Thanks a lot brn---
     
  19. liszto

    liszto

    Joined:
    Dec 22, 2011
    Posts:
    135
    Hi, thanks again for your shader it seems really really awesome !
    I don't already test it but I want to know just one thing. It can be possible to bake lightmap with it or not ?
     
  20. James___UK

    James___UK

    Joined:
    Jan 6, 2013
    Posts:
    13
    The double sided cutout texture works fantastically for this flag I've done, thankyou so much! I was wondering if it would be ok to include the shader in a store asset upload? (I've got this diner which has a flag on it that uses it)
     
  21. andremusic1997

    andremusic1997

    Joined:
    Oct 21, 2015
    Posts:
    3
    Hello guys, i'm sorry for reviving this post, but I was reading it and begun to ask to myself. What's the most optimized option: To duplicate the model's geometry and invert the normals, or render both sides trough adding "cull off" to the shader?
     
  22. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Wow talk about an old thread coming back to life!
    IMO it depends on what you are doing and what you are trying to optimise.

    If you are production/content creation bound then using a shader variant with a toggle for the The VFACE semantic input variable is a great option with a little code to flip the normals for better lighting. Very easy for your artists to use.

    If you are fill-rate bound and you only need to double side a collar or a small surface area then getting your artist to double side only the areas needed is probably best.

    If you are vertex bound or the surface is skinned/cloth and may result in z-fighting again a VFACE test with culling off works well.

    A two pass shader doesn't really have much going for it unless you need the back-face to be dramatically different to the front-face and your target platform doesn't like branching shaders. This is the most expensive option in almost every respect.

    I hope that helps Andremusic1997