Jump to content
  • Advertisement
Sign in to follow this  
akira32

what is the meaning of Sampler[0]

This topic is 3815 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 somebody tell me what is the meaning of Sampler[0]? Where is the place of using Sampler[0]?
texture ShadowMap1;
sampler ShadowMapSamp1 = sampler_state
{
    Texture = <ShadowMap1>;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = NONE;

    AddressU = Clamp;
    AddressV = Clamp;
};

technique TShader
{
    pass P0
    {
        VertexShader = compile vs_1_1 VSCreateShadowMap();
        PixelShader = compile ps_2_0 PSCreateShadowMap();
    }
    
    pass P1
    {
	Sampler[0] = (ShadowMapSamp1);
        VertexShader = compile vs_1_1 VSScene();
        PixelShader  = compile ps_2_0 PSScene();
    }
}

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure I follow your question - there is no Sampler[0] in the code you've posted.

The FX framework detaches the samplers used by a shader and the actual slots configurable on the pipeline. Compilation and optimization might well move the slots around therefore you tend to write your code without reference to specific sampler indices.

How is this causing you a problem? What are you trying to do?

Cheers,
Jack

Share this post


Link to post
Share on other sites
When using a pixel shader, let the HLSL compiler automatically assign the samplers.

When using the fixed pipeline with FX files, you can use that syntax to indicate which sampler settings and texture (if the sampler is bound to a texture) to use on each texture stage. I suppose you'd use that syntax when writing asm pixel shaders too.

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
I'm not sure I follow your question - there is no Sampler[0] in the code you've posted.

The FX framework detaches the samplers used by a shader and the actual slots configurable on the pipeline. Compilation and optimization might well move the slots around therefore you tend to write your code without reference to specific sampler indices.

How is this causing you a problem? What are you trying to do?

Cheers,
Jack


Sampler[0] = (ShadowMapSamp1);<==Sampler[0] is here!
The shader code has no problem. I just try to understand the line of "Sampler[0] = (ShadowMapSamp1);".


Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
When using a pixel shader, let the HLSL compiler automatically assign the samplers.

When using the fixed pipeline with FX files, you can use that syntax to indicate which sampler settings and texture (if the sampler is bound to a texture) to use on each texture stage. I suppose you'd use that syntax when writing asm pixel shaders too.

Hi Namethatnobodyelsetook! My problem is that if I do not add the line of "Sampler[0] = (ShadowMapSamp1);", there is no any problem in the period of running. My confusion is at the variable of Sampler[0],the Sampler[0] means what? Is Sampler[0] only a sampler for texture ShadowMap1? What is the variable type of Sampler[0]?

Share this post


Link to post
Share on other sites
Typically your HLSL file has something this:

texture diffuseTexture : Diffuse
<
string ResourceName = "default_color.dds";
>;

sampler TextureSampler = sampler_state
{
texture = <diffuseTexture>;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};


This sampler structure contains all the details of how to read the texture. If your HLSL code samples a texture (tex2D(TextureSampler, IN.coord)) the HLSL compiler will automatically realize that sampler[0] = TextureSampler. If you refer to multiple textures, HLSL might assign the samplers in a different order than you're expecting, which is why you shouldn't specify the samplers yourself.

If your FX file uses the fixed pipeline or asm shaders, HLSL has no information about which samplers you intend to read from. You can assign each state individually, or just refer to the sampler structure. If you move textures around from stage to stage when editing your FX file, you only need to change the sampler[n] number rather than the stage index for each state.

sampler[n] = <TextureSampler> is the same as
texture[n] = <diffuseTexture>;
AddressU[n] = CLAMP;
AddressV[n] = CLAMP;
AddressW[n] = CLAMP;
MIPFILTER[n] = LINEAR;
MINFILTER[n] = LINEAR;
MAGFILTER[n] = LINEAR;

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!