DBPRO features a COLOR OBJECT, which provides the easiest way to make an object or limb render in a single colour. The problem with this approach is that in most cases when you need an object to be a certain colour, the object is instead displayed as a desaturated fade of the colour you specify.
One way to overcome this problem is by using SET OBJECT EMISSIVE to enhance the colour, and SET OBJECT FOG to prevent coloured objects from being affected by fog can help make the colour stand out. The problem with this solution is that all of these parameters are disregarded once you introduce shaders into your game or application to enhance the look of your scene. Another problem is that you may not want to have to deal with such parameters whatsoever.
This sample shader demonstrates how you can get started displaying your objects in rich colour uneffected by fog, ambience or other environmental factors. The object simply remains coloured by the tint you specify. Use the FillColor constant in the shader to specify colour you want to use. Shader constants can be adjusted in code by using SET EFFECT CONSTANT VECTOR. All objects using the same effect number will be displayed by the same colour that is assigned to that shader.
float4x4 WorldViewProj : WorldViewProjection;
float4x4 World : World;
float4x4 WorldView : WorldView;
float4 eyePos : CameraPosition;
float4 FillColor = {1.0,0,0,1.0};
float Brightness
<
string UIWidget = "slider";
float UIMax = 1.0;
float UIMin = 0.0;
float UIStep = 0.01;
> = 0.5;
struct app_in
{
float4 pos : POSITION;
float3 normal : NORMAL;
};
struct vs_out
{
float4 pos : POSITION;
float angle : TEXCOORD0;
};
vs_out DefaultVertexShader( app_in IN )
{
vs_out OUT;
OUT.pos = mul( IN.pos, WorldViewProj );
float4 wPos = mul( IN.pos, World );
float3 wNormal = mul( IN.normal, (float3x3)World );
float angle = saturate( dot( normalize(wNormal), normalize(eyePos.xyz - wPos.xyz) ) );
OUT.angle = angle / 1.5;
return OUT;
}
float4 DefaultPixelShader( vs_out IN ) : COLOR
{
float angle = saturate(IN.angle) + Brightness;
float4 color = FillColor*angle;
return float4(color.xyz,1);
}
technique Default
{
pass p0
{
VertexShader = compile vs_2_0 DefaultVertexShader( );
PixelShader = compile ps_2_0 DefaultPixelShader( );
}
}