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?

• 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". – Lars Viklund Aug 16 '11 at 9:00
• 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 ;) – mikeschuld Aug 17 '11 at 19:39

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