• Advertisement
Sign in to follow this  

Two vertexShader cannot function simultaneously

This topic is 1354 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 have stayed up for this problem,but it is unsolved.

     I load a D3DXFrame from an X file,Scan the D3DXFrame hierarchy and render the mesh if there is one.I have two vertexShader:p_vs_Skinning for the mesh-with-SkinInfo and p_vs_simple for the mesh-without-SkinInfo.There's no compile error or running-time error,two vertexShader perform perfect when running seperately.However, when they are simultaneously running,the p_vs_simple has no effect.Actually they were not literally simultaneous.they are in different parts of if-else branch.When I render mesh-without-SkinInfo through fixed pipeline ,it works well.When I bypass if branch,the vertexShader works.

     Here's part of code,boneMesh is a derived class of D3DXMeshContainer,I've omitted large part of irrelevant content.Virtually I don't think the trouble is in the code.

              if((boneMesh->pSkinInfo!=NULL))
		{

			for (int i = 0; i < boneMesh->numAttributeGroups; i++)
			{
				int mtrl=boneMesh->attributeTable[i].AttribId;
				p_Device->SetMaterial(&(boneMesh->materials[mtrl]));
				p_Device->SetTexture(texIndex,boneMesh->textures[mtrl]);
				
				p_Device->SetVertexShader(p_vs_Skinning);
				p_Device->SetPixelShader(p_ps_Simple);
				boneMesh->MeshData.pMesh->DrawSubset(mtrl);				
			}
		}
		else 
		{
			
			for (int i = 0; i < boneMesh->NumMaterials; i++)
			{
				p_Device->SetMaterial(&(boneMesh->materials[i]));
				p_Device->SetTexture(texIndex,boneMesh->textures[i]);

				p_Device->SetVertexShader(p_vs_Simple);
			        p_Device->SetPixelShader(p_ps_Simple);

				boneMesh->MeshData.pMesh->DrawSubset(i);
			}
		}

Share this post


Link to post
Share on other sites
Advertisement

It's not entirely clear what your situation is from your description.

 

However, do these remarks in the docs apply?

 

To set a fixed-function vertex shader (after having set a programmable vertex shader), call IDirect3DDevice9::SetVertexShader(NULL) to release the programmable shader, and then call IDirect3DDevice9::SetFVF with the fixed-function vertex format.

 

 

I've not used SetVertexShader so I can't speak from experience (I use effects). However, it may be that you also have to release one vertex shader before setting and using another.

Share this post


Link to post
Share on other sites

I don't use the Mesh interfaces, but otherwise the code you've posted should work (I'd move the Set*Shader calls outside of the for loops, though).  There's nothing in raw D3D to prevent it.

 

The possibility is that one or both of your shaders has failed to compile; have you run this in the debugger and checked that the shaders are non-NULL?

 

Your SetMaterial calls are useless, by the way: these relate to the fixed-pipeline lighting engine, which is switched off when using vertex shaders.

Share this post


Link to post
Share on other sites

Thanks , I've tried to do so,but didn't make any difference.

It's not entirely clear what your situation is from your description.

 

However, do these remarks in the docs apply?

 

To set a fixed-function vertex shader (after having set a programmable vertex shader), call IDirect3DDevice9::SetVertexShader(NULL) to release the programmable shader, and then call IDirect3DDevice9::SetFVF with the fixed-function vertex format.

 

 

I've not used SetVertexShader so I can't speak from experience (I use effects). However, it may be that you also have to release one vertex shader before setting and using another.

Share this post


Link to post
Share on other sites

 More complete code posted here.

Notice line 44 to 47

line 44 and 45 are for vertex shader,46 and 47 are for pipeline.pipeline works,vertex shader has no effects.

if((boneMesh->pSkinInfo!=NULL))
		{
			//Set up bone transforms
			int numBones=boneMesh->pSkinInfo->GetNumBones();
			for (int i = 0; i < numBones; i++)
			{
				D3DXMatrixMultiply(&currentBoneMatrices[i],&boneOffsetMatrices[i],pBoneMatrices[i]);
			}

			//Update the skinned mesh
			p_ct_VS_Skinning->SetMatrixArray(p_Device,h_VS_Skinning_MatrixPalette,
                                currentBoneMatrices,numBones);                               //set matrix pallete in VertexShader

			for (int i = 0; i < boneMesh->numAttributeGroups; i++)
			{
				int mtrl=boneMesh->attributeTable[i].AttribId;
				p_Device->SetMaterial(&(boneMesh->materials[mtrl]));
				p_Device->SetTexture(texIndex,boneMesh->textures[mtrl]);
				
				p_Device->SetVertexShader(p_vs_Skinning);
				p_Device->SetPixelShader(p_ps_Simple);

				boneMesh->MeshData.pMesh->DrawSubset(mtrl);
				
				p_Device->SetVertexShader(NULL);
				p_Device->SetPixelShader(NULL);
				
			}
		}
		else if(boneMesh->pSkinInfo==NULL)
		{
			D3DXMATRIX world,position;
			p_Device->GetTransform(D3DTS_WORLD,&world);
			D3DXMatrixMultiply(&position,&bone->ConbinedTransformationMatrix,&world);
			p_Device->SetTransform(D3DTS_WORLD,&position);                                                //For fixed-pipeline
			p_ct_VS_Simple->SetMatrix(p_Device,h_VS_Simple_WorldMatrix,&position);                        //For vertex shader
			
			p_Device->SetFVF(boneMesh->MeshData.pMesh->GetFVF());
			for (int i = 0; i < boneMesh->NumMaterials; i++)
			{
				p_Device->SetMaterial(&(boneMesh->materials[i]));
				p_Device->SetTexture(texIndex,boneMesh->textures[i]);

				//p_Device->SetVertexShader(p_vs_Simple);                             //render by vertex shader
			        //p_Device->SetPixelShader(p_ps_Simple);                              //render by vertex shader
				p_Device->SetVertexShader(NULL);                                      //render by fixed-pipeline
				p_Device->SetPixelShader(NULL);                                       //render by fixed-pipeline
				hr=boneMesh->MeshData.pMesh->DrawSubset(i);
			}
			p_Device->SetTransform(D3DTS_WORLD,&world);                                   //for fixed-pipeline
Edited by xxl534

Share this post


Link to post
Share on other sites

I don't use the Mesh interfaces, but otherwise the code you've posted should work (I'd move the Set*Shader calls outside of the for loops, though).  There's nothing in raw D3D to prevent it.

 

The possibility is that one or both of your shaders has failed to compile; have you run this in the debugger and checked that the shaders are non-NULL?

 

Your SetMaterial calls are useless, by the way: these relate to the fixed-pipeline lighting engine, which is switched off when using vertex shaders.

I've set breakpoints and checked ,no error in compiling and shaders are non-NULL.Both shaders work seperately.

And the SetMaterial is my habit,but it's not the key.

Share this post


Link to post
Share on other sites

Does it matter that one loop uses DrawSubset(mtrl) while the other uses DrawSubset(i)?

No,they are just indices.

Share this post


Link to post
Share on other sites

when you say the pixel shader has no effect, do you mean that nothing is rendered? have you tried pix to see what the vertices look like after the vertex shader has passed?

 

EDIT: IIRC SetFVF will not work with the shader pipeline, only the FFP. For shaders, vertices need to be bound with VertexDeclarations, which WILL work with the FFP.

 

http://msdn.microsoft.com/en-us/library/windows/desktop/bb206335%28v=vs.85%29.aspx

 

EDIT2: I was wrong, FVF vertex buffers can be used with vertex shaders.

Edited by Burnt_Fyr

Share this post


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

  • Advertisement