• Advertisement
Sign in to follow this  

Shaders - HLSL - SampleLevel()

This topic is 1737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
 

 

 

 

 

Share this post


Link to post
Share on other sites
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. )

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement