Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

SAMPLE_TEXTURE2D_LOD cannot map expression to vs_5_0 instruction set (on gles)

Discussion in 'Graphics Experimental Previews' started by studentutu, Aug 20, 2019.

  1. studentutu

    studentutu

    Joined:
    Oct 22, 2017
    Posts:
    121
    Please Help!
    LWRP 6.9.1, ShaderGraph 6.9.1, Core RP Library 6.9.1, Unity 2019.2.0f1
    I'm trying to build on the old Android device (GLES 2) and I cannot build the build - there is always the same error inside the shader :
    'Custom/WaterLWRPShader': cannot map expression to vs_5_0 instruction set at line 375 (on gles)

    The thing is - it is a simple line of code :
    (Generated by the Shadergraph itself, nothing is modifyed! )
    line 375 : vdi.NoiseNormal = SAMPLE_TEXTURE2D_LOD(_NormalMapCustom1, sampler_NormalMapCustom1, _NewTilingUV_OUT, 0);

    // Vertex shader
    GraphVertexOutput vert (GraphVertexInput v)
    {
    GraphVertexOutput o = (GraphVertexOutput)0;
    UNITY_SETUP_INSTANCE_ID(v);
    UNITY_TRANSFER_INSTANCE_ID(v, o);
    // UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);

    // Vertex transformations performed by graph
    float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex).xyz;
    float3 WorldSpaceViewDirection = _WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz;
    float3 WorldSpaceNormal = normalize(mul(v.normal,(float3x3)UNITY_MATRIX_I_M));
    float3 WorldSpaceTangent = normalize(mul((float3x3)UNITY_MATRIX_M,v.tangent.xyz));
    float3 WorldSpaceBiTangent = cross(WorldSpaceNormal, WorldSpaceTangent.xyz) * v.tangent.w;
    float4 uv0 = v.texcoord0;
    // float4 uv1 = v.texcoord1;

    VertexDescriptionInputs vdi = (VertexDescriptionInputs)0;

    // Vertex description inputs defined by graph
    vdi.WorldSpacePosition = WorldSpacePosition;
    vdi.TimeParameters = _TimeParameters.xyz;

    // TIling And Offset
    float2 _NewTilingUV_OUT;
    Unity_TilingAndOffset_half(uv0.xy, half2(_TilingCustom, _TilingCustom), half2 (0, 0), _NewTilingUV_OUT);
    vdi.NoiseNormal = SAMPLE_TEXTURE2D_LOD(_NormalMapCustom1, sampler_NormalMapCustom1, _NewTilingUV_OUT, 0);

    // half2 _Rotated_UVS_Out;
    // Unity_Rotate_Degrees_half(_NewTilingUV_OUT, half2 (0.5, 0.5), _RotationCustom, _Rotated_UVS_Out);
    // vdi.NoiseNormalFlipped = SAMPLE_TEXTURE2D_LOD(_NOrmalMapCustomFlipped1, sampler_NOrmalMapCustomFlipped1, _Rotated_UVS_Out, 0);


    // Done Displaycment
    VertexDescription vd = PopulateVertexData(vdi);
    v.vertex.xyz = vd.Position;

    // Vertex shader outputs defined by graph
    o.WorldSpacePosition = WorldSpacePosition;
    o.WorldSpaceNormal = WorldSpaceNormal;
    o.WorldSpaceTangent = WorldSpaceTangent;
    o.WorldSpaceBiTangent = WorldSpaceBiTangent;
    o.WorldSpaceViewDirection = WorldSpaceViewDirection;
    o.uv0 = uv0;

    float3 lwWNormal = TransformObjectToWorldNormal(v.normal);

    VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);

    // We either sample GI from lightmap or SH.
    // Lightmap UV and vertex SH coefficients use the same interpolator ("float2 lightmapUV" for lightmap or "half3 vertexSH" for SH)
    // see DECLARE_LIGHTMAP_OR_SH macro.
    // The following funcions initialize the correct variable with correct data
    OUTPUT_LIGHTMAP_UV(v.texcoord1, unity_LightmapST, o.lightmapUV);
    OUTPUT_SH(lwWNormal, o.vertexSH);

    half3 vertexLight = VertexLighting(vertexInput.positionWS, lwWNormal);
    half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
    o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
    o.clipPos = vertexInput.positionCS;

    #ifdef _MAIN_LIGHT_SHADOWS
    o.shadowCoord = GetShadowCoord(vertexInput);
    #endif
    return o;
    }

    // Fragment shader
    half4 frag (GraphVertexOutput IN ) : SV_Target
    {
    UNITY_SETUP_INSTANCE_ID(IN);
    // UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);

    // Pixel transformations performed by graph
    float3 WorldSpacePosition = IN.WorldSpacePosition;
    float3 WorldSpaceNormal = IN.WorldSpaceNormal;
    float3 WorldSpaceTangent = IN.WorldSpaceTangent;
    float3 WorldSpaceBiTangent = IN.WorldSpaceBiTangent;
    float3 WorldSpaceViewDirection = IN.WorldSpaceViewDirection;
    float4 uv0 = IN.uv0;

    SurfaceDescriptionInputs surfaceInput = (SurfaceDescriptionInputs)0;

    // TIling And Offset
    float2 _NewTilingUV_OUT;
    Unity_TilingAndOffset_half(uv0.xy, half2(_TilingCustom, _TilingCustom), half2 (0, 0), _NewTilingUV_OUT);
    surfaceInput.NoiseNormal = SAMPLE_TEXTURE2D(_NormalMapCustom1, sampler_NormalMapCustom1, _NewTilingUV_OUT);

    half2 _Rotated_UVS_Out;
    Unity_Rotate_Degrees_half(_NewTilingUV_OUT, half2 (0.5, 0.5), _RotationCustom, _Rotated_UVS_Out);
    surfaceInput.NoiseNormalFlipped = SAMPLE_TEXTURE2D(_NOrmalMapCustomFlipped1, sampler_NOrmalMapCustomFlipped1, _Rotated_UVS_Out);


    // Surface description inputs defined by graph
    surfaceInput.WorldSpaceViewDirection = WorldSpaceViewDirection;
    surfaceInput.WorldSpacePosition = WorldSpacePosition;
    surfaceInput.TimeParameters = _TimeParameters.xyz;

    SurfaceDescription surf = PopulateSurfaceData(surfaceInput);

    float3 Albedo = float3(0.5, 0.5, 0.5);
    float3 Specular = float3(0, 0, 0);
    float Metallic = 1;
    float3 Normal = surf.Normal;
    float3 Emission = 0;
    float Smoothness = 0.5;
    float Occlusion = 1;
    float Alpha = 1;
    float AlphaClipThreshold = 0;

    // Surface description remap performed by graph
    Albedo = surf.Albedo;
    Emission = surf.Emission;
    Specular = surf.Specular;
    Smoothness = surf.Smoothness;
    Occlusion = surf.Occlusion;
    Alpha = surf.Alpha;
    AlphaClipThreshold = surf.AlphaClipThreshold;

    InputData inputData = (InputData)0;
    inputData.positionWS = WorldSpacePosition;

    // using Normal Maps!
    #ifdef _NORMALMAP
    inputData.normalWS = normalize(TransformTangentToWorld(Normal, half3x3(WorldSpaceTangent, WorldSpaceBiTangent, WorldSpaceNormal)));
    #else
    inputData.normalWS = WorldSpaceNormal;
    #endif


    inputData.viewDirectionWS = WorldSpaceViewDirection;

    inputData.shadowCoord = IN.shadowCoord;

    inputData.fogCoord = IN.fogFactorAndVertexLight.x;
    inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
    // inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.vertexSH, inputData.normalWS);

    half4 color = LightweightFragmentPBR(
    inputData,
    Albedo,
    Metallic,
    Specular,
    Smoothness,
    Occlusion,
    Emission,
    Alpha);

    // Computes fog factor per-vertex
    //color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x);

    return color;
    }

    For newer devices - it builds successfully and everything works as it should.
    Please, Help!
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Use code snippets for big code paste