Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been reading a lot of different shaders and some have the preference of:

sampler depthSampler : register(s1);

Whilst others take the longer route:

texture depthMap;
sampler depthSampler = sampler_state
{
    // etc.
};

Is there any real difference between the two? Does one perform faster than the other?

share|improve this question
    
I think, that performance is the same. In the first case, settings from your application is taken. In the second case, you can set sampler (clamping etc.) on your own. –  zacharmarz Feb 16 '12 at 13:05

1 Answer 1

up vote 3 down vote accepted

Zacharmarz briefly touched on it in his comment; however, it's less about performance and more about configuration.

In the first example the sampler state is left uninitialized and works just like any other parameter (e.g. your WorldMatrix) - this would allow your game to change the sampler at runtime. Conversely your shader won't work if you don't initialize the sampler. Most often you will see this syntax in conjunction with custom SpriteBatch shaders as they would allow the SpriteBatch to provide crucial configuration.

In the second example the sampler state is 'hardcoded' into the shader. This means that once the shader is compiled it's set in stone - your game can't change it if it needs to.

Both techniques are just as viable as the other - it all depends on how you intend to use the shader. If you need the sampler configurable use the first, if you require that the sampler is always in a predictable state use the second. It is much more likely that you will be using the second method.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.