1
votes

I am new to shaders and HLSL, I hope I'm not doing anything seriously incorrect. I am trying to blend two textures in HLSL. I've got both of my textures and samplers set up:

Texture2D<float4> First : register(t0);
Texture2D<float4> Second : register(t1);
uniform sampler FirstSampler : register(s0);
uniform sampler SecondSampler : register(s1);

In my pixel shader, I am sampling my textures:

float4 firstSample = First.Sample(FirstSampler, coords);
float4 secondSample = Second.Sample(SecondSampler, coords);

Now, at this point, if I directly return firstSample or secondSample, I get correct results. However, I'm trying to interpolate between my textures. I tried:

float4 returnValue = lerp(firstSample, secondSample, 0.5);

But what I'm getting is an interpolation between pure black and my second texture. If I switch their places, I'm getting the same result. If I set the weight to be 0.0, I get pure black etc. meaning that there is something wrong about the firstSample. I've also tried to manually interpolate between them using pure math component-wise, instead of lerp, but it also yields the same result. Most weird thing is that, when I directly return my firstSample or return some value without interacting with the other sample (e.g. return float4(firstSample.b, firstSample.g, firstSample.r, 1); for channel swapping), I get a working result, but whenever I try to use my texture with any other sample, my texture sample becomes effectively invalid (black). What could be the reason? I am very new to shaders to it's probably something I'm doing obviously wrong, but I couldn't find out what it is.

1

1 Answers

0
votes

The results you are seeing may be due to a compiler bug. Ensure that you are using a recent version of the HLSL compiler, either Version 46 from the Windows SDK, or Version 43 from the June 2010 DirectX SDK.