lundi 10 mars 2014

[Question] PixelShader Generation topic




Hey Guys,
I have some troubles with the function:


Code:


HRESULT GenerateShader(IDirect3DDevice9* Device, IDirect3DPixelShader9** Shader, float r, float g, float b, float t)
{
        char ShaderAsmBuf[256];
        ID3DXBuffer* ShaderBuf = NULL;
        sprintf_s(ShaderAsmBuf, "ps_3_0\ndef c0, %f, %f, %f, %f\nmov oC0,c0", r, g, b, t);
        if (FAILED(D3DXAssembleShader(ShaderAsmBuf, (strlen(ShaderAsmBuf) + 1), NULL, NULL, 0, &ShaderBuf, NULL)))
        {
                return E_FAIL;
        }
        return Device->CreatePixelShader((const DWORD*)ShaderBuf->GetBufferPointer(), Shader);
}


which Im using for months to generate pixelshaders cuz they look better than textures..

So my problem is following -> if I want colors which are defined like


Code:


GenerateShader(pDevice, &RedShader, 1.0f, 0.0f, 0.0f, 1.0f);
                GenerateShader(pDevice, &GreenShader, 0.0f, 1.0f, 0.0f, 1.0f);
                GenerateShader(pDevice, &BlueShader, 0.0f, 0.0f, 1.0f, 1.0f);
                GenerateShader(pDevice, &BlackShader, 0.0f, 0.0f, 0.0f, 0.0f);
                GenerateShader(pDevice, &YellowShader, 1.0f, 1.0f, 0.0f, 1.0f);
                GenerateShader(pDevice, &PinkShader, 1.0f, 0.0f, 1.0f, 1.0f);


its no problem, 1.0f is ment as 255 , means eg for red its like RGBA :


Code:


1.0f, 0.0f, 0.0f, 1.0f

which is equal to the red color code


Code:


255, 000, 000, 255

so my problem is starting in the following:

if I have eg grey as Colorcode its like


Code:


88, 88, 88, 255

and we know that theres a equality between 1.0f and 255

so the shader number for the shader based on 88 should be


Code:


88/255 = 0.3450980392156863f

because of the equality


Code:



255  =  1.0f
88    =    x

x = 88*1.0f/255


so simple equality math like we learned it in school, but the big problem is that its not showing grey then, its showing black, like it would be


Code:


1.0f, 0.0f, 1.0f, 1.0f

for the generator function and not


Code:


0.3450980392156863f, 0.3450980392156863f, 0.3450980392156863f, 1.0f

so its weirdly painting black but its all calculated right, so Im confused now like running against a wall :banghead:

and for geting grey as pixelshader I ofc do


Code:


GenerateShader(pDevice, &GreyShader, 0.3450980392156863f, 0.3450980392156863f, 0.3450980392156863f, 1.0f);

but as I wrote here .... its freaking painting the stuff black =.='

,greez GAFO :thinking:





Aucun commentaire:

Enregistrer un commentaire