Home Unity

How Do I add BumpColorSpec material?

ScottHoneycutt
polycounter lvl 14
Offline / Send Message
ScottHoneycutt polycounter lvl 14
Unity noob question:

How do I install the BumpColorSpec Material type?

http://wiki.unity3d.com/index.php?title=BumpColorSpec

I see code but don't know what language it is or where to place it? I am aware of using the spec map in the alpha slot of the diffuse map, but that is of course very different than the usual workflow and I'm working on something where I'm intending to use multiple editors at once.

Thanks

Replies

  • Neox
    Offline / Send Message
    Neox godlike master sticky
    its hlsl, shadercode. rightclick in your assets folder ad create a new shader, paste that code in there.
  • ScottHoneycutt
    Offline / Send Message
    ScottHoneycutt polycounter lvl 14
    Neox wrote: »
    its hlsl, shadercode. rightclick in your assets folder ad create a new shader, paste that code in there.

    Thank you. I created a new shader. I can see buttons such as "Show Generated Code" and "Show All". I click on them and see MonoDev open up. I can paste the code in and even save it somewhere. That is as far as I get. No change.
  • Farfarer
    Offline / Send Message
    Farfarer polycounter lvl 17
    Double click on the new shader, monodevelop will open up with the shader code in it. Or you can just open it from Windows Explorer with notepad or something. Replace all the shader code in there with the code from the site and save the file.
  • ScottHoneycutt
    Offline / Send Message
    ScottHoneycutt polycounter lvl 14
    Farfarer wrote: »
    Double click on the new shader, monodevelop will open up with the shader code in it. Or you can just open it from Windows Explorer with notepad or something. Replace all the shader code in there with the code from the site and save the file.

    Thanks. I believe the mistake I made was I did a "file > save as" which made a new shader in a folder rather than updating the one in front of me. When I successfully do what I quoted above, I go back into Unity to see this:

    01-11.jpg

    I go back into MonoDev and see this at the top of the code:


    // Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position
    // Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION'


    I delete these lines, save it again, go back into Unity and then it's fixed. Or so its seems at first. Only the diffuse is actually showing on the model (The normal was working just fine on a default material type earlier)

    02-12.jpg
  • Farfarer
    Offline / Send Message
    Farfarer polycounter lvl 17
    It is a very old shader, looks like it's trying to do stuff for older versions of Unity.

    Here's one for the newer versions.
    1. Shader "Bumped Colour Specular" {
    2. Properties {
    3. _Color ("Main Color", Color) = (1,1,1,1)
    4. _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    5. _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    6. _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    7. _BumpMap ("Normalmap", 2D) = "bump" {}
    8. _SpecMap ("Specular Map", 2D) = "grey" {}
    9. }
    10. SubShader {
    11. Tags { "RenderType"="Opaque" }
    12. LOD 400
    13. CGPROGRAM
    14. #pragma surface surf BlinnPhongColoured
    15.  
    16. sampler2D _MainTex;
    17. sampler2D _BumpMap;
    18. sampler2D _SpecMap;
    19. fixed4 _Color;
    20. half _Shininess;
    21.  
    22. struct SurfaceOutputColoured {
    23. fixed3 Albedo;
    24. fixed3 Normal;
    25. fixed3 Emission;
    26. fixed4 SpecColor;
    27. half Specular;
    28. fixed Gloss;
    29. fixed Alpha;
    30. };
    31.  
    32. struct Input {
    33. float2 uv_MainTex;
    34. float2 uv_BumpMap;
    35. float2 uv_SpecMap;
    36. };
    37.  
    38. void surf (Input IN, inout SurfaceOutputColoured o) {
    39. fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    40. o.Albedo = tex.rgb * _Color.rgb;
    41. o.Gloss = tex.a;
    42. o.Alpha = tex.a * _Color.a;
    43. o.Specular = _Shininess;
    44. o.SpecColor = tex2D(_SpecMap, IN.uv_SpecMap);
    45. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    46. }
    47.  
    48. inline fixed4 LightingBlinnPhongColoured (SurfaceOutputColoured s, fixed3 lightDir, half3 viewDir, fixed atten)
    49. {
    50. half3 h = normalize (lightDir + viewDir);
    51. fixed diff = max (0, dot (s.Normal, lightDir));
    52. float nh = max (0, dot (s.Normal, h));
    53. float spec = pow (nh, s.Specular*128.0) * s.Gloss;
    54. fixed4 c;
    55. c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * s.SpecColor.rgb * spec) * (atten * 2);
    56. c.a = s.Alpha + _LightColor0.a * _SpecColor.a * s.SpecColor.a * spec * atten;
    57. return c;
    58. }
    59.  
    60. inline fixed4 LightingBlinnPhongColoured_PrePass (SurfaceOutputColoured s, half4 light)
    61. {
    62. fixed spec = light.a * s.Gloss;
    63. fixed4 c;
    64. c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * s.SpecColor.rgb * spec);
    65. c.a = s.Alpha + spec * _SpecColor.a * s.SpecColor.a;
    66. return c;
    67. }
    68.  
    69. inline half4 LightingBlinnPhongColoured_DirLightmap (SurfaceOutputColoured s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor)
    70. {
    71. UNITY_DIRBASIS
    72. half3 scalePerBasisVector;
    73. half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
    74. half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
    75. half3 h = normalize (lightDir + viewDir);
    76.  
    77. float nh = max (0, dot (s.Normal, h));
    78. float spec = pow (nh, s.Specular * 128.0);
    79. // specColor used outside in the forward path, compiled out in prepass
    80. specColor = lm * _SpecColor.rgb * s.SpecColor.rgb * s.Gloss * spec;
    81. // spec from the alpha component is used to calculate specular
    82. // in the Lighting*_Prepass function, it's not used in forward
    83. return half4(lm, spec);
    84. }
    85.  
    86. ENDCG
    87. }
    88.  
    89. FallBack "Bumped Specular"
    90. }
  • ScottHoneycutt
    Offline / Send Message
    ScottHoneycutt polycounter lvl 14
    Farfarer wrote: »
    It is a very old shader, looks like it's trying to do stuff for older versions of Unity.

    Here's one for the newer versions.
    1. Shader "Bumped Colour Specular" {
    2. Properties {
    3. _Color ("Main Color", Color) = (1,1,1,1)
    4. _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    5. _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    6. _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    7. _BumpMap ("Normalmap", 2D) = "bump" {}
    8. _SpecMap ("Specular Map", 2D) = "grey" {}
    9. }
    10. SubShader {
    11. Tags { "RenderType"="Opaque" }
    12. LOD 400
    13. CGPROGRAM
    14. #pragma surface surf BlinnPhongColoured
    15.  
    16. sampler2D _MainTex;
    17. sampler2D _BumpMap;
    18. sampler2D _SpecMap;
    19. fixed4 _Color;
    20. half _Shininess;
    21.  
    22. struct SurfaceOutputColoured {
    23. fixed3 Albedo;
    24. fixed3 Normal;
    25. fixed3 Emission;
    26. fixed4 SpecColor;
    27. half Specular;
    28. fixed Gloss;
    29. fixed Alpha;
    30. };
    31.  
    32. struct Input {
    33. float2 uv_MainTex;
    34. float2 uv_BumpMap;
    35. float2 uv_SpecMap;
    36. };
    37.  
    38. void surf (Input IN, inout SurfaceOutputColoured o) {
    39. fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    40. o.Albedo = tex.rgb * _Color.rgb;
    41. o.Gloss = tex.a;
    42. o.Alpha = tex.a * _Color.a;
    43. o.Specular = _Shininess;
    44. o.SpecColor = tex2D(_SpecMap, IN.uv_SpecMap);
    45. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    46. }
    47.  
    48. inline fixed4 LightingBlinnPhongColoured (SurfaceOutputColoured s, fixed3 lightDir, half3 viewDir, fixed atten)
    49. {
    50. half3 h = normalize (lightDir + viewDir);
    51. fixed diff = max (0, dot (s.Normal, lightDir));
    52. float nh = max (0, dot (s.Normal, h));
    53. float spec = pow (nh, s.Specular*128.0) * s.Gloss;
    54. fixed4 c;
    55. c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * s.SpecColor.rgb * spec) * (atten * 2);
    56. c.a = s.Alpha + _LightColor0.a * _SpecColor.a * s.SpecColor.a * spec * atten;
    57. return c;
    58. }
    59.  
    60. inline fixed4 LightingBlinnPhongColoured_PrePass (SurfaceOutputColoured s, half4 light)
    61. {
    62. fixed spec = light.a * s.Gloss;
    63. fixed4 c;
    64. c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * s.SpecColor.rgb * spec);
    65. c.a = s.Alpha + spec * _SpecColor.a * s.SpecColor.a;
    66. return c;
    67. }
    68.  
    69. inline half4 LightingBlinnPhongColoured_DirLightmap (SurfaceOutputColoured s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor)
    70. {
    71. UNITY_DIRBASIS
    72. half3 scalePerBasisVector;
    73. half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
    74. half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
    75. half3 h = normalize (lightDir + viewDir);
    76.  
    77. float nh = max (0, dot (s.Normal, h));
    78. float spec = pow (nh, s.Specular * 128.0);
    79. // specColor used outside in the forward path, compiled out in prepass
    80. specColor = lm * _SpecColor.rgb * s.SpecColor.rgb * s.Gloss * spec;
    81. // spec from the alpha component is used to calculate specular
    82. // in the Lighting*_Prepass function, it's not used in forward
    83. return half4(lm, spec);
    84. }
    85.  
    86. ENDCG
    87. }
    88.  
    89. FallBack "Bumped Specular"
    90. }

    It works! :D!! Can't thank you enough! I will definitely save that code somewhere.
Sign In or Register to comment.