Sign in to follow this  
tracegame

how to use two sampler in pixel shade with d3d9

Recommended Posts

tracegame    164
just beginner of d3d9,the ps code is something like this

[source lang="cpp"]
sampler s_2D = sampler_state
{
minfilter = LINEAR;
maxfilter = LINEAR;
};


struct PS_INPUT
{
float2 tex : TEXCOORD0;
};

struct PS_OUTPUT
{
float4 Color:COLOR;
};

PS_OUTPUT PS(PS_INPUT psInput)
{
PS_OUTPUT Out_ps = (PS_OUTPUT) 0;
Out_ps.Color = tex2D(s_2D, psInput.tex);
return Out_ps;
}
[/source]

and the code in main.cpp

[source lang="cpp"]//=========setup

V_RETURN( D3DXCreateTextureFromFile( pd3dDevice, L"texture.jpg", &g_pTexture) );
pd3dDevice->SetTexture(0, g_pTexture);

LPD3DXBUFFER pCode_PS;
DWORD dwShaderFlags = D3DXSHADER_SKIPOPTIMIZATION|D3DXSHADER_DEBUG;
V_RETURN(D3DXCompileShaderFromFile( L"HLSLTexture.psh", NULL, NULL, "PS",
"ps_2_0", dwShaderFlags, &pCode_PS,
NULL, &g_pConstantTable_PS));

V_RETURN(pd3dDevice->CreatePixelShader( (DWORD*)pCode_PS->GetBufferPointer(), &g_pPixelShader));
pCode_PS->Release();

//=====render

if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{

pd3dDevice->SetPixelShader( g_pPixelShader );
pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 );

V( pd3dDevice->EndScene() );
}[/source]

how can i use another sampler,or texture.i try to load another image in cpp


[source lang="cpp"]V_RETURN( D3DXCreateTextureFromFile( pd3dDevice, L"texture2.jpg", &g_pTexture2) );
pd3dDevice->SetTexture(1, g_pTexture2);[/source]
and add another member

[source lang="cpp"]
sampler s_2D = sampler_state
{
minfilter = LINEAR;
maxfilter = LINEAR;
};

struct PS_INPUT
{
float2 tex : TEXCOORD0;
float2 tex2 : TEXCOORD1;
};

struct PS_OUTPUT
{
float4 Color:COLOR;
};



PS_OUTPUT PS(PS_INPUT psInput)
{
PS_OUTPUT Out_ps = (PS_OUTPUT) 0;
Out_ps.Color = tex2D(s_2D, psInput.tex2);
return Out_ps;
}
[/source]

but it doesn't work,nothing shows up.what's wrong?how can i fix that?

Share this post


Link to post
Share on other sites
Dawoodoz    461
Pix can show you if your resources are loaded by finding their buffers and selecting a relevant time.
[url="http://blogs.msdn.com/b/manders/archive/2006/12/15/a-painless-introduction-to-pix-for-windows.aspx"]http://blogs.msdn.co...or-windows.aspx[/url]

I advice you to start learning DirectX 11 instead since it support both new and old hardware.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this