The problem is, no matter what finalColour is at the end, the colour of the pixel is a greyscale colour, the value of the output's alpha. So if finalColour is (0.3, 0.2, 0.1, 1.0) then the pixel ends up (1.0, 1.0, 1.0, 1.0). In desperation, I changed the end to:
If return float4(not white) yields white, then the problem doesn't lie in your shader, so you've posted the wrong code. Post the blending code etc. instead.
Of course it should. Post some other code then, or better try using PIX to debug a pixel that gets the wrong color. If you can replace your shader with another that only does "return float4(1.0f, 0.0f, 0.0f, 1.0f)" and it's still white it obviously has nothing to do with the shader.
I've used PIX to debug the shader. The colour that gets written just seems to be different to the colour returned by the pixel shader - running through the shader in PIX's debugger shows everything in the shader working fine.
DXerror(m_swapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), reinterpret_cast<void**>(&m_backBuffer)));
DXerror(m_d3dDevice->CreateRenderTargetView(m_backBuffer, 0, &m_renderTargetView));
m_backBuffer->Release(); // need this because the call to GetBuffer adds an extra COM reference
int shaderID = -1;
int materialID = -1;
int meshID = -1;
for (std::vector<Renderable>::iterator it = renderables.begin(); it != renderables.end(); ++it)
{
if (it->shaderID() != shaderID) shaderID = it->updatePerShader(&m_viewMatrix, &m_projMatrix);
if (it->materialID() != materialID) materialID = it->updatePerMaterial();
if (it->meshID() != meshID) meshID = it->updatePerMesh();
for ( UINT p = 0; p < techDesc.Passes; p++)
{
technique->GetPassByIndex( p )->Apply(0);
m_d3dDevice->DrawIndexed( it->meshIndices(), 0, 0 );
}
}
m_swapChain->Present(0, 0);
}
And here's the entire .fx file it's using:
//--------------------------------------------------------------------------------------
// File: Tutorial02.fx
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 PosH : SV_POSITION;
float4 Color : COLOR0;
float3 Normal : TEXCOORD0;
float3 Pos : TEXCOORD1;
};
cbuffer lights
{
Light_Point PointLights[3];
Light_Parallel ParallelLights[3];
Light_Spot SpotLights[3];
int NumPointLights;
int NumParallelLights;
int NumSpotLights;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT VS( float4 Pos : POSITION , float4 Color : COLOR, float3 Normal : NORMAL)
{
matrix WorldView = mul(WorldMatrix, ViewMatrix); // so we don't have to calculate it twice
VS_OUTPUT output = (VS_OUTPUT)0;
Apart from the code to create the vertex and index buffers for the mesh, they're the only parts that involve the directx device. Before I posted here I thought it might be a blending issue, but as I said, I don't set blending states anywhere at all in the code, so it should just use the default.
If you comment out the entire shader and just do return float4(1.0f, 0.0f, 0.0f, 1.0f) does it still get white?
I've used PIX to debug the shader. The colour that gets written just seems to be different to the colour returned by the pixel shader - running through the shader in PIX's debugger shows everything in the shader working fine.[/quote]
Did you right-click a pixel in the render view and select debug pixel so you get a list of every write to the pixel?
Is there anything other than Initial frambuffer value and a Draw call that outputs the color?
Is the color there also white, or just on the screen?
Usually in PIX the SysValue for SV_Target is TARGET, not NONE as in your case..
Check all the warnings that you get from compiling your shader, and definitely try replacing the entire shader with return single color, and not leaving the whole thing in there. Perhaps compilation fails.