Shaders - HLSL - SampleLevel()

Started by
1 comment, last by Bokke 11 years ago

Could someone help me figure out why a float3 is being returned in the following HLSL line?


float3 v = gRandomTex.SampleLevel(gTriLinearSam, u, 0);
 

Now, gRandomTex, gTriLinearSam and u are defined as follows:


Texture1D gRandomTex;
SamplerState gTriLinearSam
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = WRAP;
    AddressV = WRAP;
}
float u = 1.0f; //Actually it is not a constant, but just for the example, I set it to 1.0f
 

Twitter: @StevenDeBo

Advertisement

It's been a while since I used HLSL properly( so far back that SM2 was the thing ) so I may be completely off here. But you're asking it for a float3, no ? Does it fail if you switch it to float4 on the return ?

Also, according to MSDN it should return in the format of the texture -- specified by DXGI_FORMAT. What format is the texture in ? ( http://msdn.microsoft.com/en-gb/library/windows/desktop/bb509699(v=vs.85).aspx )

( I'm probably way off and completely wrong. But thought I'd post on the off-chance it's helpful. )

Thanks, I should have read the msdn more closely:

The Format of the texture is indeed defined as DXGI_FORMAT_R32G32B32A32_FLOAT.

I was too much focused on the fact that it was a Texture1D and ignored to see that an element could as well have multiple dimensions...

As for the float3 vs float4: I only need a random x, y and z component for v, so no use for a float4 variable.

Twitter: @StevenDeBo

This topic is closed to new replies.

Advertisement