Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Setting sampler state

Discussion in 'Shaders' started by LeeHickey, Apr 20, 2009.

  1. LeeHickey

    LeeHickey

    Joined:
    Apr 8, 2009
    Posts:
    25
    I've probably just missed it when reading the docs but I don't seem to be able to find a way to control sampler state from within a ShaderLab shader. I can set bilinear off on a texture asset but I need to control sampler state programmatically. Is there a way to do this?
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,590
  3. LeeHickey

    LeeHickey

    Joined:
    Apr 8, 2009
    Posts:
    25
    Aha - totally mised that one, thanks. That'd set it on the texture resource globally though wouldn't it? I have a set of textures that, when rendered with certain shaders, I want bilinear on and when rendered with another set of shaders I want bilinear off, within the same frame. Coordinating rendering with a script in this way is going to be a little tricky, that's why I would have thought sampler state would be exposed to the shader language.
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,590
    No, it sets the filtering mode on a particular texture (so from a script, you have to set it on a particular texture).

    If you want to use the same texture with different filtering modes, and can't have some script executed in between, then yes, it does get tricky.

    There's no separate sampler state in OpenGL (filtering and other modes are set onto a texture), so exposing it in D3D style is not easy.
     
  5. LeeHickey

    LeeHickey

    Joined:
    Apr 8, 2009
    Posts:
    25
    Yes, when I said globally I meant on that specific texture resource but 'globally' in the sense of for any other object which uses it, not just the object whose script modified it. It's a bit of an overloaded word really :)

    I'm used to HLSL so didn't realise it wasn't available in OpenGL. Fair enough, I'll try amd work around it. Thanks for the help.
     
unityunity