Search Unity

Simple mobile shader with color picker and shininess

Discussion in 'Shaders' started by ThisIsSparta, Sep 23, 2016.

  1. ThisIsSparta

    ThisIsSparta

    Joined:
    May 4, 2014
    Posts:
    142
    Hi guys!
    I was wondering is someone has a simple shader for mobile with shininess and colorpicker for the diffuse. Thank you!
     
  2. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    A simple one. From Bumped Specular shader.

    Code (CSharp):
    1.  
    2.  
    3. Shader "Mobile/Color Specular" {
    4. Properties {
    5.     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    6.     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    7.     _Color("Color", Color) = (1,1,1,1)
    8. }
    9. SubShader {
    10.     Tags { "RenderType"="Opaque" }
    11.     LOD 250
    12.    
    13. CGPROGRAM
    14. #pragma surface surf MobileBlinnPhong exclude_path:prepass nolightmap noforwardadd halfasview interpolateview
    15.  
    16. inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
    17. {
    18.     fixed diff = max (0, dot (s.Normal, lightDir));
    19.     fixed nh = max (0, dot (s.Normal, halfDir));
    20.     fixed spec = pow (nh, s.Specular*128) * s.Gloss;
    21.    
    22.     fixed4 c;
    23.     c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * atten;
    24.     UNITY_OPAQUE_ALPHA(c.a);
    25.     return c;
    26. }
    27.  
    28. sampler2D _MainTex;
    29. half _Shininess;
    30. fixed4 _Color;
    31.  
    32. struct Input {
    33.     float2 uv_MainTex;
    34. };
    35.  
    36. void surf (Input IN, inout SurfaceOutput o) {
    37.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    38.     o.Albedo = _Color.rgb*tex.rgb;
    39.     o.Gloss = tex.a;
    40.     o.Alpha = tex.a;
    41.     o.Specular = _Shininess;
    42. }
    43. ENDCG
    44. }
    45.  
    46. FallBack "Mobile/VertexLit"
    47. }
    48.  
     
    arufolo and Michal_123 like this.
  3. ThisIsSparta

    ThisIsSparta

    Joined:
    May 4, 2014
    Posts:
    142
    thank you :)
     
  4. ThisIsSparta

    ThisIsSparta

    Joined:
    May 4, 2014
    Posts:
    142
    any chance this can bake lightmaps too?
     
  5. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    Just delete the "nolightmap" param
     
  6. ThisIsSparta

    ThisIsSparta

    Joined:
    May 4, 2014
    Posts:
    142
    Hey again :) I want to remove the texture input and have just the color picker and the shininess. I don't need texture. Which lines should I delete?
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,729
    The ones that have something to do with _MainTex
     
  8. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    You can try this.
    Code (CSharp):
    1. Shader "Mobile/Color Specular" {
    2. Properties {
    3.     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    4.     _Color("Color", Color) = (1,1,1,1)
    5. }
    6. SubShader {
    7.     Tags { "RenderType"="Opaque" }
    8.     LOD 250
    9.  
    10. CGPROGRAM
    11. #pragma surface surf MobileBlinnPhong exclude_path:prepass noforwardadd halfasview interpolateview
    12. inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
    13. {
    14.     fixed diff = max (0, dot (s.Normal, lightDir));
    15.     fixed nh = max (0, dot (s.Normal, halfDir));
    16.     fixed spec = pow (nh, s.Specular*128) * s.Gloss;
    17.  
    18.     fixed4 c;
    19.     c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * atten;
    20.     UNITY_OPAQUE_ALPHA(c.a);
    21.     return c;
    22. }
    23. half _Shininess;
    24. fixed4 _Color;
    25. struct Input {
    26.     float3 pos;
    27. };
    28. void surf (Input IN, inout SurfaceOutput o) {
    29.     o.Albedo = _Color.rgb;
    30.     o.Gloss = _Color.a;
    31.     o.Alpha = _Color.a;
    32.     o.Specular = _Shininess;
    33. }
    34. ENDCG
    35. }
    36. FallBack "Mobile/VertexLit"
    37. }
     
  9. Michal_123

    Michal_123

    Joined:
    Feb 5, 2014
    Posts:
    3
    Hello,
    I have a big request, is there a possibility to add cubemap reflection to this shader?

    Code (CSharp):
    1.  
    2. Shader "Mobile/Color Specular" {
    3. Properties {
    4.     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    5.     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    6.     _Color("Color", Color) = (1,1,1,1)
    7. }
    8. SubShader {
    9.     Tags { "RenderType"="Opaque" }
    10.     LOD 250
    11.  
    12. CGPROGRAM
    13. #pragma surface surf MobileBlinnPhong exclude_path:prepass nolightmap noforwardadd halfasview interpolateview
    14. inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
    15. {
    16.     fixed diff = max (0, dot (s.Normal, lightDir));
    17.     fixed nh = max (0, dot (s.Normal, halfDir));
    18.     fixed spec = pow (nh, s.Specular*128) * s.Gloss;
    19.  
    20.     fixed4 c;
    21.     c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * atten;
    22.     UNITY_OPAQUE_ALPHA(c.a);
    23.     return c;
    24. }
    25. sampler2D _MainTex;
    26. half _Shininess;
    27. fixed4 _Color;
    28. struct Input {
    29.     float2 uv_MainTex;
    30. };
    31. void surf (Input IN, inout SurfaceOutput o) {
    32.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    33.     o.Albedo = _Color.rgb*tex.rgb;
    34.     o.Gloss = tex.a;
    35.     o.Alpha = tex.a;
    36.     o.Specular = _Shininess;
    37. }
    38. ENDCG
    39. }
    40. FallBack "Mobile/VertexLit"
    41. }
    42.  
     
  10. mhmtemnacr

    mhmtemnacr

    Joined:
    Mar 7, 2013
    Posts:
    15
    Hi. Can we add emission property to this?