Has anyone stumbled upon a toon shader with parallax mapping?
I got it working sort of, but it’s very heavy (two matrix multiplications in the fragment program, loads of other computation), so probably not the best solution ever. Any better ideas?
Also: what might be the cause of having problems loading three textures and a cube map to registers and then reaching them with samplers? Always one of the registers is empty (_MainTex), although same number of textures works in a different shader I’ve written.
uniform sampler2D _MainTex : register(s3);
uniform sampler2D _MainTex2 : register(s2);
uniform sampler2D _BumpMap : register(s1);
uniform samplerCUBE _ToonShade : register(s0);
uniform float4 _Color;
struct v2f {
float4 pos : POSITION;
float3 cubeNormal;
float4 uv;
float3 viewDirT;
float4 tangent;
};
v2f vert (appdata_tan v)
{
v2f o;
o.pos = mul (glstate.matrix.mvp, v.vertex);
o.uv = TRANSFORM_UV(0).xyxy;
glstate.matrix.invtrans.modelview[0], v.normal );
o.cubeNormal = v.normal;
o.position = v.vertex;
TANGENT_SPACE_ROTATION;
o.viewDirT = normalize(mul( rotation, ObjSpaceViewDir( v.vertex ) ));
o.tangent = v.tangent;
return o;
}
half4 frag( v2f i ) : COLOR
{
float2 uv = i.uv.xy;
half4 color1 = tex2D( _MainTex, uv );
half4 color2 = tex2D( _MainTex2, uv );
half h = tex2D( _BumpMap, uv ).w;
float2 offset = ParallaxOffset( h, 0.02, i.viewDirT );
//uv += offset;
half3 normal = tex2D(_BumpMap, uv).xyz * 2 - 1;
float3 binormal = cross( i.cubeNormal, i.tangent.xyz ) * i.tangent.w;
float3x3 rotation = float3x3( i.tangent.xyz, binormal, i.cubeNormal );
float3 cubeNormal = normalize(mul( rotation, normal ));
cubeNormal = mul((float3x3)glstate.matrix.invtrans.modelview[0], cubeNormal );
half4 toon = texCUBE(_ToonShade, cubeNormal);
//return tex2D( _MainTex, uv );//this shows black!
return toon*color2*_Color;
}