Jump to content
  • Advertisement
Sign in to follow this  

Learning Vertex shaders

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

Im just starting to learn shaders and am alittle stuck on a shader im making for my landscape. Its ment to take 2 vertex streams and merge them together. Here i fill the buffers for(i=0;i<64;i++) for(j=0;j<64;j++) { vert[j*64+i].pos = D3DXVECTOR3((float)i,0.0f,(float)j); vert2[j*64+i].pos = 0.0f; } here is the decleration for the shader D3DVERTEXELEMENT9 decl[] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, { 1, 0, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1 }, D3DDECL_END() }; LPD3DXBUFFER pCode; device->CreateVertexDeclaration( decl, &g_pVertexDeclaration ); here i set the vertes streams device->SetStreamSource(0,Verts,0,sizeof(D3DXVECTOR3)); device->SetStreamSource(1,Verts2,0,sizeof(float)); and here is the shader (hack from ms shader) float4x4 mWorldViewProj; // World * View * Projection transformation float fTime; // Time parameter. This keeps increasing struct VS_OUTPUT { float4 Position : POSITION; // vertex position float4 Diffuse : COLOR0; // vertex diffuse color }; VS_OUTPUT Ripple( in float3 vPosition : POSITION ,in float vHeight : POSITION) { VS_OUTPUT Output; float fSin, fCos; float x = length( vPosition ) * sin( fTime ) * 15.0f; // This HLSL intrinsic computes returns both the sine and cosine of x sincos( x, fSin, fCos ); // Change the y of the vertex position based on a function of time // and transform the vertex into projection space. Output.Position = mul( float4( vPosition.x, vHeight,vPosition.z, 1.0f ), mWorldViewProj ); // Output the diffuse color as function of time and // the vertex's object space position Output.Diffuse = 0.5f - 0.5f * fCos;; // Output the diffuse color as function of time and // the vertex's object space position return Output; } the problem is that it isnt using the second source properly any ideas?

Share this post


Link to post
Share on other sites
Advertisement
The input position semantics should be POSITION0 and POSITION1.

VS_OUTPUT Ripple( in float3 vPosition : POSITION0 ,in float vHeight : POSITION1)

the number corresponds to the usage index (the last number in your declaration).

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!