0

I have been trying to create some waves like effect with unity shader. I did it and it works fine in editor, but on Android device(Samsung J1) it gives error:
GLES20: vprog textures are used, but not supported
GLSL link error: L0100 GLSL allows exactly two attached shaders (one of each type) per program

then it shows nothing.
I searched internet about it, but didn't find anything useful.

In order to implement this effect I created perlin noise image 512x512 and used it's pixel values to displace y position of vertices.
From my understanding, problem is coming from the tex2Dlod.

Shader "Custom/Wave"
{
    Properties
    {
        _Color("Color",COLOR) = (0.5,0.5,0.5,1.0)
        _MainTex("Base (RGB)", 2D) = "white" {}
        _Noise("Noise", 2D) = "white"{}
        _Curvature("Curvature", Float) = 0.01
        _ScrollXSpeed("X", Range(0,10)) = 2
        _ScrollYSpeed("Y", Range(0,10)) = 3
        _WaveIntensity("Intensity", Range(0,20)) = 5
    }

        SubShader
        {
            Tags { "RenderType" = "Opaque" }
            LOD 150
            CGPROGRAM
            #pragma surface surf Lambert vertex:vert addshadow
            #pragma glsl
            #pragma target 3.0
            sampler2D _MainTex;
            sampler2D _Noise;

            fixed4 _Color;

            float _Curvature;
            fixed _ScrollXSpeed;
            fixed _ScrollYSpeed;
            fixed _WaveIntensity;

            struct Input
            {
                float2 uv_MainTex;
            };


            void vert(inout appdata_full v) {
                // Apply scroll
                half2 texcoord = v.texcoord.xy;
                texcoord.x += _Time.x * _ScrollXSpeed;
                texcoord.y += _Time.x * _ScrollYSpeed;
                // Get value of perlin noise
                float waveHeight = tex2Dlod(_Noise, float4(texcoord,0,0)).r * _WaveIntensity;

                // Get world position of vertex
                float4 worldSpace = mul(unity_ObjectToWorld, v.vertex);
                // Get distance relative to camera
                worldSpace.xyz -= _WorldSpaceCameraPos.xyz;
                // Square distance and apply curvature with perlin noise
                worldSpace = float4(0.0f, (worldSpace.z * worldSpace.z) * -_Curvature + waveHeight, 0.0f, 0.0f);
                // Assign position to vertex
                v.vertex += mul(unity_WorldToObject, worldSpace);
            }

            void surf(Input IN, inout SurfaceOutput o)
            {
                fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
                o.Albedo = _Color.xyz;
                o.Alpha = c.a;
            }
            ENDCG
        }
        Fallback "Mobile/VertexLit"
}


How can I fix it so it will work on any device?

Raguel
  • 595
  • 8
  • 25
  • *vprog textures* refers to the fact that you are trying to read from a texture in a vertex shader, which is not supported on all devices in OpenGL ES 2.0 (see https://stackoverflow.com/questions/21526088/opengl-es-2-0-vertex-shader-texture-reads-not-possible-from-fbo) – UnholySheep Apr 27 '19 at 10:41
  • @UnholySheep so how to workaround it? – Raguel Apr 27 '19 at 10:46
  • I'm not sure there is any easy workaround - probably the easiest fix would be to bump up the minimum required version to OpenGL ES 3.0 and not support 2.0 – UnholySheep Apr 27 '19 at 10:57
  • @UnholySheep well I have `#pragma target 3.0` and `#pragma glsl` is it not enough? Right now I am thinking of implementing it with C#, but not sure will performance decrease drastically. – Raguel Apr 27 '19 at 11:05
  • Unity's `#pragma target` correspond to DirectX shader models, not OpenGL - as you can see here https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html `#pragma target 3.0` will attempt to compile for OpenGLES 2.0 though it may not be fully supported – UnholySheep Apr 27 '19 at 11:14

0 Answers0