Looking a little nicer now isn't it? I've jacked up the sphere quality a bit, too. There was a bit of a struggle getting the normal map integrating with everything else: one has to combine the flat normal map composed of mostly blue (indicating a vector of approx {0.5, 0.5, 1} with the normal as interpolated from the nearby vertices. This is in the pixel shader, of course. Here's mine:
pf_col PS_LitTextured(vp_pos_tex PSIn)
{
pf_col Output = (pf_col)0;
float3 baseNorms;
baseNorms.xyz = tex2D(NormalsSampler, PSIn.TexCoords).rgb;
baseNorms.r -= 0.5;
baseNorms.g -= 0.5;
baseNorms.b -= 1;
baseNorms = (baseNorms * 16) + PSIn.Normal;
float diffuseLightingFactor = DotProduct(xLightPos, PSIn.Position3D, baseNorms);
diffuseLightingFactor = saturate(diffuseLightingFactor);
diffuseLightingFactor *= xLightPower;
float4 baseColor = tex2D(TextureSampler, PSIn.TexCoords);
Output.Color = baseColor*(diffuseLightingFactor + xAmbient);
return Output;
}
In order to compose the flat normal vector with the interpolated vector, I figured the sensible thing to do would be to subtract the perpendicular vector from the value from the normal map, then add that to the normal coming from the vertex shader. In order to give the bumps a little more oomph I multiplied the difference vector up by 16.
No comments:
Post a Comment