Sign in to follow this  
korvax

How to structure Sampler States within the system

Recommended Posts

Hi,

this is more a question regarding architecture or how structure I should structure the my system. In a more real production render system, is it common to use multiple samplers states at the same time or is it just the same one thats being used on multiple times.

 

As its now, I have a Rendeble3D Class that has a Material. Material can have both a Texture Class (ShaderView) and a Shader Class.

As of now i have some different shaders (all of this is test and for my learning) and they can have a multi sampler states bound to them.

So should I structure it so that each Shader Class has one/multiple sampler state or should sampler state be a more global setting in the system.  With the second global option it will be hard to specify which sampler state the each shader should be using, not sure if thats a common problem?

 

All thoughts and feedback or real life examples is much appreciated.

Share this post


Link to post
Share on other sites

What langauge are you using as in C++ having that global sampler state and having either a reference or a pointer to it is simple. I can see this being a bit more difficult in other languages but even there you can come up with constructs of handles or ids to certain things to fix the global handle.

 

How you structure your rendering is up to you but it is a good idea to split rendering off from gameplay logic, once you do that the global states start to make more sense.

Share this post


Link to post
Share on other sites

What langauge are you using as in C++ having that global sampler state and having either a reference or a pointer to it is simple. I can see this being a bit more difficult in other languages but even there you can come up with constructs of handles or ids to certain things to fix the global handle.

 

How you structure your rendering is up to you but it is a good idea to split rendering off from gameplay logic, once you do that the global states start to make more sense.

Hi, im using C++, I have no problem implementing the different solutions, but this is more a question of what would be the more logical way doing it. I don't really have any experiencing from render system, so this is me learning :)

Share this post


Link to post
Share on other sites


In a more real production render system, is it common to use multiple samplers states at the same time or is it just the same one thats being used on multiple times.
Yes, there are cases where you will want to be using more than one sampler state, or just one, but different ones for different effects.

One shader might just need a point sampler, another might need just a linear sampler, another might need both.

 

You might have one "common" sampler-state, that's used for most textures in the game.

E.g. all of your standard textures (diffuse/normal/spec/etc) on 3D objects could share a common sampler state. You can then hook this up to the option screen to choose either linear sampling, or 2x/4x/8x/16x anisotropic sampling.

Share this post


Link to post
Share on other sites

Hi, 


Yes, there are cases where you will want to be using more than one sampler state, or just one, but different ones for different effects.
One shader might just need a point sampler, another might need just a linear sampler, another might need both.

 

So what sampler state that should be used is normally controlled by the shader,  and not the texture except of the what-kind-of-sampling-all-textures-should-have sample state?


 

Share this post


Link to post
Share on other sites


So what sampler state that should be used is normally controlled by the shader, and not the texture except of the what-kind-of-sampling-all-textures-should-have sample state?

 

Yes, a shader/effect should logically decide what type of sampler it expects. It might seem to be useful to delegate this to the texture instead, but when you think about it, it doesn't make sense. Aside from program-wise settings like the multisample-level, the effect will always somehow expect a certain sampler setting - for example, one effect might want to sample a texture with wrap mode set to clamp to avoid artifacts at the edges, therefore all textures passed to the effect must be sampled with clamp, and therefore the only logical place to put the sampler state is the effect. 

Share this post


Link to post
Share on other sites

 


So what sampler state that should be used is normally controlled by the shader, and not the texture except of the what-kind-of-sampling-all-textures-should-have sample state?

 

Yes, a shader/effect should logically decide what type of sampler it expects. It might seem to be useful to delegate this to the texture instead, but when you think about it, it doesn't make sense. Aside from program-wise settings like the multisample-level, the effect will always somehow expect a certain sampler setting - for example, one effect might want to sample a texture with wrap mode set to clamp to avoid artifacts at the edges, therefore all textures passed to the effect must be sampled with clamp, and therefore the only logical place to put the sampler state is the effect. 

 

Excellent, now I know how I should implement it.

 

thx all for you help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this