how to simulate the specular calculation using 'SetTextureStageState'

Started by
3 comments, last by tcige 10 years, 9 months ago

yes it is easy to accomplish it using pixel shader, but i want to try it with SetTextureStageState

i find if setting D3DRS_SPECULARENABLE, the specular calculation is as follows

(vertex's diffuse + vertex's specular) * (texture's color + vertex's specular)

i have tried different parameters and stages of SetTextureStageState, but still unsolved

Advertisement

I think you must set more things to see FFP specular, here is example:


//Turn on lighting and set an ambient value
    d3d9device->SetRenderState( D3DRS_SPECULARENABLE, TRUE );
    d3d9device->SetRenderState( D3DRS_LIGHTING, TRUE );
    d3d9device->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_COLORVALUE( 0.2f, 0.2f, 0.2f, 1.0f ) );

    //Create a simple DX directional light
    D3DLIGHT9 light0;
    ZeroMemory( &light0, sizeof(D3DLIGHT9) );
    light0.Type = D3DLIGHT_DIRECTIONAL;
    light0.Direction = D3DXVECTOR3( 0.5f, -0.8f, 0.7f );
    light0.Diffuse.r = 0.8f;
    light0.Diffuse.g = 0.8f;
    light0.Diffuse.b = 0.8f;
    light0.Diffuse.a = 1.0f;
    light0.Specular.r = 1.0f;
    light0.Specular.g = 1.0f;
    light0.Specular.b = 1.0f;
    light0.Specular.a = 1.0f;

    //Set the light
    d3d9device->SetLight(0, &light0);
    d3d9device->LightEnable(0, TRUE);

    //Create a white material
    D3DMATERIAL9 WhiteMtrl;
    ZeroMemory( &WhiteMtrl, sizeof(D3DMATERIAL9) );

    WhiteMtrl.Diffuse.r = 1.0f;
    WhiteMtrl.Diffuse.g = 1.0f;
    WhiteMtrl.Diffuse.b = 1.0f;
    WhiteMtrl.Diffuse.a = 1.0f;
    WhiteMtrl.Specular.r = 1.0f;
    WhiteMtrl.Specular.g = 1.0f;
    WhiteMtrl.Specular.b = 1.0f;
    WhiteMtrl.Specular.a = 1.0f;
    WhiteMtrl.Power     = 8.0f;

    d3d9device->SetMaterial(&WhiteMtrl);

I think you must set more things to see FFP specular, here is example:


//Turn on lighting and set an ambient value
    d3d9device->SetRenderState( D3DRS_SPECULARENABLE, TRUE );
    d3d9device->SetRenderState( D3DRS_LIGHTING, TRUE );
    d3d9device->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_COLORVALUE( 0.2f, 0.2f, 0.2f, 1.0f ) );

    //Create a simple DX directional light
    D3DLIGHT9 light0;
    ZeroMemory( &light0, sizeof(D3DLIGHT9) );
    light0.Type = D3DLIGHT_DIRECTIONAL;
    light0.Direction = D3DXVECTOR3( 0.5f, -0.8f, 0.7f );
    light0.Diffuse.r = 0.8f;
    light0.Diffuse.g = 0.8f;
    light0.Diffuse.b = 0.8f;
    light0.Diffuse.a = 1.0f;
    light0.Specular.r = 1.0f;
    light0.Specular.g = 1.0f;
    light0.Specular.b = 1.0f;
    light0.Specular.a = 1.0f;

    //Set the light
    d3d9device->SetLight(0, &light0);
    d3d9device->LightEnable(0, TRUE);

    //Create a white material
    D3DMATERIAL9 WhiteMtrl;
    ZeroMemory( &WhiteMtrl, sizeof(D3DMATERIAL9) );

    WhiteMtrl.Diffuse.r = 1.0f;
    WhiteMtrl.Diffuse.g = 1.0f;
    WhiteMtrl.Diffuse.b = 1.0f;
    WhiteMtrl.Diffuse.a = 1.0f;
    WhiteMtrl.Specular.r = 1.0f;
    WhiteMtrl.Specular.g = 1.0f;
    WhiteMtrl.Specular.b = 1.0f;
    WhiteMtrl.Specular.a = 1.0f;
    WhiteMtrl.Power     = 8.0f;

    d3d9device->SetMaterial(&WhiteMtrl);

not using light, i have set D3DRS_LIGHTING to FALSE

only vertex's diffuse, specular and texture

SetTextureStageState is used for setting "textures states", how can you expect to see speculars if you don't have light?

SetTextureStageState is used for setting "textures states", how can you expect to see speculars if you don't have light?

there is 'D3DFVF_SPECULAR' and 'D3DTA_SPECULAR', and that does not matter

i just want 'SetTextureStageState' do two add operation respectively, and modulate two results

This topic is closed to new replies.

Advertisement