Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
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

1 Answer 1

up vote 5 down vote accepted

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/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.