Sampling a texture in a VertexShader not supported ?

Using a Tex2D(…) call in a VertexShader appears to be unsupported by the current Shader Compiler ?
error X4532: cannot map expression to vertex shader instruction set

Is there another way to sample a texture from within a VertexShader ?

On a related note, I tried compiling the shader using a MonoGame branch with ShaderConductor but then I get an error about the Tex2D intrinsic is deprecated although I can’t find what it’s been replaced with.
Does anyone know how I would re-write the Tex2D call in the VertexShader to work with ShaderConductor ?

Definitely supported, however sampler in Vertex Shader can’t decide which minmap to use (as this is pre rasterization), hence it need to be specified, for example as Texture.SampleLevel(SamplerState, uvCoords, 0)

1 Like

Thank you, will give this a go.

ops, I don’t know how it happened but i forget “Level” in “Sample” sorry, check edit for correction.

No hassles, thanks for fixing it.

However… I’ve run into new (unrelated) issues that I think I’ll open a different ticket for.

But in short, my project was a DesktopGL project, but it appears the shader compiler doesn’t support that syntax for OpenGL. So I created a new DirectX project and your sample code compiles fine.

  • float4 data = Texture0.SampleLevel(TextureSampler0, float2(_x, _y), 0);

However, at runtime I get the below when trying to load the effect in the DirectX project.
‘This MGFX effect was built for a different platform!’

MGCB seems to be passing the correct platform switch (/platform:Windows), so not sure what’s going on

I would try to hard specify Windows platform in your mgcb project

You said that you were using the ShaderConductor fork. Texture.SampleLevel() should work fine there, both in DX and GL.

Thanks, will try that.