Search Unity

A velvet or satin shader?

Discussion in 'Shaders' started by garyhaus, Apr 12, 2007.

  1. garyhaus

    garyhaus

    Joined:
    Dec 16, 2006
    Posts:
    601
    Does anyone know if the capability exists or has created a shader for velvet or satin? Specifically looking for effects to change with incidence angle to get the satin, velvet look. Thanks in advance.

    Cheers,

    Gary
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    I did experiment with cloth rendering some 4 years back. The easy and cheap trick in that time was to use a special cubemap to get satin/velvet-like look. I might dig up the cubemaps and the shaders somewhere (it was long time ago).
     
  3. garyhaus

    garyhaus

    Joined:
    Dec 16, 2006
    Posts:
    601
    Thanks Aras. I hope to be able to do this in Unity. I use this capability often in software rendered scenery. I have seen some nVidia and DirectX shaders that do this.

    Gary
     
  4. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Hi Gary.

    You could use the X-Ray shader from the wiki as a start. It works like the Facing Ratio node in maya which can be used to create velvet -> Maya Velvet shader tutorial. More info on the Facing Ratio shader node here.

    /Patrik
     
  5. garyhaus

    garyhaus

    Joined:
    Dec 16, 2006
    Posts:
    601
    Yes I thought about using that shader... I just don't know enough yet about coding one. I will use that as a start since no one else has one created yet. Thanks for the tip.

    Cheers,

    Gary
     
  6. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Recreated the velvet effect from Steve J. Tubbrits maya tut by combining the X-Ray shader (wiki) + standard Self-Illumin/Diffuse + a little copying from the shader tuts in the docs.

    Could be used for all kinds of rim-light effects aswell, just create a texture that fits your needs. Maybe a rimlight color can be added to control the look a bit more...



    Code (csharp):
    1. Shader "SC/Velvet" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,0.5)
    4.         _MainTex ("Base (RGB) Rim-Light Ramp (A)", 2D) = "white" {}
    5.     }
    6.     SubShader {
    7.         //make Self-Illumination depend on Facig Ratio
    8.         Pass {
    9.             Tags {"LightMode" = "PixelOrNone"}
    10.             Color [_PPLAmbient]
    11.            
    12.             CGPROGRAM
    13.             // profiles arbfp1
    14.             // vertex vert
    15.             // fragment frag
    16.             // fragmentoption ARB_fog_exp2
    17.  
    18.             #include "UnityCG.cginc"
    19.  
    20.             float4 _Color;
    21.             sampler2D _MainTex : register(s0);
    22.             //sampler2D _BumpMap : register(s1);
    23.  
    24.             struct v2f {
    25.                 V2F_POS_FOG;
    26.                 float2  uv : TEXCOORD0;
    27.                 float2  uv1 : TEXCOORD1;
    28.             };
    29.  
    30.             v2f vert (appdata_base v)
    31.             {
    32.                 v2f o;
    33.                 PositionFog( v.vertex, o.pos, o.fog );
    34.                 o.uv = TRANSFORM_UV(0);
    35.                
    36.                 float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
    37.                
    38.                 o.uv1.x = dot(viewDir,v.normal);
    39.                 o.uv1.y = 0.5;
    40.                
    41.                 return o;
    42.             }
    43.  
    44.             half4 frag (v2f i) : COLOR
    45.             {
    46.                 half4 texcol = tex2D( _MainTex, i.uv );
    47.                 half4 texcol2 = tex2D( _MainTex, i.uv1 );
    48.                 return texcol * _Color * texcol2.a;
    49.             }
    50.             ENDCG
    51.            
    52.             SetTexture [_MainTex] {}
    53.         }
    54.        
    55.         UsePass " Diffuse/PPL"
    56.     }
    57.    
    58.     //FallBack "Self-Illumin/VertexLit", 1
    59.     FallBack "Normal-Diffuse", 1
    60. }
    Use a texture with a gradient alpha channel. See the attached file for an example.
     

    Attached Files:

  7. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Looks awesome man, welldone!
    AC
     
  8. garyhaus

    garyhaus

    Joined:
    Dec 16, 2006
    Posts:
    601
    My friend I thank you soooo much! You should post it on the wiki now! Cannot thankyou enough!!! You are mighty!


    Cheers,

    Gary
     
  9. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    That is so nice - now for a chance to earn some bonus points:

    This shader can be easily converted to use texture combiners (instead of a fragment program) hence work on just about anything. Try to give it a shot for brownie points ;-)
     
  10. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Challange accepted ;-)

    I was a bit lazy when i did this I admit. Didn't think about the best way, just copied pasted it together from other shaders. Could be a good exercise in texture combiners though!

    /P
     
  11. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Got it working without the fragment program :)

    One thing I don't get is how the different uv coordinates are used. Seems it automatically maps the first UV set to the first texture stage and the second UV set to the second texture stage? Is that right? I don't need BindChannels to do that?

    Code (csharp):
    1. Shader "SC/Velvet" {
    2.      Properties {
    3.           _Color ("Main Color", Color) = (1,1,1,0.5)
    4.           _MainTex ("Base (RGB) Rim-Light Ramp (A)", 2D) = "white" {}
    5.      }
    6.      SubShader {
    7.           //For Velvet look, Make Self-Illumination Depend on Facig Ration
    8.           Pass {
    9.                Tags {"LightMode" = "PixelOrNone"}
    10.                Color [_PPLAmbient]
    11.            
    12.                CGPROGRAM
    13.                // profiles arbfp1
    14.                // vertex vert
    15.  
    16.                #include "UnityCG.cginc"
    17.  
    18.                sampler2D _MainTex : register(s0);
    19.  
    20.                struct v2f {
    21.                     V2F_POS_FOG;
    22.                     float2  uv : TEXCOORD0;
    23.                     float2  uv1 : TEXCOORD1;
    24.                };
    25.  
    26.                v2f vert (appdata_base v)
    27.                {
    28.                     v2f o;
    29.                     PositionFog( v.vertex, o.pos, o.fog );
    30.                     o.uv = TRANSFORM_UV(0);
    31.                
    32.                     float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
    33.                
    34.                     o.uv1.x = dot(viewDir,v.normal);
    35.                     o.uv1.y = 0.5;
    36.                
    37.                     return o;
    38.                }
    39.            
    40.                ENDCG
    41.            
    42.                SetTexture [_MainTex] {
    43.                     constantColor [_Color]
    44.                     combine constant * texture
    45.                }
    46.                SetTexture [_MainTex] {
    47.                     constantColor (0,0,0,1)
    48.                     combine previous lerp(texture) constant
    49.                }
    50.            
    51.           }
    52.        
    53.           UsePass " Diffuse/PPL"
    54.      }
    55.    
    56.      FallBack "Normal-Diffuse", 1
    57. }
     
  12. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    That's correct. BindChannels is only when you don't use vertex programs; when you do you control what gets output to what yourself.
     
  13. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Thanks Aras. Things are beginning to make sense...

    I'll post it on the wiki.

    /P
     
  14. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Shader is on the wiki -> Velvet shader.

    Also, did a little creative alpha channeling for a satin like look:

     
  15. garyhaus

    garyhaus

    Joined:
    Dec 16, 2006
    Posts:
    601
    Simply AWESOME!!! Thank you so much for your efforts on this. I hope that I won't be the only using this really cool shader!!!

    Cheers,

    Gary
     
  16. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    i'll definitly find a use for it too - that is a fantastic shader metervara - thanks for sharing ; )
     
  17. aaronsullivan

    aaronsullivan

    Joined:
    Nov 10, 2005
    Posts:
    986
    Should be pretty nice for a silver-surfer-esque chrome look, too. :D
     
  18. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Just playing around. I modeled a spider and put the Velvet
    Shader on it. gives more like a painted metal effect.

    Norby
     

    Attached Files:

  19. jordan

    jordan

    Joined:
    Mar 24, 2008
    Posts:
    3
    I just don't know enough yet about coding one. I will use that as a start since no one else has one created yet.
     
  20. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Creative spam?

    3 semi-related replies, and what looks like an affiliate link for the website.

    I apologize if this is not the case...

    -Jeremy
     
  21. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Ouch, accusing someone of being a spam bot :wink:

    I really doubt it, but we'll keep an eye on it... no offense jordan.

    Unless you are a bot, which in that case, "01100110 01110101 01100011 01101011 00100000 01101111 01100110 01100110".
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Such language! I don't know if it's scarier that I knew what that said right away, or that I bothered to make sure I was right. ;)

    --Eric
     
  23. Obscurity

    Obscurity

    Joined:
    Nov 13, 2007
    Posts:
    203
    Any way to add traditional bump/spec to this so that the rim light follows the normal map?

    I've been trying to make a rim lit bump/spec/diffuse shader and this seems like the closest hope for what I'm looking to do.

    http://forum.unity3d.com/viewtopic.php?t=24333
     
  24. Map_Builder

    Map_Builder

    Joined:
    Aug 23, 2011
    Posts:
    1
    Hi, the shader do not seems to work anymore. Does somebody knows where to find it for last version of unity ?

    Thanks.
     
  25. DanHibiki

    DanHibiki

    Joined:
    Aug 3, 2011
    Posts:
    1
    I'm getting "No subshaders can run on this graphics card" error when compiling the code.
     
  26. Spartan_Boy

    Spartan_Boy

    Joined:
    Jul 8, 2012
    Posts:
    38