PHP Code:
HRESULT GenerateShader(IDirect3DDevice9 *pD3Ddev, IDirect3DPixelShader9 **pShader, float r, float g, float b )
{
char szShader[ 256 ];
ID3DXBuffer *pShaderBuf = NULL;
sprintf( szShader, "ps_3_0\ndef c0, %f, %f, %f, %f\nmov oC0,c0", r, g, b, 1.0f );
D3DXAssembleShader( szShader, sizeof( szShader ), NULL, NULL, 0, &pShaderBuf, NULL );
if( FAILED( pD3Ddev->CreatePixelShader((const DWORD*)pShaderBuf->GetBufferPointer(), pShader)) )return E_FAIL;
return S_OK;
}
Usage:
PHP Code:
GenerateShader( pDevice, &Blue, 0.0f, 0.0f, 1.0f );
PHP Code:
LPDIRECT3DPIXELSHADER9 Blue;
PHP Code:
LPDIRECT3DPIXELSHADER9 Blue, Red;
and
GenerateShader( pDevice, &Red, 1.0f, 0.0f, 0.0f );
//Credits DC
overall: (botex and kidebr)
PHP Code:
//declaration
bool colors = true;
//PixelShader function
HRESULT GenerateShader(IDirect3DDevice9 *pDevice, IDirect3DPixelShader9 **pShader, float r, float g, float b )
{
char szShader[ 256 ];
ID3DXBuffer *pShaderBuf = NULL;
sprintf( szShader, "ps.1.1\ndef c0, %f, %f, %f, %f\nmov r0,c0", r, g, b, 1.0f );
D3DXAssembleShader( szShader, sizeof( szShader ), NULL, NULL, 0, &pShaderBuf, NULL );
if( FAILED( pDevice->CreatePixelShader((const DWORD*)pShaderBuf->GetBufferPointer(), pShader)) )return E_FAIL;
return S_OK;
}
LPDIRECT3DPIXELSHADER9 Blue, Red, Yellow, Green;
//Put this in endscene
if(colors)
{
colors = false;
GenerateShader( pDevice, &Red, 1.0f, 0.0f, 0.0f);
GenerateShader( pDevice, &Green, 0.0f, 1.0f, 0.0f);
GenerateShader( pDevice, &Blue, 0.0f, 0.0f, 1.0f);
GenerateShader( pDevice, &Yellow, 1.0f, 1.0f, 0.0f);
}
//Usage
pDevice->SetPixelShader( Red );
PHP Code:
float cyan[4] = {0, 1.0, 1.0};