Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Double Sided *Material*

Discussion in 'Shaders' started by p3x797, Apr 24, 2009.

  1. p3x797

    p3x797

    Joined:
    Mar 30, 2009
    Posts:
    6
    Hi everyone!

    I really need to be able to create a double sided material.

    For example one face (two tris, 1 poly) that shows the material on the reverse side of it.

    I know alot of people have enquired about this, but i really can't afford to physically have the reverse side as part of the geometry.

    My actual question is, does unity support this type of material option and if so does it need to be scripted in or is there a prefab or a shader that someone has made that is able to do it

    Any info regarding this would be amazing!

    Many thanks
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,348
    This has been asked and answered many times...a search will easily find the solution.

    --Eric
     
  3. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    dylanHart likes this.
  4. p3x797

    p3x797

    Joined:
    Mar 30, 2009
    Posts:
    6
    Hi eric

    Thank you for your insightful response, maybe if i had spent time making four thousand and something posts i may recall a vague reference to it, but unfortunately i have just the two posts for now.

    I have looked alot using the search and all i can find is information from people that don't really seem to actually know the answer to my specific question and just describe physically making another polygon mirrored fr the solution to a two sided *material*.

    i.e.

    "I know alot of people have enquired about this, but i really can't afford to physically have the reverse side as part of the geometry."

    if you can find a post relating to the material settings i need to use that can answer my question, you may receive a gold star.

    or

    you may not

    either way don't make condescending posts for the sake of it, its slightly immature, and will waste a lot of your time. Much appreciated.

    But to anyone else that may be able to help, i would love some constructive feedback it will help alot as i really can not find any information relating to this and i felt posting a more specific question would be more efficient.

    Many thanks

    Kind regards
     
  5. p3x797

    p3x797

    Joined:
    Mar 30, 2009
    Posts:
    6
    Hi Muriac,

    Thank you very very much! ill look into that then, i wasn't sure on what avenue to approach on this. But this will really help.

    Thanks so much!
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,348
    My post was not condescending, it was factual. If you do a search on "double-sided", you get many relevant results. This is to your benefit, since you would have instantly gotten your answer without having to wait for a reply. Please refrain from reading negative intent into posts where there isn't any.

    --Eric
     
  7. Charles Hinshaw

    Charles Hinshaw

    Joined:
    Feb 6, 2008
    Posts:
    1,070
  8. Animaleante

    Animaleante

    Joined:
    Apr 3, 2009
    Posts:
    26
    Here am I, a complete newb, having to answer such a popular question, shame on you!!! :D jk
    here is my code for a DoubleSided Shader mate. Not like the ones Eric posted, this one is for any model, lighted or not:

    Code (csharp):
    1. Shader "DoubleSided" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         //_BumpMap ("Bump (RGB) Illumin (A)", 2D) = "bump" {}
    6.     }
    7.     SubShader {    
    8.         //UsePass "Self-Illumin/VertexLit/BASE"
    9.         //UsePass "Bumped Diffuse/PPL"
    10.        
    11.         // Ambient pass
    12.         Pass {
    13.         Name "BASE"
    14.         Tags {"LightMode" = "PixelOrNone"}
    15.         Color [_PPLAmbient]
    16.         SetTexture [_BumpMap] {
    17.             constantColor (.5,.5,.5)
    18.             combine constant lerp (texture) previous
    19.             }
    20.         SetTexture [_MainTex] {
    21.             constantColor [_Color]
    22.             Combine texture * previous DOUBLE, texture*constant
    23.             }
    24.         }
    25.    
    26.     // Vertex lights
    27.     Pass {
    28.         Name "BASE"
    29.         Tags {"LightMode" = "Vertex"}
    30.         Material {
    31.             Diffuse [_Color]
    32.             Emission [_PPLAmbient]
    33.             Shininess [_Shininess]
    34.             Specular [_SpecColor]
    35.             }
    36.         SeparateSpecular On
    37.         Lighting On
    38.         Cull Off
    39.         SetTexture [_BumpMap] {
    40.             constantColor (.5,.5,.5)
    41.             combine constant lerp (texture) previous
    42.             }
    43.         SetTexture [_MainTex] {
    44.             Combine texture * previous DOUBLE, texture*primary
    45.             }
    46.         }
    47.     }
    48.     FallBack "Diffuse", 1
    49. }
    [/code]
     
  9. p3x797

    p3x797

    Joined:
    Mar 30, 2009
    Posts:
    6
    Thanks guys :D
     
  10. Hanford

    Hanford

    Joined:
    Aug 28, 2008
    Posts:
    167
    This gets asked/answered so often, i think it's worth Unity looking into providing this functionality with the standard assets package.
     
  11. Hanford

    Hanford

    Joined:
    Aug 28, 2008
    Posts:
    167
    PS: What part of that shader code actually renders it double-sided?

    I wish more shader source had comments in them; I feel lost trying to figure it out.
     
  12. Animaleante

    Animaleante

    Joined:
    Apr 3, 2009
    Posts:
    26
    ...SeparateSpecular On
    Lighting On
    Cull Off
    ...

    Just the cull off part
     
  13. Hanford

    Hanford

    Joined:
    Aug 28, 2008
    Posts:
    167
    Wow, so you can take any shader with Cull off, remove that line, and you get double-sided?

    Seems like comments in the default shader code could cut down this problem being asked/answered so often.
     
  14. Animaleante

    Animaleante

    Joined:
    Apr 3, 2009
    Posts:
    26
    Actually, is not taking that line off. It is more like:
    Cull On //Don't render "inner" faces
    Cull Off // Render double-sided
     
    Devilwhale likes this.
  15. GI_JOEJK

    GI_JOEJK

    Joined:
    Nov 11, 2008
    Posts:
    160
    It would be EXTREMELY helpful to have a simple "on/off" button next to the shader for this function...

    This is giving me shades of TGEA nauseum.
     
  16. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    The possible arguments to Cull are actually:

    Back
    Front
    Off

    Where Back is the default.

    The problem with simply turning off backface culling is that lighting won't work properly. If you use the shader provided above on a plane, you'll notice that both sides are always the same brightness as one another, no matter where the light source is. This is because when back faces are rendered, they use the same mesh normals as the front faces. Mesh normals are almost always calculated for front faces, and so lighting for back faces will be wrong and ugly.

    It's not a difficult problem, but it's not as easy as just turning off culling.
     
    Devilwhale likes this.
  17. Animaleante

    Animaleante

    Joined:
    Apr 3, 2009
    Posts:
    26
    Ow, I never actually coded for it to be only back sided or fof, so I didn't know, sorry...:(
     
  18. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    If I have time, I'll try and make a shader that does lighting of back faces properly. Can't promise anything for a few days, though.
     
  19. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    First attempt only works with pixel lights that don't have shadows:

    Code (csharp):
    1. Shader "Diffuse" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _MainTex ("Base (RGB)", 2D) = "white" {}
    5. }
    6.  
    7. Category {
    8.     Blend AppSrcAdd AppDstAdd
    9.     Fog { Color [_AddFog] }
    10.    
    11.     SubShader {
    12.         // Ambient pass
    13.         Pass {
    14.             Name "BASE"
    15.             Tags {"LightMode" = "PixelOrNone"}
    16.             Cull Off
    17.             Color [_PPLAmbient]
    18.             SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
    19.         }
    20.         // Vertex lights
    21.         // Pass {
    22.         //  Name "BASE"
    23.         //  Tags {"LightMode" = "Vertex"}
    24.         //  Lighting On
    25.         //  Material {
    26.         //      Diffuse [_Color]
    27.         //      Emission [_PPLAmbient]
    28.         //  }
    29.         //  SetTexture [_MainTex] { constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
    30.         // }
    31.         // Pixel lights front
    32.         Pass {
    33.             Name "PPL"
    34.             Tags { "LightMode" = "Pixel" }
    35. CGPROGRAM
    36. #pragma vertex vert
    37. #pragma fragment frag
    38. #pragma multi_compile_builtin
    39. #pragma fragmentoption ARB_fog_exp2
    40. #pragma fragmentoption ARB_precision_hint_fastest
    41. #include "UnityCG.cginc"
    42. #include "AutoLight.cginc"
    43.  
    44. struct v2f {
    45.     V2F_POS_FOG;
    46.     LIGHTING_COORDS
    47.     float2  uv;
    48.     float3  normal;
    49.     float3  lightDir;
    50. };
    51.  
    52. uniform float4 _MainTex_ST;
    53.  
    54. v2f vert (appdata_base v)
    55. {
    56.     v2f o;
    57.     PositionFog( v.vertex, o.pos, o.fog );
    58.     o.normal = v.normal;
    59.     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    60.     o.lightDir = ObjSpaceLightDir( v.vertex );
    61.     TRANSFER_VERTEX_TO_FRAGMENT(o);
    62.     return o;
    63. }
    64.  
    65. uniform sampler2D _MainTex;
    66.  
    67. float4 frag (v2f i) : COLOR
    68. {
    69.     // The eternal tradeoff: do we normalize the normal?
    70.     //float3 normal = normalize(i.normal);
    71.     float3 normal = i.normal;
    72.        
    73.     half4 texcol = tex2D( _MainTex, i.uv );
    74.    
    75.     return DiffuseLight( i.lightDir, normal, texcol, LIGHT_ATTENUATION(i) );
    76. }
    77. ENDCG
    78.         }
    79.             // Pixel lights back
    80.         Pass {
    81.             Name "PPL"
    82.             Cull Front
    83.             Tags { "LightMode" = "Pixel" }
    84. CGPROGRAM
    85. #pragma vertex vert
    86. #pragma fragment frag
    87. #pragma multi_compile_builtin
    88. #pragma fragmentoption ARB_fog_exp2
    89. #pragma fragmentoption ARB_precision_hint_fastest
    90. #include "UnityCG.cginc"
    91. #include "AutoLight.cginc"
    92.  
    93. struct v2f {
    94.     V2F_POS_FOG;
    95.     LIGHTING_COORDS
    96.     float2  uv;
    97.     float3  normal;
    98.     float3  lightDir;
    99. };
    100.  
    101. uniform float4 _MainTex_ST;
    102.  
    103. v2f vert (appdata_base v)
    104. {
    105.     v2f o;
    106.     PositionFog( v.vertex, o.pos, o.fog );
    107.     o.normal = -v.normal;
    108.     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    109.     o.lightDir = ObjSpaceLightDir( v.vertex );
    110.     TRANSFER_VERTEX_TO_FRAGMENT(o);
    111.     return o;
    112. }
    113.  
    114. uniform sampler2D _MainTex;
    115.  
    116. float4 frag (v2f i) : COLOR
    117. {
    118.     // The eternal tradeoff: do we normalize the normal?
    119.     //float3 normal = normalize(i.normal);
    120.     float3 normal = i.normal;
    121.        
    122.     half4 texcol = tex2D( _MainTex, i.uv );
    123.    
    124.     return DiffuseLight( i.lightDir, normal, texcol, LIGHT_ATTENUATION(i) );
    125. }
    126. ENDCG
    127.         }
    128.     }
    129. }
    130.  
    131. Fallback "VertexLit", 2
    132.  
    133. }
    134.  
     
  20. sonygod

    sonygod

    Joined:
    Dec 5, 2009
    Posts:
    8
    your shader light's direction was wrong.
     
  21. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    I'm not sure what you mean. The lighting looks fine to me. Are you perhaps trying to use it with vertex lights?
     
  22. M3D

    M3D

    Joined:
    Nov 11, 2009
    Posts:
    149
    excuse to all,
    how to install shader?? :?
     
  23. M3D

    M3D

    Joined:
    Nov 11, 2009
    Posts:
    149
    ok installed :wink:
    but no speculat light!! :cry:
     
  24. james.albert

    james.albert

    Joined:
    Aug 27, 2010
    Posts:
    24
    damn eric pwned you
     
  25. mooktown

    mooktown

    Joined:
    Feb 12, 2011
    Posts:
    5
    Sorry Daniel, you might be able to help, I think I'm getting the same thing. I modelled a garden umbrella but the underside of the cover was missing in unity. When I use your double sided shader, Unity draws both sides but the underside of the umbrella is lit brightly with the shadows on the top of the umbrella. How do I change the direction of the lighting or is it something else I'm doing wrong?
     
  26. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    I'm not sure what the issue is. Why are you using a double-sided shader, though? If you modelled the umbrella yourself, just duplicated and flip the geometry of the cloth in your modelling program. Then you can use regular shaders and they'll work faster and more correctly.
     
  27. bkgamer

    bkgamer

    Joined:
    Mar 31, 2010
    Posts:
    11
    In reply to Eric5h5:
    This thread IS the top result on google if you search for "double sided shader unity." I felt I should let you know that. Telling people to "do a search" is useless advice. I came to this thread through a search, so if you can't offer good information, refrain from replying next time.
     
    buttmatrix and turtlesss like this.
  28. Josh_Amsterdam

    Josh_Amsterdam

    Joined:
    Feb 22, 2011
    Posts:
    68
    @bkgamer

    Congratulations on bumping up a long-dead thread with a useless comment on someone who has answered over *thousands* of questions on both these forums and UA, very classy. At this moment Eric has over 13500 posts where this one could be considered as unhelpful (but correct) critique, you have four posts on this forum where one just made me waste my time on a rant..
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,348
    This thread has a bunch of good links thanks to Charles Hinshaw's post on the first page. Not to mention, looking through the first 10 results of your Google search, most of them are completely relevant and get you good answers. So I can't honestly see what you're complaining about...looks like "do a search" was great advice in this case.

    --Eric
     
  30. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
  31. Azazeo

    Azazeo

    Joined:
    Oct 12, 2011
    Posts:
    23
    Guys. I,ve googled a lot and tested a lot. Please, help me to write
    "Cull Off" and using two one sided materials (one with "Cull Back" and another "Cull Front") is not suitable because of incorrect lighting.
    I need "bumped diffuse doublesided" shader.
     
  32. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    Why do you need it?
     
  33. Azazeo

    Azazeo

    Joined:
    Oct 12, 2011
    Posts:
    23
    I cannot use mesh with doubled polygons because it create problems with cloth simulation. Using 2 materials with "Cull Back" and "Cull Front" still has problem with lighting on inner side.
     
  34. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    Try copying the source for the shader you want (get it from the sticky thread in this forum), and add Cull Front, and then put a minus sign in front of the value assigned to o.Normal. Unless you also need shadow support, I think that should get you everything you want.
     
  35. Azazeo

    Azazeo

    Joined:
    Oct 12, 2011
    Posts:
    23
    Well, thank you, it's almost what I need. But still has some problems - lighting not looking as correct as suppose to be (sometimes it's looks like translucent), maybe I really need "shadow support".
    I will be much appreciated if you show me how to fix it.
     
  36. Azazeo

    Azazeo

    Joined:
    Oct 12, 2011
    Posts:
    23
    $??????????.jpg
    Thats is a problem
     
  37. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    If you're using shadows (which you are in that picture), then your shader will have to support shadows properly. You'll have to write your own shadow caster and collector passes. You can see the original passes by looking in the VertexLit code in the built-in shader source.
     
  38. Azazeo

    Azazeo

    Joined:
    Oct 12, 2011
    Posts:
    23
    Well, I found this helpers in *.cginc file, but I still cannot understand how can I implement it.
    I'm game-logic programmer, but had to work with shaders, it's very difficult for me.
    Am I first who really need 2sided shader with correct lighting?
     
  39. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    Have you looked at the source code for the VertexLit shader?
     
  40. Azazeo

    Azazeo

    Joined:
    Oct 12, 2011
    Posts:
    23
    I didn't find vertexlit.shader source in Unity installation, so I googled i little and found http://code.google.com/p/syphon-imp...SyphonShaders/AlphaTest-VertexLit.shader?r=39

    So, as I can see, I need to use this lines of code? (there is late night right now, so I'll try it tommorow at work)

    Code (csharp):
    1.     // Pass to render object as a shadow caster
    2.     Pass {
    3.         Name "Caster"
    4.         Tags { "LightMode" = "ShadowCaster" }
    5.         Offset 1, 1
    6.        
    7.         Fog {Mode Off}
    8.         ZWrite On ZTest Less Cull Off
    9.  
    10. CGPROGRAM
    11. #pragma vertex vert
    12. #pragma fragment frag
    13. #pragma multi_compile_shadowcaster
    14. #pragma fragmentoption ARB_precision_hint_fastest
    15. #include "UnityCG.cginc"
    16.  
    17. struct v2f {
    18.     V2F_SHADOW_CASTER;
    19.     float2  uv : TEXCOORD1;
    20. };
    21.  
    22. uniform float4 _MainTex_ST;
    23.  
    24. v2f vert( appdata_base v )
    25. {
    26.     v2f o;
    27.     TRANSFER_SHADOW_CASTER(o)
    28.     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    29.     return o;
    30. }
    31.  
    32. uniform sampler2D _MainTex;
    33. uniform float _Cutoff;
    34. uniform float4 _Color;
    35.  
    36. float4 frag( v2f i ) : COLOR
    37. {
    38.     half4 texcol = tex2D( _MainTex, i.uv );
    39.     clip( texcol.a*_Color.a - _Cutoff );
    40.    
    41.     SHADOW_CASTER_FRAGMENT(i)
    42. }
    43. ENDCG
    44.  
    45.     }
    46.    
    47.     // Pass to render object as a shadow collector
    48.     Pass {
    49.         Name "ShadowCollector"
    50.         Tags { "LightMode" = "ShadowCollector" }
    51.        
    52.         Fog {Mode Off}
    53.         ZWrite On ZTest Less
    54.  
    55. CGPROGRAM
    56. #pragma vertex vert
    57. #pragma fragment frag
    58. #pragma fragmentoption ARB_precision_hint_fastest
    59. #pragma multi_compile_shadowcollector
    60.  
    61. #define SHADOW_COLLECTOR_PASS
    62. #include "UnityCG.cginc"
    63.  
    64. struct v2f {
    65.     V2F_SHADOW_COLLECTOR;
    66.     float2  uv : TEXCOORD5;
    67. };
    68.  
    69. uniform float4 _MainTex_ST;
    70.  
    71. v2f vert (appdata_base v)
    72. {
    73.     v2f o;
    74.     TRANSFER_SHADOW_COLLECTOR(o)
    75.     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    76.     return o;
    77. }
    78.  
    79. uniform sampler2D _MainTex;
    80. uniform float _Cutoff;
    81. uniform float4 _Color;
    82.  
    83. half4 frag (v2f i) : COLOR
    84. {
    85.     half4 texcol = tex2D( _MainTex, i.uv );
    86.     clip( texcol.a*_Color.a - _Cutoff );
    87.    
    88.     SHADOW_COLLECTOR_FRAGMENT(i)
    89. }
    90. ENDCG
    91.  
    92.     }
     
  41. LuisGuimaraes

    LuisGuimaraes

    Joined:
    Oct 9, 2009
    Posts:
    19
    Have you tried 3 passes for that cloth?

    Cull Front -> Unlit
    Cull Back -> Unlit
    Cull Off -> Shadow/Light for both sides
     
  42. Daniel-Brauer

    Daniel-Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,317
    I'm not sure how this would help. It is difficult, if not impossible, to do correct double-sided lighting in a single pass. Adding passes for "unlit" does not address this problem, or any other that I can see.
     
  43. 88darkangel

    88darkangel

    Joined:
    Oct 14, 2011
    Posts:
    14
  44. 88darkangel

    88darkangel

    Joined:
    Oct 14, 2011
    Posts:
    14

    i used this code for one of my projects
    I create JS and paste the code.
    But it;s show me that there are some errors..


    Image: http://www.flickr.com/photos/76257364@N08/6840919073/
     
  45. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    You need to create a shader, this is not javascript.

    In the project view, right click and go to 'Create > Shader'.
     
  46. 88darkangel

    88darkangel

    Joined:
    Oct 14, 2011
    Posts:
    14
    iafter i create the shader how to put it to my object?
    Thank you for your help =)
     
  47. MADmarine

    MADmarine

    Joined:
    Aug 31, 2010
    Posts:
    627
    You then need to create a new material, and when you have that material selected, change the "Shader" drop down box to the name of the shader that is defined in the code, which in this case would be "DoubleSided".

    You can then drag this material onto your object in the scene.
     
  48. rectalogic

    rectalogic

    Joined:
    Nov 30, 2012
    Posts:
    34
    This thread is pretty old, but here's another approach. I've been using Unity 4 surface shaders. Create a FrontShader (culls backfaces) and BackShader (culls frontfaces and inverts normals), and corresponding materials. Then apply both materials to the mesh you want double sided. The generated surface shader code deals with lighting, and this also allows you to specify separate textures for the front and back faces - and you can change the lightModel if needed using the surface directive.

    FrontSide.shader
    Code (csharp):
    1. Shader "Custom/FrontSide" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.     }
    5.     SubShader {
    6.         Tags { "RenderType"="Opaque" }
    7.         Cull Back
    8.         LOD 200
    9.        
    10.         CGPROGRAM
    11.         #pragma surface surf Lambert
    12.  
    13.         sampler2D _MainTex;
    14.  
    15.         struct Input {
    16.             float2 uv_MainTex;
    17.         };
    18.  
    19.         void surf(Input IN, inout SurfaceOutput o) {
    20.             half4 c = tex2D(_MainTex, IN.uv_MainTex);
    21.             o.Albedo = c.rgb;
    22.             o.Alpha = c.a;
    23.         }
    24.         ENDCG
    25.     }
    26.     FallBack "Diffuse"
    27. }
    28.  
    BackSide.shader
    Code (csharp):
    1. Shader "Custom/BackSide" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.     }
    5.     SubShader {
    6.         Tags { "RenderType"="Opaque" }
    7.         Cull Front
    8.         LOD 200
    9.        
    10.         CGPROGRAM
    11.         #pragma surface surf Lambert vertex:vert
    12.  
    13.         sampler2D _MainTex;
    14.  
    15.         struct Input {
    16.             float2 uv_MainTex;
    17.         };
    18.  
    19.         void vert (inout appdata_full v, out Input o) {
    20.             UNITY_INITIALIZE_OUTPUT(Input, o);
    21.             v.normal = -v.normal;
    22.         }
    23.  
    24.         void surf(Input IN, inout SurfaceOutput o) {
    25.             half4 c = tex2D(_MainTex, IN.uv_MainTex);
    26.             o.Albedo = c.rgb;
    27.             o.Alpha = c.a;
    28.         }
    29.         ENDCG
    30.     }
    31.     FallBack "Diffuse"
    32. }
    33.  
     
    windwolfx_23 likes this.
  49. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Except as far as I'm aware you can't apply two materials to one mesh (by which I mean submesh).

    You could just split those out into passes and have it in one shader.
     
  50. rectalogic

    rectalogic

    Joined:
    Nov 30, 2012
    Posts:
    34
    Well, it seems to work. Mesh Renderer has an array of materials, so you can put both the front and back materials in that array.

    Yeah, but you can't use passes with surface shaders since they generate the passes for you. The advantage of surface shaders is they deal with the lighting model etc. for you.