Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sampler questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 KaiserJohan   Members   -  Reputation: 1158

Like
0Likes
Like

Posted 07 August 2014 - 01:38 PM

I got a few questions regarding samplers objects in directx 11.

 

I have the following kind of textures that needs to be sampled:

  • 3D model texture2d (diffuse, normal textures)
  • GBuffer texture2d (position, diffuse, normals)
  • Depth texture2d
  • Depth textureCube

This is how I create my (so far only) sampler:

D3D11_SAMPLER_DESC samplerDesc;
ZeroMemory(&samplerDesc, sizeof(D3D11_SAMPLER_DESC));
samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.MaxAnisotropy = anisotropic;			// typically 16
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
DXCALL(mDevice->CreateSamplerState(&samplerDesc, &mTextureSampler));

1. Up untill now, I have sampled the 3d model textures AND GBuffer textures using the same sampler, even though the 3d model textures are mipmapped and the gbuffers are not - and it works, not even any dxgi warnings. How can this be? Shouldnt the gbuffer textures be wrong if they are not mipmapped, yet sampled by a mipmap sampler?

 

2. Which leads me to the following question, if the first two can be sampled using the same sampler, can I also use it for depth 2d and cubemap textures?


Edited by KaiserJohan, 07 August 2014 - 01:39 PM.


Sponsor:

#2 MJP   Moderators   -  Reputation: 11372

Like
6Likes
Like

Posted 07 August 2014 - 03:00 PM

  1. It is completely valid for a texture to only have 1 mip level, and still get sampled with mipmapping enabled. It may not be as efficient as it could if you used a different sampler state, but it's still valid.
  2. Sure, you can re-use the same sampler for those cases if you just want to sample them with filtering.

For things like your G-Buffer, you typically don't want to use a sampler at all. Usually you don't want any filtering at all, and you want to sample using a pixel coordinate instead of [0, 1] texture coordinates. This can be easily done using the Load() function, or by using the array operator []. Here's an example:

Texture2D GBufferAlbedo;
 
float4 PSMain(in float4 ScreenPos : SV_Position) : SV_Target0
{
    float3 albedo = GBufferAlbedo[uint2(ScreenPos.xy)].xyz;
 
    // ...do lighting stuff
}

Edited by MJP, 07 August 2014 - 03:00 PM.


#3 KaiserJohan   Members   -  Reputation: 1158

Like
0Likes
Like

Posted 08 August 2014 - 03:40 PM

Interesting. Is there any performance penalty to sample for example a textureCube (for shadowmapping) with no mipmaps with the sampler I posted? Does a sampler with more mipmap filtering incur any extra operations no-mipmap textures?

 

ALSO - you cast the screenPos.xy into uint2. Is this because of precision issues, or why is it?


Edited by KaiserJohan, 08 August 2014 - 03:46 PM.


#4 MJP   Moderators   -  Reputation: 11372

Like
0Likes
Like

Posted 09 August 2014 - 06:45 PM


Interesting. Is there any performance penalty to sample for example a textureCube (for shadowmapping) with no mipmaps with the sampler I posted? Does a sampler with more mipmap filtering incur any extra operations no-mipmap textures?

 

 

It depends on the hardware and driver, so I can't say for sure. It's also not something I've tested personally. However using anisotropic filtering is definitely going to add a performance cost.
 

Since it's a shadow map, you should consider making a new sampler that uses D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR or one of the similar variants. If you do this, then you can use SampleCmp in your shader to get hardware PCF.

 

 

 


ALSO - you cast the screenPos.xy into uint2. Is this because of precision issues, or why is it?


The Texture2D array operator takes a uint2 as a parameter, so I use an explicit cast to prevent warnings.


Edited by MJP, 09 August 2014 - 06:46 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS