Jump to content
  • Advertisement
Sign in to follow this  
Adaline

Issue while trying to sample a texture in a vertex shader

This topic is 2139 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 this vertex shader:

Texture2D matrixPalettes;

SamplerState matrixPaletteSamplerState
{
    AddressU=CLAMP;
    AddressV=CLAMP;
    Filter=MIN_MAG_MIP_POINT;
};

row_major matrix computeBoneTransformInstanced(in uint instanceIndex,in float4 weights,in uint4 boneIds)
{
	row_major matrix boneTransform=matrix(0.0f,0.0f,0.0f,0.0f,
										  0.0f,0.0f,0.0f,0.0f,
										  0.0f,0.0f,0.0f,0.0f,
										  0.0f,0.0f,0.0f,0.0f);
	row_major matrix transform;

	[unroll (NUM_INFLUENCES)]
	for (int i=0;i<NUM_INFLUENCES;i++)
	{
		[unroll (4)]
		for (int j=0;j<4;j++)
			transform[j]=matrixPalettes.Sample(matrixPaletteSamplerState,float2(0.0f,0.0f),uint2(4*boneIds[i]+j,instanceIndex));
		
		boneTransform+=weights[i]*transform;
	}

	return boneTransform;
}

PS_INPUT_DS_GB VS_DS_GB_SKINNED(VS_INPUT_SKINNED_INST input)
{
	PS_INPUT_DS_GB output;
	row_major matrix boneTransform=computeBoneTransformInstanced(input.csmMaskInstanceId.y,input.weights,input.ids);
	row_major matrix W=mul(boneTransform,input.vWorldMatrix);
	row_major matrix WVP=mul(W,g_mViewProjection);

//...
	
	return output;
}

It's supposed to get the matrix plalettes from a texture for instanced skinning rendering.

But I get this error : error X4532 : cannot map expression to vs_4_0 instruction set, for the line :

transform[j]=matrixPalettes.Sample(matrixPaletteSamplerState,float2(0.0f,0.0f),uint2(4*boneIds[i]+j,instanceIndex));

What's wrong here ? Is it legit to sample a texture in a vertex shader ?

Share this post


Link to post
Share on other sites
Advertisement

Let me refer you to this old thread which answers your question.

 

You can't use Sample in a vertex shader because a vertex shader can't come up with a texture coordinate derivative to use to determine the mip level. So you have to use SampleLevel with an explicit mip level, or use Load as MJP suggests in the the thread I linked to sample from texel indices (which it appears you want to do).

Share this post


Link to post
Share on other sites

Let me refer you to this old thread which answers your question.

 

You can't use Sample in a vertex shader because a vertex shader can't come up with a texture coordinate derivative to use to determine the mip level. So you have to use SampleLevel with an explicit mip level, or use Load as MJP suggests in the the thread I linked to sample from texel indices (which it appears you want to do).

Thank you

 

I replaced this line with :

transform[j]=matrixPalettes.Load(uint3(4*boneIds[i]+j,instanceIndex,0));

and it compiled. 

Share this post


Link to post
Share on other sites

 

Let me refer you to this old thread which answers your question.

 

You can't use Sample in a vertex shader because a vertex shader can't come up with a texture coordinate derivative to use to determine the mip level. So you have to use SampleLevel with an explicit mip level, or use Load as MJP suggests in the the thread I linked to sample from texel indices (which it appears you want to do).

Thank you

 

I replaced this line with :

transform[j]=matrixPalettes.Load(uint3(4*boneIds[i]+j,instanceIndex,0));

and it compiled. 

 

 

Make sure you replace the texture declaration, too (if you haven't already):

Texture2D<float4> matrixPalettes;  // must specify that this is a float4 texture to get the correct return value from Load

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!