5
\$\begingroup\$

These lines work (compile fine):

float4 offset = HeightMap.Sample(HeightSampler, input.Texcoord);
input.Position.xyzw += float4(0, 1, 0, 0);

These do not (any use of offset together with input/output Position causes the error):

float4 offset = HeightMap.Sample(HeightSampler, input.Texcoord);
input.Position.xyzw += offset;

No matter what I try to do to use the offset values to change the positions it breaks:

float4 offset = HeightMap.Sample(HeightSampler, input.Texcoord);
matrix<float, 4, 4> offs = {
    1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    offset.x, offset.y, offset.z, 1
};

output.Position = input.Position;
output.Position = mul(output.Position, offs);

Debug output:

(32,9): error X4532: cannot map expression to vs_5_0 instruction set
(62,19): There was an error compiling expression
(49): Error compiling effect hr=S_OK (0x00000000)

Anyone have an idea why?

\$\endgroup\$
2
  • \$\begingroup\$ A guess is that it validates the syntax but leaves some validation to when actually emitting instructions. If it's optimized away due to not being used, no instructions need to be emitted and it may appear to "work". \$\endgroup\$ Aug 16, 2011 at 9:00
  • \$\begingroup\$ Yeah that was my thought as well. Compiler probably just removes the items that end up not affecting the final output altogether. What a smart compiler ;) \$\endgroup\$
    – mikeschuld
    Aug 17, 2011 at 19:39

1 Answer 1

11
\$\begingroup\$

The problem is that you can't use a simple Sample() call in the vertex shader as it doesn't know what mipmap level to sample from, so the data coming back can't really be a float 4 and the call just doesn't really make sense. In the pixel shader, you need to use:

float4 offset = HeightMap.SampleLevel(HeightSampler, input.Texcoord, 0);

Changing to that worked perfectly.

http://www.gamedev.net/topic/604632-texture2d-sample-in-hlsl/

\$\endgroup\$
1
  • \$\begingroup\$ You star, thank you for coming back to share the solution \$\endgroup\$
    – Baggers
    Dec 3, 2019 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .