Well, the main reason I was asking was for the good old terrain shader. I took your "GG Blended Bump Mapping Shader.fx" and made it into a deferred shader. Here it is for anyone who wishes to use it. If you could have a look over it and see if I did anything that was needless please let me know. Its working fine on my project as demonstrated by this screenshot.
// Green Gandalf's Blended Normal Mapping Shader
//
// designed for use with terrain objects
//
// contains two techniques: with and without bump mapping
//
// Created 7 March 2007, edited 8 March 2007.
// edited july 2 2009.
//
// edited for deferred rendering
// outputs to render targets color, normals, depth
//
float4x4 wvp : WorldViewProjection;
float4x4 mw : World;
float4x4 View;
float4x4 Projection;
float2 UVTiling = {6, 6};
float vertScale = 0.01; // reciprocal of maximum height of terrain
float contrast = 1.0; // higher values increase the contrast between textures
texture detailMap1 < string ResourceName = ""; >;
texture detailMap2 < string ResourceName = ""; >;
texture detailMap3 < string ResourceName = ""; >;
texture detailMap4 < string ResourceName = ""; >;
texture normalMap1 < string ResourceName = ""; >;
texture normalMap2 < string ResourceName = ""; >;
texture normalMap3 < string ResourceName = ""; >;
texture normalMap4 < string ResourceName = ""; >;
sampler2D detail1 = sampler_state
{ texture = <detailMap1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D detail2 = sampler_state
{ texture = <detailMap2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D detail3 = sampler_state
{ texture = <detailMap3>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D detail4 = sampler_state
{ texture = <detailMap4>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D nMap1 = sampler_state
{ texture = <normalMap1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D nMap2 = sampler_state
{ texture = <normalMap2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D nMap3 = sampler_state
{ texture = <normalMap3>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D nMap4 = sampler_state
{ texture = <normalMap4>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
struct VS_INPUT
{ float4 Pos : POSITION0;
float3 Tangent : TANGENT0;
float3 Binormal : BINORMAL0;
float3 Normal : NORMAL0;
float2 Tex : TEXCOORD0;
};
struct VS_OUTPUT
{ float4 Pos : POSITION0;
float2 Tex : TEXCOORD0;
float4 Blender : TEXCOORD1;
float2 Depth : TEXCOORD2;
float3x3 tangentToWorld : TEXCOORD3;
};
VS_OUTPUT GGBlendVShader(VS_INPUT In, VS_OUTPUT Out)
{
float4 tempPos = mul(In.Pos, mw);
Out.Pos = mul(In.Pos, wvp);
Out.Tex = In.Tex * UVTiling;
float2 hn = float2 (tempPos.y * vertScale, In.Normal.y);
hn = saturate(0.5.xx + contrast * (hn - 0.5.xx));
Out.Blender = float4 (hn.x * hn.y, hn.x * (1 - hn.y),
(1 - hn.x) * hn.y, (1 - hn.x) * (1 - hn.y));
// e.g. blends = grass, rock, sand, gravel
// calculate tangent space to world space matrix using the world space tangent,
// binormal, and normal as basis vectors
Out.tangentToWorld[0] = mul(In.Tangent, mw);
Out.tangentToWorld[1] = mul(In.Binormal, mw);
Out.tangentToWorld[2] = mul(In.Normal, mw);
float4 worldPosition = mul(float4(In.Pos.xyz,1), mw);
float4 viewPosition = mul(worldPosition, View);
float4 Position = mul(viewPosition, Projection);
Out.Depth.x = Position.z;
Out.Depth.y = Position.w;
return Out;
}
struct PS_INPUT
{ float2 Tex : TEXCOORD0;
float4 Blender : TEXCOORD1;
float2 Depth : TEXCOORD2;
float3x3 tangentToWorld : TEXCOORD3;
};
struct PS_OUTPUT
{
float4 Color : COLOR0;
float4 Normal : COLOR1;
float4 Depth : COLOR2;
};
PS_OUTPUT GGBlendPShader(PS_INPUT In, PS_OUTPUT Out)
{
float4 base1 = tex2D(detail1, In.Tex) * In.Blender.x;
float4 base2 = tex2D(detail2, In.Tex) * In.Blender.y;
float4 base3 = tex2D(detail3, In.Tex) * In.Blender.z;
float4 base4 = tex2D(detail4, In.Tex) * In.Blender.w;
float4 base = base1 + base2 + base3 + base4;
Out.Color = base;
float4 normal1 = tex2D(nMap1, In.Tex) * In.Blender.x;
float4 normal2 = tex2D(nMap2, In.Tex) * In.Blender.y;
float4 normal3 = tex2D(nMap3, In.Tex) * In.Blender.z;
float4 normal4 = tex2D(nMap4, In.Tex) * In.Blender.w;
float4 normal = normal1 + normal2 + normal3 + normal4;
//tranform to [-1,1]
float3 normalFromMap = 2.0f * normal- 1.0f;
//transform into world space
normalFromMap = mul(normalFromMap, In.tangentToWorld);
//normalize the result
normalFromMap = normalize(normalFromMap);
//output the normal, in [0,1] space
Out.Normal.rgb = 0.5f * (normalFromMap + 1.0f);
Out.Normal.a = 0.0f;
Out.Depth = In.Depth.x / In.Depth.y;
return Out;
}
technique t0 // use this for blending only
{ pass p0
{
NORMALIZENORMALS = TRUE;
VertexShader = compile vs_2_0 GGBlendVShader();
PixelShader = compile ps_2_0 GGBlendPShader();
}
}
Thanks for the help.