Could Someone help me add something to this shader?

So i made this shader, but i want to add a second texture to it so i can put Ambient Occlusion maps from blender on the material, but still be able to put another texture, how could i add a second texture to this shader? I normally wouldn’t need to help on this, but i made this in Strumpy Shader Editor and i lost the file for it, and i don’t know how to make a shader by writing out the code.

Shader "BetterBlerber"
{
	Properties 
	{
_Color("_Color", Color) = (1,1,1,1)
_Diffuse("_Diffuse", 2D) = "white" {}
_BumpMap("_BumpMap", 2D) = "bump" {}
_CubeMap("_CubeMap", Cube) = "black" {}
_Gloss("_Gloss", Range(0.01,1) ) = 1
_SpecularIntestity("_SpecularIntestity", Range(0.01,2) ) = 2
_ReflectionColor("_ReflectionColor", Color) = (1,1,1,1)
_ReflectionStrength("_ReflectionStrength", Range(0,3) ) = 1.4
_FresnelStrength("_FresnelStrength", Range(0,3) ) = 1.7

	}
	
	SubShader 
	{
		Tags
		{
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"

		}

		
Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}


		CGPROGRAM
#pragma surface surf BlinnPhongEditor  vertex:vert
#pragma target 3.0


float4 _Color;
sampler2D _Diffuse;
sampler2D _BumpMap;
samplerCUBE _CubeMap;
float _Gloss;
float _SpecularIntestity;
float4 _ReflectionColor;
float _ReflectionStrength;
float _FresnelStrength;

			struct EditorSurfaceOutput {
				half3 Albedo;
				half3 Normal;
				half3 Emission;
				half3 Gloss;
				half Specular;
				half Alpha;
				half4 Custom;
			};
			
			inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
			{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;

			}

			inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
			{
				half3 h = normalize (lightDir + viewDir);
				
				half diff = max (0, dot ( lightDir, s.Normal ));
				
				float nh = max (0, dot (s.Normal, h));
				float spec = pow (nh, s.Specular*128.0);
				
				half4 res;
				res.rgb = _LightColor0.rgb * diff;
				res.w = spec * Luminance (_LightColor0.rgb);
				res *= atten * 2.0;

				return LightingBlinnPhongEditor_PrePass( s, res );
			}
			
			struct Input {
				float2 uv_Diffuse;
float2 uv_BumpMap;
float3 worldRefl;
float3 viewDir;
INTERNAL_DATA

			};

			void vert (inout appdata_full v, out Input o) {
float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);


			}
			

			void surf (Input IN, inout EditorSurfaceOutput o) {
				o.Normal = float3(0.0,0.0,1.0);
				o.Alpha = 1.0;
				o.Albedo = 0.0;
				o.Emission = 0.0;
				o.Gloss = 0.0;
				o.Specular = 0.0;
				o.Custom = 0.0;
				
float4 Tex2D0=tex2D(_Diffuse,(IN.uv_Diffuse.xyxy).xy);
float4 Multiply0=Tex2D0 * _Color;
float4 Tex2D1=tex2D(_BumpMap,(IN.uv_BumpMap.xyxy).xy);
float4 UnpackNormal0=float4(UnpackNormal(Tex2D1).xyz, 1.0);
float4 Tex2D3=tex2D(_BumpMap,(IN.uv_BumpMap.xyxy).xy);
float4 UnpackNormal2=float4(UnpackNormal(Tex2D3).xyz, 1.0);
float4 WorldReflection0=float4( WorldReflectionVector (IN, UnpackNormal2), 1.0);
float4 TexCUBE0=texCUBE(_CubeMap,WorldReflection0);
float4 Tex2D2=tex2D(_BumpMap,(IN.uv_BumpMap.xyxy).xy);
float4 UnpackNormal1=float4(UnpackNormal(Tex2D2).xyz, 1.0);
float4 Fresnel0=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( UnpackNormal1.xyz ) )).xxxx;
float4 Pow0=pow(Fresnel0,_FresnelStrength.xxxx);
float4 Multiply1=TexCUBE0 * Pow0;
float4 Multiply2=Multiply1 * _ReflectionStrength.xxxx;
float4 Multiply3=Multiply2 * _ReflectionColor;
float4 Master0_5_NoInput = float4(1,1,1,1);
float4 Master0_7_NoInput = float4(0,0,0,0);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = Multiply0;
o.Normal = UnpackNormal0;
o.Emission = Multiply3;
o.Specular = _Gloss.xxxx;
o.Gloss = _SpecularIntestity.xxxx;

				o.Normal = normalize(o.Normal);
			}
		ENDCG
	}
	Fallback "Diffuse"
}

bump

Here you go. I swapped around the gloss the specular too, as they were in the wrong slots for some reason. Even with the extra texture it’s about 10-20% faster on my laptop than the original (with plenty of room for more optimsation too).

Shader "Custom/HyperBlerber" 
{
	Properties 
	{
		_Color("_Color", Color) = (1,1,1,1)
		_Diffuse("_Diffuse", 2D) = "white" {}
		_BumpMap("_BumpMap", 2D) = "bump" {}
		_CubeMap("_CubeMap", Cube) = "black" {}
		_AmbientOcclusion("_AmbientOcclusion" , 2D) = "white" {}
		_Gloss("_Gloss", Range(0.01,1) ) = 1
		_SpecularIntensity("_SpecularIntensity", Range(0.01,2) ) = 2
		_ReflectionColor("_ReflectionColor", Color) = (1,1,1,1)
		_ReflectionStrength("_ReflectionStrength", Range(0,3) ) = 1.4
		_FresnelStrength("_FresnelStrength", Range(0,3) ) = 1.7

	}
	
	SubShader 
	{
		Tags
		{
			"Queue"="Geometry"
			"IgnoreProjector"="False"
			"RenderType"="Opaque"

		}

		Cull Back
		ZWrite On
		ZTest LEqual
		ColorMask RGBA



		CGPROGRAM
#pragma surface surf BlinnPhong
#pragma target 3.0


float4 _Color;
sampler2D _Diffuse;
sampler2D _BumpMap;
sampler2D _AmbientOcclusion;
samplerCUBE _CubeMap;
float _Gloss;
float _SpecularIntensity;
float4 _ReflectionColor;
float _ReflectionStrength;
float _FresnelStrength;

			
	struct Input {
		float2 uv_Diffuse;
		float2 uv_BumpMap;
		float3 worldRefl;
		float3 viewDir;
		INTERNAL_DATA
	};

	float Fresnel( float3 view , float3 normal )
	{
		float fresnel = 1.0f - dot( normalize( view ) , normal );
		return pow( fresnel , _FresnelStrength );
	}

	void surf (Input IN, inout SurfaceOutput o) 
	{
		// calculate the diffuse
		float4 diffusePart = tex2D( _Diffuse , IN.uv_Diffuse.xy );
		diffusePart *= tex2D( _AmbientOcclusion, IN.uv_Diffuse.xy );
		diffusePart *= _Color;
		
		// the vectors
		float3 normal = UnpackNormal( tex2D( _BumpMap , IN.uv_BumpMap.xy ) );
		normal = normalize( normal );
		float3 worldRefl = WorldReflectionVector(IN, normal);
		
		// the cube part
		float4 cubePart = texCUBE( _CubeMap , worldRefl );
		cubePart *= Fresnel( IN.viewDir , normal );
		cubePart *= _ReflectionStrength;
		cubePart *= _ReflectionColor;
		
		// and fill the output structure
		o.Albedo	= half3(diffusePart);
		o.Normal	= normal;
		o.Emission	= half3(cubePart);
		o.Specular	= _SpecularIntensity;
		o.Gloss		= _Gloss;
					
		}
		ENDCG
	}
	Fallback "Diffuse"
}

Thank you so much :slight_smile: i really needed this, this will help a lot. And i like that name you gave it too lol “HyperBlerber”

Oh but the specular isn’t working now, i just noticed it

hmm, ok so i tried it out a bit more, and the tiling of the regular texture affects the Acclusion Maps tiling, is it possible to make the tiling of the occlusion maps and the regular texture maps separate? Also you said that you switched the specular and gloss, but i think they were in the right places, it was just bad naming on my part.

As you found in another thread, there’s a limit to the number of texture coords that can be sent. I’ve got around this by having the diffuse and bump maps share a set of texture coords, thus letting you tile the occlusion map separately. I’ve also swapped back the Specular and Gloss parts:

Shader "Custom/HyperBlerber" 
{
	Properties 
	{
		_Color("_Color", Color) = (1,1,1,1)
		_Diffuse("_Diffuse", 2D) = "white" {}
		_BumpMap("_BumpMap", 2D) = "bump" {}
		_CubeMap("_CubeMap", Cube) = "black" {}
		_AmbientOcclusion("_AmbientOcclusion" , 2D) = "white" {}
		_Gloss("_Gloss", Range(0.01,1) ) = 1
		_SpecularIntensity("_SpecularIntensity", Range(0.01,2) ) = 2
		_ReflectionColor("_ReflectionColor", Color) = (1,1,1,1)
		_ReflectionStrength("_ReflectionStrength", Range(0,3) ) = 1.4
		_FresnelStrength("_FresnelStrength", Range(0,3) ) = 1.7

	}
	
	SubShader 
	{
		Tags
		{
			"Queue"="Geometry"
			"IgnoreProjector"="False"
			"RenderType"="Opaque"

		}

		Cull Back
		ZWrite On
		ZTest LEqual
		ColorMask RGBA



		CGPROGRAM
#pragma surface surf BlinnPhong
#pragma target 3.0


float4 _Color;
sampler2D _Diffuse;
sampler2D _BumpMap;
sampler2D _AmbientOcclusion;
samplerCUBE _CubeMap;
float _Gloss;
float _SpecularIntensity;
float4 _ReflectionColor;
float _ReflectionStrength;
float _FresnelStrength;

			
	struct Input {
		float2 uv_Diffuse;
		float2 uv_AmbientOcclusion;
		float3 worldRefl;
		float3 viewDir;
		INTERNAL_DATA
	};

	float Fresnel( float3 view , float3 normal )
	{
		float fresnel = 1.0f - dot( normalize( view ) , normal );
		return pow( fresnel , _FresnelStrength );
	}

	void surf (Input IN, inout SurfaceOutput o) 
	{
		// calculate the diffuse
		float4 diffusePart = tex2D( _Diffuse , IN.uv_Diffuse.xy );
		diffusePart *= tex2D( _AmbientOcclusion, IN.uv_AmbientOcclusion.xy );
		diffusePart *= _Color;
		
		// the vectors
		float3 normal = UnpackNormal( tex2D( _BumpMap , IN.uv_Diffuse.xy ) );
		normal = normalize( normal );
		float3 worldRefl = WorldReflectionVector(IN, normal);
		
		// the cube part
		float4 cubePart = texCUBE( _CubeMap , worldRefl );
		cubePart *= Fresnel( IN.viewDir , normal );
		cubePart *= _ReflectionStrength;
		cubePart *= _ReflectionColor;
		
		// and fill the output structure
		o.Albedo	= half3(diffusePart);
		o.Normal	= normal;
		o.Emission	= half3(cubePart);
		o.Specular	= _Gloss;
		o.Gloss		= _SpecularIntensity;
					
		}
		ENDCG
	}
	Fallback "Diffuse"
}

Hmm, well it works better now, but the specular still isn’t working.

Try this then, I’m using SSE’s lighting function instead of Unity’s, and I think that must be what you’re expecting:

Shader "Custom/HyperBlerber" 
{
	Properties 
	{
		_Color("_Color", Color) = (1,1,1,1)
		_Diffuse("_Diffuse", 2D) = "white" {}
		_BumpMap("_BumpMap", 2D) = "bump" {}
		_CubeMap("_CubeMap", Cube) = "black" {}
		_AmbientOcclusion("_AmbientOcclusion" , 2D) = "white" {}
		_Gloss("_Gloss", Range(0.01,1) ) = 1
		_SpecularIntensity("_SpecularIntensity", Range(0.01,2) ) = 2
		_ReflectionColor("_ReflectionColor", Color) = (1,1,1,1)
		_ReflectionStrength("_ReflectionStrength", Range(0,3) ) = 1.4
		_FresnelStrength("_FresnelStrength", Range(0,3) ) = 1.7

	}
	
	SubShader 
	{
		Tags
		{
			"Queue"="Geometry"
			"IgnoreProjector"="False"
			"RenderType"="Opaque"

		}

		Cull Back
		ZWrite On
		ZTest LEqual
		ColorMask RGBA



		CGPROGRAM
#pragma surface surf BlinnPhongEditor
#pragma target 3.0


float4 _Color;
sampler2D _Diffuse;
sampler2D _BumpMap;
sampler2D _AmbientOcclusion;
samplerCUBE _CubeMap;
float _Gloss;
float _SpecularIntensity;
float4 _ReflectionColor;
float _ReflectionStrength;
float _FresnelStrength;

			
			struct EditorSurfaceOutput {
				half3 Albedo;
				half3 Normal;
				half3 Emission;
				half3 Gloss;
				half Specular;
				half Alpha;
			};
			
			inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
			{
                half3 spec = light.a * s.Gloss;
                half4 c;
                c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
                c.a = s.Alpha;
                return c;
			}

			inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
			{
				half3 h = normalize (lightDir + viewDir);
				
				half diff = max (0, dot ( lightDir, s.Normal ));
				
				float nh = max (0, dot (s.Normal, h));
				float spec = pow (nh, s.Specular*128.0);
				
				half4 res;
				res.rgb = _LightColor0.rgb * diff;
				res.w = spec * Luminance (_LightColor0.rgb);
				res *= atten * 2.0;

				return LightingBlinnPhongEditor_PrePass( s, res );
			}
            
            
	struct Input {
		float2 uv_Diffuse;
		float2 uv_AmbientOcclusion;
		float3 worldRefl;
		float3 viewDir;
		INTERNAL_DATA
	};

	float Fresnel( float3 view , float3 normal )
	{
		float fresnel = 1.0f - dot( normalize( view ) , normal );
		return pow( fresnel , _FresnelStrength );
	}

	void surf (Input IN, inout EditorSurfaceOutput o) 
	{
		// calculate the diffuse
		float4 diffusePart = tex2D( _Diffuse , IN.uv_Diffuse.xy );
		diffusePart *= tex2D( _AmbientOcclusion, IN.uv_AmbientOcclusion.xy );
		diffusePart *= _Color;
		
		// the vectors
		float3 normal = UnpackNormal( tex2D( _BumpMap , IN.uv_Diffuse.xy ) );
		normal = normalize( normal );
		float3 worldRefl = WorldReflectionVector(IN, normal);
		
		// the cube part
		float4 cubePart = texCUBE( _CubeMap , worldRefl );
		cubePart *= Fresnel( IN.viewDir , normal );
		cubePart *= _ReflectionStrength;
		cubePart *= _ReflectionColor;
		
		// and fill the output structure
		o.Albedo	= half3(diffusePart);
		o.Normal	= normal;
		o.Emission	= half3(cubePart);
		o.Specular	= _Gloss;
		o.Gloss		= _SpecularIntensity;
					
		}
		ENDCG
	}
	Fallback "Diffuse"
}

Edit: If you want to know the difference, I think Unity uses a different specular power to SSE. (+ fixed typo in shader)

Ok, that worked, thank you so much :slight_smile: stuff is already looking much better with this shader.