We are working on a bonestructure for our 3d-model viewing program. A normal map tiled 1:1 is needed to visualize the rough topology and another normal map tiled 500-100:1 is needed to create good-looking graininess of the bone when zoomed in really close.
See attachments for illustrations of the macro and micro bumping (using mipmapping). We want to combine both of these bumps in one shader.
We can’t just blend the two bump maps in advance, because we want to preserv all details when zooming in max on object.
We want to create something like this
http://forum.unity3d.com/viewtopic.php?t=40266
but with different tiling for the two maps.
Shader "TwoLayerBumped mix" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0.5)
_MainTex ("Base (RGB)", 2D) = "white" {}
_MainTex2 ("Base 2 (RGB)", 2D) = "white" {}
_BumpMap ("Bumpmap (RGB)", 2D) = "bump" {}
_BumpMap2 ("Bumpmap2 (RGB)", 2D) = "bump" {}
_Mask ("Mix Mask (A)", 2D) = "gray" {}
}
Category {
Blend AppSrcAdd AppDstAdd
Fog { Color [_AddFog] }
// ------------------------------------------------------------------
// ARB fragment program
SubShader {
// Ambient pass
Pass {
Tags {"LightMode" = "PixelOrNone"}
Color [_PPLAmbient]
SetTexture [_MainTex] { combine texture }
SetTexture [_Mask] { combine previous, texture }
SetTexture [_MainTex2] { combine texture lerp (previous) previous }
SetTexture [_MainTex2] { constantColor [_Color] combine previous * primary DOUBLE, previous * constant }
}
// Vertex lights
Pass {
Tags {"LightMode" = "Vertex"}
Lighting On
Material {
Diffuse [_Color]
Emission [_PPLAmbient]
}
SetTexture [_MainTex] { combine texture }
SetTexture [_Mask] { combine previous, texture }
SetTexture [_MainTex2] { combine texture lerp (previous) previous }
SetTexture [_MainTex2] { constantColor [_Color] combine previous * primary DOUBLE, previous * constant }
}
// Pixel lights
Pass {
Name "PPL"
Tags { "LightMode" = "Pixel" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_builtin
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct v2f {
V2F_POS_FOG;
LIGHTING_COORDS
float2 uv[5] ;
float3 lightDirT;
};
float4 _MainTex_ST, _MainTex2_ST, _Mask_ST, _BumpMap_ST, _BumpMap2_ST;
v2f vert (appdata_tan v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uv[0] = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv[1] = TRANSFORM_TEX(v.texcoord, _MainTex2);
o.uv[2] = TRANSFORM_TEX(v.texcoord, _Mask);
o.uv[3] = TRANSFORM_TEX(v.texcoord, _BumpMap);
o.uv[4] = TRANSFORM_TEX(v.texcoord, _BumpMap2);
TANGENT_SPACE_ROTATION;
o.lightDirT = mul( rotation, ObjSpaceLightDir( v.vertex ) );
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
uniform sampler2D _MainTex;
uniform sampler2D _MainTex2;
uniform sampler2D _BumpMap;
uniform sampler2D _BumpMap2;
uniform sampler2D _Mask;
float4 frag (v2f i) : COLOR
{
half4 col1 = tex2D(_MainTex,i.uv[0]);
half4 col2 = tex2D(_MainTex2,i.uv[1]);
half mix = tex2D(_Mask,i.uv[2]).a;
half4 texcol = lerp(col1,col2,mix);
// get normal from the normal maps
float3 normal = tex2D(_BumpMap, i.uv[3]).xyz * 2 - 1;
float3 normal2 = tex2D(_BumpMap2, i.uv[4]).xyz * 2 - 1;
float3 normcol = lerp(normal ,normal2, mix);
return DiffuseLight( i.lightDirT, normcol, texcol, LIGHT_ATTENUATION(i) );
}
ENDCG
}
}
// ------------------------------------------------------------------
// Four texture cards
SubShader {
// Vertex lit
Pass {
Lighting On
Material {
Diffuse [_Color]
Ambient [_Color]
}
SetTexture [_MainTex] { combine texture }
SetTexture [_Mask] { combine previous, texture }
SetTexture [_MainTex2] { combine texture lerp (previous) previous }
SetTexture [_MainTex2] { constantColor [_Color] combine previous * primary DOUBLE, previous * constant }
}
}
}
FallBack "VertexLit"
}
The problem with the shader above is that unity thinks that _BumpMap and _BumpMap2 is one and the same. When changing tiling for one of the two bumpmaps, the other is changed too.
Does this require Cg editing?
Any ideas on how to achieve this?

