Search Unity

Vertex texture fetching in scriptable pipeline?

Discussion in 'Shaders' started by C-Gabriel, Oct 17, 2019.

  1. C-Gabriel

    C-Gabriel

    Joined:
    Jan 27, 2016
    Posts:
    119
    What is the proper way of doing vertex texture fetching with the scriptable pipeline? Is it the same as it used to? tex2Dlod() + #pragma target 3.0 . I'm asking because I've noticed the other shaders use some macros TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex); + SAMPLE_TEXTURE2D() instead of the old way using tex2D()
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    The SRPs are trying to move away from the Direct3D 9 style HLSL (tex2D()) in favor of directly calling the Direct3D 11 style HLSL (texture.Sample()) or other API equivalents, switching between the native functions via the SAMPLE_TEXTURE2D() macros. The old style will still work for now, but it's possible they'll stop working in the future, so I'd suggest getting used to using the new macros.

    For tex2Dlod you want SAMPLE_TEXTURE2D_LOD.
    https://github.com/Unity-Technologi...r-pipelines.core/ShaderLibrary/API/D3D11.hlsl

    If you want to see a file that has the native functions in a form you're more used to, the GLES 2.0 file still uses D3D9 HLSL (since Unity converts Direct3D HLSL to GLES GLSL behind the scenes, it's easier to keep everything user facing in HLSL).
    https://github.com/Unity-Technologi...r-pipelines.core/ShaderLibrary/API/GLES2.hlsl
     
    C-Gabriel likes this.
  3. C-Gabriel

    C-Gabriel

    Joined:
    Jan 27, 2016
    Posts:
    119
    Thanks for the info and links bgolus. Very useful!