Issue while trying to sample a texture in a vertex shader

Started by
2 comments, last by Samith 10 years, 4 months ago

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 ?

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

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.

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

This topic is closed to new replies.

Advertisement