Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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,770
  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,770
    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.