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
    Options
    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
    Options
    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
    Options
    Offline / Send Message
    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
    Options
    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
    Options
    Offline / Send Message
    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.
    Shader "Bumped Colour Specular" {
    	Properties {
    		_Color ("Main Color", Color) = (1,1,1,1)
    		_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    		_Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    		_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    		_BumpMap ("Normalmap", 2D) = "bump" {}
    		_SpecMap ("Specular Map", 2D) = "grey" {}
    	}
    	SubShader { 
    		Tags { "RenderType"="Opaque" }
    		LOD 400
    		
    		CGPROGRAM
    			#pragma surface surf BlinnPhongColoured
    
    			sampler2D _MainTex;
    			sampler2D _BumpMap;
    			sampler2D _SpecMap;
    			fixed4 _Color;
    			half _Shininess;
    
    			struct SurfaceOutputColoured {
    				fixed3 Albedo;
    				fixed3 Normal;
    				fixed3 Emission;
    				fixed4 SpecColor;
    				half Specular;
    				fixed Gloss;
    				fixed Alpha;
    			};
    
    			struct Input {
    				float2 uv_MainTex;
    				float2 uv_BumpMap;
    				float2 uv_SpecMap;
    			};
    
    			void surf (Input IN, inout SurfaceOutputColoured o) {
    				fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    				o.Albedo = tex.rgb * _Color.rgb;
    				o.Gloss = tex.a;
    				o.Alpha = tex.a * _Color.a;
    				o.Specular = _Shininess;
    				o.SpecColor = tex2D(_SpecMap, IN.uv_SpecMap);
    				o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    			}
    
    			inline fixed4 LightingBlinnPhongColoured (SurfaceOutputColoured s, fixed3 lightDir, half3 viewDir, fixed atten)
    			{
    				half3 h = normalize (lightDir + viewDir);
    				
    				fixed diff = max (0, dot (s.Normal, lightDir));
    				
    				float nh = max (0, dot (s.Normal, h));
    				float spec = pow (nh, s.Specular*128.0) * s.Gloss;
    				
    				fixed4 c;
    				c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * s.SpecColor.rgb * spec) * (atten * 2);
    				c.a = s.Alpha + _LightColor0.a * _SpecColor.a * s.SpecColor.a * spec * atten;
    				return c;
    			}
    
    			inline fixed4 LightingBlinnPhongColoured_PrePass (SurfaceOutputColoured s, half4 light)
    			{
    				fixed spec = light.a * s.Gloss;
    				
    				fixed4 c;
    				c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * s.SpecColor.rgb * spec);
    				c.a = s.Alpha + spec * _SpecColor.a * s.SpecColor.a;
    				return c;
    			}
    
    			inline half4 LightingBlinnPhongColoured_DirLightmap (SurfaceOutputColoured s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor)
    			{
    				UNITY_DIRBASIS
    				half3 scalePerBasisVector;
    				
    				half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
    				
    				half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
    				half3 h = normalize (lightDir + viewDir);
    
    				float nh = max (0, dot (s.Normal, h));
    				float spec = pow (nh, s.Specular * 128.0);
    				
    				// specColor used outside in the forward path, compiled out in prepass
    				specColor = lm * _SpecColor.rgb * s.SpecColor.rgb * s.Gloss * spec;
    				
    				// spec from the alpha component is used to calculate specular
    				// in the Lighting*_Prepass function, it's not used in forward
    				return half4(lm, spec);
    			}
    
    		ENDCG
    	}
    
    	FallBack "Bumped Specular"
    }
    
  • ScottHoneycutt
    Options
    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.
    Shader "Bumped Colour Specular" {
    	Properties {
    		_Color ("Main Color", Color) = (1,1,1,1)
    		_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    		_Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    		_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    		_BumpMap ("Normalmap", 2D) = "bump" {}
    		_SpecMap ("Specular Map", 2D) = "grey" {}
    	}
    	SubShader { 
    		Tags { "RenderType"="Opaque" }
    		LOD 400
    		
    		CGPROGRAM
    			#pragma surface surf BlinnPhongColoured
    
    			sampler2D _MainTex;
    			sampler2D _BumpMap;
    			sampler2D _SpecMap;
    			fixed4 _Color;
    			half _Shininess;
    
    			struct SurfaceOutputColoured {
    				fixed3 Albedo;
    				fixed3 Normal;
    				fixed3 Emission;
    				fixed4 SpecColor;
    				half Specular;
    				fixed Gloss;
    				fixed Alpha;
    			};
    
    			struct Input {
    				float2 uv_MainTex;
    				float2 uv_BumpMap;
    				float2 uv_SpecMap;
    			};
    
    			void surf (Input IN, inout SurfaceOutputColoured o) {
    				fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    				o.Albedo = tex.rgb * _Color.rgb;
    				o.Gloss = tex.a;
    				o.Alpha = tex.a * _Color.a;
    				o.Specular = _Shininess;
    				o.SpecColor = tex2D(_SpecMap, IN.uv_SpecMap);
    				o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    			}
    
    			inline fixed4 LightingBlinnPhongColoured (SurfaceOutputColoured s, fixed3 lightDir, half3 viewDir, fixed atten)
    			{
    				half3 h = normalize (lightDir + viewDir);
    				
    				fixed diff = max (0, dot (s.Normal, lightDir));
    				
    				float nh = max (0, dot (s.Normal, h));
    				float spec = pow (nh, s.Specular*128.0) * s.Gloss;
    				
    				fixed4 c;
    				c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * s.SpecColor.rgb * spec) * (atten * 2);
    				c.a = s.Alpha + _LightColor0.a * _SpecColor.a * s.SpecColor.a * spec * atten;
    				return c;
    			}
    
    			inline fixed4 LightingBlinnPhongColoured_PrePass (SurfaceOutputColoured s, half4 light)
    			{
    				fixed spec = light.a * s.Gloss;
    				
    				fixed4 c;
    				c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * s.SpecColor.rgb * spec);
    				c.a = s.Alpha + spec * _SpecColor.a * s.SpecColor.a;
    				return c;
    			}
    
    			inline half4 LightingBlinnPhongColoured_DirLightmap (SurfaceOutputColoured s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor)
    			{
    				UNITY_DIRBASIS
    				half3 scalePerBasisVector;
    				
    				half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
    				
    				half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
    				half3 h = normalize (lightDir + viewDir);
    
    				float nh = max (0, dot (s.Normal, h));
    				float spec = pow (nh, s.Specular * 128.0);
    				
    				// specColor used outside in the forward path, compiled out in prepass
    				specColor = lm * _SpecColor.rgb * s.SpecColor.rgb * s.Gloss * spec;
    				
    				// spec from the alpha component is used to calculate specular
    				// in the Lighting*_Prepass function, it's not used in forward
    				return half4(lm, spec);
    			}
    
    		ENDCG
    	}
    
    	FallBack "Bumped Specular"
    }
    

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