Jump to content
  • Advertisement
Sign in to follow this  
jackharmon

Maintaining lighting with pixel shaders?

This topic is 3648 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

I just started using a pixel shader to blend 4 textures using a combined alphamap, and when I did this, I lost my ambient lighting - it acts as though lighting is turned off. Here's my shader code:
ps_1_4

////////////////////////////////
// r0: alphamaps
// r1 - r4: textures
////////////////////////////////

// Sample textures
texld r0, t0
texld r1, t1
texld r2, t1
texld r3, t1
texld r4, t1

// Combine textures together based off of their alphamaps
mul r1, r1, r0.x
lrp r2, r0.y, r2, r1
lrp r3, r0.z, r3, r2
lrp r0, r0.w, r4, r3


What do I need to do to this to maintain my old lighting? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Namethatnobodyelsetook
Assuming you're just using a pixel shader, the fixed pipeline vertex processing is still running. Just mul with V0 whereever you'd like to mix in the lighting... usually at the end of the mixing.


After setting my render states, this is all that I do. My Ambient lighting changes each frame using D3DRS_AMBIENT.


device3D->SetFVF( D3DVERTEX::FVF );
device3D->SetMaterial( &m_pMaterials[0] );
device3D->SetPixelShader( g_SplatShader );
D3DXVECTOR3 vector;

for( int y = 0; y < PATCHSIZE; y++ )
{
for( int x = 0; x < PATCHSIZE; x++ )
{
device3D->SetTexture( 0, zoneQuads[x][y]->alpha );
device3D->SetTexture( 1, zoneQuads[x][y]->tex1 );
device3D->SetTexture( 2, zoneQuads[x][y]->tex2 );
device3D->SetTexture( 3, zoneQuads[x][y]->tex3 );
device3D->SetTexture( 4, zoneQuads[x][y]->tex4 );
device3D->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, zoneQuads[x][y]->verts, sizeof(D3DVERTEX) );
}
}



And the vertex structure. Do I need more to make it happen?

struct D3DVERTEX
{
D3DXVECTOR3 p;
D3DXVECTOR3 n;
FLOAT tu1, tv1;
FLOAT tu2, tv2;

static const DWORD FVF;
};



Where should I start to get the lighting back? You say to mul V0. Do you have some example code available so I can attempt to figure it out?

Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!