我一直在尝试用统一着色器创建一些类似效果的波形。我做到了,它在编辑器中工作正常,但是在Android设备(三星J1)上却给出了错误:
GLES20:使用了vprog纹理,但不支持
GLSL链接错误:L0100 GLSL允许每个程序精确地连接两个着色器(每种类型之一)
然后什么也没显示。
我在互联网上搜索了它,但没有发现有用的东西。
为了实现此效果,我创建了Perlin噪声图像512x512,并使用其像素值替换了顶点的y位置。
据我了解,问题出在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"
}
我如何解决它,使其可以在任何设备上使用?