Jump to content
  • Advertisement
Sign in to follow this  
tracegame

how to use two sampler in pixel shade with d3d9

This topic is 2360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!