Multiple Vertex shaders DX8.

Discussion in 'Game Development (Technical)' started by Battleline, May 9, 2005.

  1. wazoo

    Original Member

    Joined:
    Jul 27, 2004
    Messages:
    519
    Likes Received:
    0
    I'm really hoping that'll make the fix to your problem Battleline. I'm crossing my fingers for ya.

    I know how freaking frustrating these things can get...entire weeks can be sucked away by the stupidest of things.

    I'm sure we've all been there and done that (WAY too many times)
     
  2. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    Thanks for pullin for me on this one wazoo. Unfortunately it didn't fix the problem... so instead, I did what I always do when I can't figure something out. I kludged it. I just drew a billboard using a world transform that gets it to approxamately fit the screen. Since I"m going for a glow effect, it doesn't really have to be perfect, just close. I may try to un-kludge it later, but I'm moving forward for now because I'm sick of screwing with it, and I'm sure everyone in this forum is sick of my dumb questions ;)
     
  3. impossible

    Original Member

    Joined:
    Aug 9, 2004
    Messages:
    443
    Likes Received:
    0
    I don't see how it was easier for you to get a billboard working with a world transform than it was to draw a screen aligned quad directly. Are you still using a vertex shader? If so can you post it? Something leads me to believe that your vertex shader actually wasn't compiling (is "dcl_" part of the DX8 shader spec?) At this point in time I've invested enough in this problem that I really want to know what's going wrong :).
     
  4. wazoo

    Original Member

    Joined:
    Jul 27, 2004
    Messages:
    519
    Likes Received:
    0
    Ditto! Give up the goods Battleline! :)
     
  5. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    You were right, I didn't check my error log. Turns out my vertex shader didn't compile. I'll try it again now that I have it compiling.
     
  6. impossible

    Original Member

    Joined:
    Aug 9, 2004
    Messages:
    443
    Likes Received:
    0
    Sounds good. You should be almost on your way now :). At least you didn't end up posting your whole application on the forums like this guy outsourcing for the company I work for did ealier today :).
     
  7. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    Ahhhhhhh

    Well, I just typed a long reply with code and questions, but then my browser crashed. Unfortunately, I had to leave and I don't have access to my code where I am at the moment. :(

    Here's a screen shot of the current situation. My quad is still not aligned with the screen, although it does appear to be not using the world transform.

    I'll post again later when I get a chance.

    Thanks
     
  8. impossible

    Original Member

    Joined:
    Aug 9, 2004
    Messages:
    443
    Likes Received:
    0
    Make sure your w coordinate is right. It needs to be 1.0, the vertices final position will be xyz/w.
     
  9. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    I had dropped the w coordinate. I'll try putting it back in when I can get to my code.
     
  10. dima

    Original Member

    Joined:
    Feb 7, 2005
    Messages:
    345
    Likes Received:
    0
    Use transformed verts to create za screen quad, its much simpler than having to align world space to screen. With transformed geometry you just use screen space coords and everything works fine like that.
     
  11. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    I thought someone in this thread had told me to drop the w coordinate when using a custom shader... but I couldn't find it, so maybe I imagined that. I had my quad screen aligned prior to switching to a custom shader, but when I did, it stopped working... probably because the shader didn't compile.
     
  12. impossible

    Original Member

    Joined:
    Aug 9, 2004
    Messages:
    443
    Likes Received:
    0
    Oh, did you change your vertex shader declaration to be FLOAT3? If it was still FLOAT4, you'd have problems. Dima's advice doesn't help you much because you want to use a vertex shader.
     
  13. dima

    Original Member

    Joined:
    Feb 7, 2005
    Messages:
    345
    Likes Received:
    0
    If you don't mind me asking, but why use a vertex shader for a screen quad? Don't you need pixel shaders for glow effects? What exactly are you trying to do that you can't with fixed function pipeline and transformed geometry?
     
  14. impossible

    Original Member

    Joined:
    Aug 9, 2004
    Messages:
    443
    Likes Received:
    0
    In ps 2.0 you would do it all in the pixel shader, but if his target ps 1.1 then I'm pretty sure he has to set his texture coordinates outside of the pixel shader because of very limited dependent read support. He could give his vertices 4 texture coordinates (or however many samples he's taking) and use FFP also... Either way it shouldn't be that different.
     
  15. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    That is correct. I'm still having some problems... I'm about to post more.
     
  16. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    Here's a current screenshot.

    Now, it almost looks like my z-coord is swapped with x or y... but I spent a while playing around with it and couldn't get something to fit the screen.

    Here's my vertex shader
    Code:
    const char GlowShaderVS[] = "vs.1.1							\n"
    							"mov oPos, v0					\n"
    							"add oT0, v7, c0				\n"
    							"add oT1, v7, c1				\n"
    							"add oT2, v7, c2				\n"
    							"add oT3, v7, c3				\n";
    
    
    Here's my declarations:
    Code:
    DWORD ShaderDecl[] = 
    {
    	D3DVSD_STREAM(0),
    	D3DVSD_REG( D3DVSDE_POSITION, D3DVSDT_FLOAT4 ),
    	D3DVSD_REG( D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2 ),
    	D3DVSD_END()
    };
    
    #define FVF_SVERTEX ( D3DFVF_XYZRHW | D3DFVF_TEX1 )
    struct SVERTEX
        {FLOAT x, y, z, rhw; FLOAT U,V;};
    SVERTEX g_pScreenQuad[] = 
    {
    	{-1.0f, -1.0f, 0.0f,1.0f,0.0f,0.0f},
    	{ 1.0f, -1.0f, 0.0f,1.0f,1.0f,0.0f},
    	{ 1.0f,  1.0f, 0.0f,1.0f,1.0f,1.0f},
    	{-1.0f,  1.0f, 0.0f,1.0f,0.0f,1.0f}
    };
    
    LPDIRECT3DVERTEXBUFFER8 g_QuadVB;
    
    Here's where I populate my Vertex Buffer:
    Code:
    	g_pDevice->CreateVertexBuffer( sizeof(g_pScreenQuad),D3DUSAGE_WRITEONLY, FVF_SVERTEX, D3DPOOL_MANAGED, &g_QuadVB );
    	SVERTEX* pVertices;
    	g_QuadVB->Lock(0, sizeof(g_pScreenQuad), (BYTE**)&pVertices, 0 ) ;
    	memcpy( pVertices, g_pScreenQuad, sizeof(g_pScreenQuad));
    	g_QuadVB->Unlock();
    
    And this is where I call the shader:
    Code:
    	g_pDevice->SetRenderState(D3DRS_ZENABLE,FALSE);
    	g_pDevice->SetStreamSource(0,g_QuadVB,sizeof(g_QuadVB));
    	g_pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,2);
    	g_pDevice->SetRenderState(D3DRS_ZENABLE,TRUE);
    
    I'll keep playing with it, but I'm not really sure why it isn't lining up right.
     
  17. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    Oh, and by the way, I had to remove the following two lines from my vertex shader:

    Code:
    dcl_position v0
    dcl_texcoord v7
    
    I don't really understand why... and I'm not sure if that's what my problem is.
     
  18. impossible

    Original Member

    Joined:
    Aug 9, 2004
    Messages:
    443
    Likes Received:
    0
    Afaik "dcl_" is not supported in DX8 (it was introduced in DX9.) Are you calling SetVertexShader btw? I don't see it in the code you posted.
     
    #38 impossible, May 14, 2005
    Last edited: May 14, 2005
  19. mkovacic

    Original Member Indie Author

    Joined:
    Jul 28, 2004
    Messages:
    127
    Likes Received:
    0
    g_pDevice->SetStreamSource(0,g_QuadVB,sizeof(g_QuadVB));

    should be

    g_pDevice->SetStreamSource(0,g_QuadVB,sizeof(SVERTEX));

    I don't see anything else obviously wrong, I suggest asking on dxdev mailing list ( http://DISCUSS.MICROSOFT.COM/archives/DIRECTXDEV.html ), you'll get better feedback there.
     
  20. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    Sweet! This fixed the quad problem. It makes sense to me now. The only vertex I could change was the first one.

    Thanks to everyone who helped me out on this one:

    impossible, dima, wazoo, sharpfish and mkovacic,

    Thank you all very much

    Now I'm off to figure out what's wrong with my Pixel Shader.
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer