Well, I'm new to shader programming, so I guess this could be a rather dumb question, but hoewever.
I got a simple diffuse mapping shader (followed the shader tutorials) and I added detail mapping to it. So far, so good, it looks as it should and everything, but now I want to be able to kinda blend the detail map in and out using a numerical expression. Like, the expression is 1, detail map is fully featured, expression is 0, no detail mapping at all, expression is 0.5, detail map is blended over the color map by 50 percent. I dont want to blend between the color- and the detail map (that could be easily done using lerp), but rather determine how strong the detail map influences the final result.
The pixel shader which does the diffuse- and detail mapping looks like this:
// Pixel shader
float4 DiffusePS(in float2 InTex : TEXCOORD0,
in float3 InNormal: TEXCOORD1,
in float4 inPos : TEXCOORD2) : COLOR
{
// calculate ambient lighting:
float4 Ambient = ambientIntensity*vecAmbient;
// calculate diffuse lighting:
float4 Diffuse = diffuseIntensity*SunColor*saturate(dot(-vecSunDir,normalize(InNormal)));
// get pixel color from color map, add from normal map
float4 colorMapping = tex2D(ColorMapSampler,InTex);
float4 detailMapping = tex2D(DetailMapSampler,InTex*2);
// compose
float4 Color = colorMapping*detailMapping;
//Color.rgb *= (detailMapping.r+detailMapping.g+detailMapping.b)*0.66;
Color.a *= fAlpha; // consider alpha value
// Color.a = saturate(Color.a);
// calculate final color
return (Ambient+Diffuse)*Color;
}
Anybody knows how to achieve what I described (hope I described it well
)?
EDIT: Meh, while I'm at it, anybody knows how to calculate the average color of a texture? Using the algorithm I got, I only get a monochrome result, which isn't really what I intended:
float4 calculateAveragePS_00(in float2 InTex : TEXCOORD0) : COLOR
{
float4 Color = (0,0,0,1);
Color.r += tex2D(ColorMapSampler,InTex).r;
Color.g += tex2D(ColorMapSampler,InTex).g;
Color.b += tex2D(ColorMapSampler,InTex).b;
Color.r /= InTex;
Color.g /= InTex;
Color.b /= InTex;
return Color;
}