Sign in to follow this  
kapru

Learning Vertex shaders

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
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

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