HLSL code 'Texture2D' to 'sampler2D'

Hi guy,

i have a trouble with a simple HLSL code. When i use a texture object or texture param is the error:
[SM5] error X3014: ‘CustomExpression0’: cannot implicitly convert from ‘Texture2D’ to ‘sampler2D’

Can have anyone help me?

You cannot create texture objects in the custom node. You need to supply them as an input.

thx for your answer, but i don’t understand this. I have the texture object to input. Sample

You need to use a Texture Sample, not a Texture Object.

When i use a texture sample, i have 3013 error.

here the code:

Ah yes, the normal height map will only want ONE channel, so you’ll have to either use a component mask with just R or G or B selected, or just drag from the red/green or blue boes on the texture sample node.

Essentially what you’re doing right now is giving it too much information, heightmaps need to be grayscale :slight_smile: Hope this helps!

Hi TheJamsh,

this is not the problem.

I search a solution in the hlsl script to convert Tex2D to Sampler2D or CustomTexture as Sampler2D.

I believe that this custom node is not fully implemented yet. We will most likely need to wait until the next update.

Has there been any progress on this issue? I tried to look through the source to find the issue, my best guess is the error is on the custom texture side-- the generated custom hlsl function seems correct at the very least.

A solution would be much appreciated,

Thanks

yop

I get custom node working with textures but it’s a bit tricky, here is how I proceed :

  • Look at my nodes build.
  • Display the HLSL code window (in material editor).
  • search in this window the code part relative to “CustomExpression” (you will show your code updated eah time you press enter in the code box of the custom node)
  • If you connect a texturesample node to custom node, you will see in the code the texture2d name declaration and its associated SamplerState.
  • reuse this in your code, and use Texture2D instead of Sampler2D (so Sample function instead of tex2D)

code example :


float4 color = MaterialTexture2D_0.Sample(MaterialTexture2D_0Sampler, uv0);return color;

nodes :

f0436b0354061a8ba5910c39958f3fe33d2bc7b4.jpeg

PS : We really need an update for the custom node and at least a real code window to edit code.

Thanks fredakilla this is really helpful! :cool:

Absolutely. This has been a popular request for freakin’ ages…

Does this trick still work in the latest version of the Engine?

I can’t seem to get the Texture2D and SamplerState to appear in 4.4.3…

in this method the sampled texture cannot be used for vertex shader. it will throw error.
do you have any solution for the vertex shader case as well ?

Same… But the problem can be solved!

It’s identical to what fredakilla did, but replace the TextureSampleParameter2D with a TextureObject. Connecting a TextureObject to your custom node will generate a Texture2D and SamplerState parameter in your CustomExpression function.

The blueprint nodes and result can be seen below. (The code in the image is **not **the right code, use the code in the code block. See why in the edits at the bottom)
The custom node code:


return TexSample.SampleLevel(TexSampleSampler, UV, 0);

Edit: Though this has the issue that the material won’t apply to your mesh, even though the material editor preview is correct. Looking for how to solve it.
Edit2: Post updated, found the solution here: https://forums.unrealengine.com/development-discussion/rendering/1447762-error-x4532-cannot-map-expression-to-cs_5_0-instruction-set

Unfortunately, this approach doesn’t work anymore

Unfortunately we cannot link render target with dynamic resolution feeded via blueprint, because there are no such function for MaterialInstanceDynamic - SetTextureObject just SetTextureParameterValue, for example you need sample auto-generated mips using some euristics inside of your Custom node

Surely there is set texture parameter.