tomtetlaw -1 Posting Pro

I'm trying to develop a pixel shader that allows me to input colors to directx in a 0-255 range for each chanel, and it will convert it to the 0-1 range that pixel shaders need to return, but the input to my pixel shader is sometimes being clamped to 255 and sometimes just being set to 0. I'm telling directx about the color with an int, which has r, g, b, a packed in it.

I don't get any warnings or error from directx, yes I have the debug runtime enabled.
If I've missed out any information just ask :)

This is the code for my shader:

matrix World;
matrix View;
matrix Projection;

struct PixelShaderInput
{
	float4 pos : sv_position;
	uint col : color0;
};

PixelShaderInput vertex( float4 Pos : VertPosition, uint Col : VertColor )
{
	PixelShaderInput ret;

	Pos = mul( Pos, World );
	Pos = mul( Pos, View );
	Pos = mul( Pos, Projection );

	ret.pos = Pos;
	ret.col = Col;

    return ret;
}

float4 pixel( PixelShaderInput input ) : sv_target
{	
	//input.col = 0xFF0000FF; << this was for testing and it works as expected..

	uint r = input.col >> 24;
	uint g = (input.col >> 16) & 0xff;
	uint b = (input.col >> 8 ) & 0xff;
	uint a = input.col & 0xff;

	float fr = (float)r / 255.0f;
	float fg = (float)g / 255.0f;
	float fb = (float)b / 255.0f;
	float fa = (float)a / 255.0f;

	return float4( fr, fg, fb, fa );
}

technique10 Render
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, vertex() ) );
		SetPixelShader( CompileShader( ps_4_0, pixel() ) );
        SetGeometryShader( NULL );
    }
}

This is how I setup my vertex layout, and how I input the vertexes to DirectX10:

const int numElems = 2;
	D3D10_INPUT_ELEMENT_DESC layout[numElems] =
	{
		{ "VertPosition", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
		{ "VertColor", 0, DXGI_FORMAT_R8G8B8A8_UINT, 0, sizeof(D3DXVECTOR3), D3D10_INPUT_PER_VERTEX_DATA, 0 }
	};
	     
	D3D10_PASS_DESC PassDesc;
	m_pVertexBaseTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );

	if( m_pDevice->CreateInputLayout( layout, numElems, PassDesc.pIAInputSignature,
		PassDesc.IAInputSignatureSize, &m_pVertexLayout ) < 0 )
		FatalError( "Couldn't create vertex input layout!" );

	m_pDevice->IASetInputLayout( m_pVertexLayout );
m_pVertexBuffer->Map( D3D10_MAP_WRITE_DISCARD, 0, (void**) &v );
	for( int i = 0; i < nCount; i++ )
		v[i] = EngineVertex( D3DXVECTOR3( pList[i].x, pList[i].y, pList[i].z ), 0xFF0000FF );
	m_pVertexBuffer->Unmap( );

This is EngineVertex:

struct EngineVertex
{
	D3DXVECTOR3 pos;
	unsigned color;

	EngineVertex( D3DXVECTOR3 p, unsigned c )
		: pos( p ), color( c )
	{
	}
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.