Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Two vertexShader cannot function simultaneously


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 xxl534   Members   -  Reputation: 102

Like
0Likes
Like

Posted 18 April 2014 - 08:15 PM

     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);
			}
		}


Sponsor:

#2 Buckeye   GDNet+   -  Reputation: 9729

Like
0Likes
Like

Posted 18 April 2014 - 08:56 PM

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.


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


#3 mhagain   Crossbones+   -  Reputation: 9491

Like
0Likes
Like

Posted 19 April 2014 - 02:46 AM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 Hodgman   Moderators   -  Reputation: 38849

Like
0Likes
Like

Posted 19 April 2014 - 04:00 AM

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

#5 ankhd   Members   -  Reputation: 1653

Like
0Likes
Like

Posted 19 April 2014 - 07:02 AM

do you update the meshes frame hierarchy



#6 xxl534   Members   -  Reputation: 102

Like
0Likes
Like

Posted 19 April 2014 - 11:46 AM

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.



#7 xxl534   Members   -  Reputation: 102

Like
0Likes
Like

Posted 19 April 2014 - 12:02 PM

 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, 19 April 2014 - 12:10 PM.


#8 xxl534   Members   -  Reputation: 102

Like
0Likes
Like

Posted 19 April 2014 - 12:10 PM

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.



#9 xxl534   Members   -  Reputation: 102

Like
0Likes
Like

Posted 19 April 2014 - 12:11 PM

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

No,they are just indices.



#10 xxl534   Members   -  Reputation: 102

Like
0Likes
Like

Posted 19 April 2014 - 12:12 PM

do you update the meshes frame hierarchy

Yes.



#11 Burnt_Fyr   Members   -  Reputation: 1385

Like
1Likes
Like

Posted 09 May 2014 - 09:58 AM

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, 10 May 2014 - 09:22 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS