Hi, I've got a vertex displacement shader which takes in a height map for terrain which works on desktop but doesn't work on webgl. Does anyone have a working vertex displacement shader for webgl? Here's the shader: Code (csharp): // Shader created with Shader Forge v1.38 // Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/ // Note: Manually altering this data may prevent you from opening it in Shader Forge /*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,cgin:,lico:1,lgpr:1,limd:0,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,hqlp:False,rprd:False,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:0,bdst:1,dpts:2,wrdp:True,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:False,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:False,atwp:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:3138,x:32719,y:32712,varname:node_3138,prsc:2|emission-8973-RGB,voffset-109-OUT;n:type:ShaderForge.SFN_Tex2d,id:8973,x:32197,y:32710,ptovrint:False,ptlb:Texture,ptin:_Texture,varname:node_8973,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:555845c57153a9549bc3093bb0addc63,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:6805,x:31617,y:32956,ptovrint:False,ptlb:Height,ptin:_Height,varname:node_6805,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:9feb21497adb72047b8f47439359390a,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Multiply,id:1189,x:31867,y:32918,varname:node_1189,prsc:2|A-1247-OUT,B-6805-R;n:type:ShaderForge.SFN_ValueProperty,id:1247,x:31617,y:32845,ptovrint:False,ptlb:Height Strength,ptin:_HeightStrength,varname:node_1247,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:4;n:type:ShaderForge.SFN_Slider,id:5781,x:31460,y:33143,ptovrint:False,ptlb:Contrast,ptin:_Contrast,varname:node_5781,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.349872,max:1;n:type:ShaderForge.SFN_OneMinus,id:7020,x:31796,y:33061,varname:node_7020,prsc:2|IN-5781-OUT;n:type:ShaderForge.SFN_RemapRangeAdvanced,id:9252,x:32031,y:33171,varname:node_9252,prsc:2|IN-1189-OUT,IMIN-5781-OUT,IMAX-7020-OUT,OMIN-3227-OUT,OMAX-1501-OUT;n:type:ShaderForge.SFN_Vector1,id:3227,x:31735,y:33283,varname:node_3227,prsc:2,v1:0;n:type:ShaderForge.SFN_Vector1,id:1501,x:31735,y:33339,varname:node_1501,prsc:2,v1:1;n:type:ShaderForge.SFN_NormalVector,id:7508,x:32011,y:32936,prsc:2,pt:False;n:type:ShaderForge.SFN_Multiply,id:5630,x:32258,y:33094,varname:node_5630,prsc:2|A-7508-OUT,B-9252-OUT;n:type:ShaderForge.SFN_Multiply,id:109,x:32438,y:33173,varname:node_109,prsc:2|A-2934-R,B-5630-OUT;n:type:ShaderForge.SFN_VertexColor,id:2934,x:32191,y:33272,varname:node_2934,prsc:2;proporder:8973-6805-1247-5781;pass:END;sub:END;*/ Shader "Shader Forge/MapSimple" { Properties { _Texture ("Texture", 2D) = "white" {} _Height ("Height", 2D) = "white" {} _HeightStrength ("Height Strength", Float ) = 4 _Contrast ("Contrast", Range(0, 1)) = 0.349872 } SubShader { Tags { "RenderType"="Opaque" } Pass { Name "FORWARD" Tags { "LightMode"="ForwardBase" } CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_FORWARDBASE #include "UnityCG.cginc" #pragma multi_compile_fwdbase_fullshadows #pragma only_renderers d3d9 d3d11 glcore gles #pragma target 3.0 uniform sampler2D _Texture; uniform float4 _Texture_ST; uniform sampler2D _Height; uniform float4 _Height_ST; uniform float _HeightStrength; uniform float _Contrast; struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float2 texcoord0 : TEXCOORD0; float4 vertexColor : COLOR; }; struct VertexOutput { float4 pos : SV_POSITION; float2 uv0 : TEXCOORD0; float3 normalDir : TEXCOORD1; float4 vertexColor : COLOR; }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.uv0 = v.texcoord0; o.vertexColor = v.vertexColor; o.normalDir = UnityObjectToWorldNormal(v.normal); float4 _Height_var = tex2Dlod(_Height,float4(TRANSFORM_TEX(o.uv0, _Height),0.0,0)); float node_3227 = 0.0; v.vertex.xyz += (o.vertexColor.r*(v.normal*(node_3227 + ( ((_HeightStrength*_Height_var.r) - _Contrast) * (1.0 - node_3227) ) / ((1.0 - _Contrast) - _Contrast)))); o.pos = UnityObjectToClipPos( v.vertex ); return o; } float4 frag(VertexOutput i) : COLOR { i.normalDir = normalize(i.normalDir); float3 normalDirection = i.normalDir; ////// Lighting: ////// Emissive: float4 _Texture_var = tex2D(_Texture,TRANSFORM_TEX(i.uv0, _Texture)); float3 emissive = _Texture_var.rgb; float3 finalColor = emissive; return fixed4(finalColor,1); } ENDCG } Pass { Name "ShadowCaster" Tags { "LightMode"="ShadowCaster" } Offset 1, 1 Cull Back CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_SHADOWCASTER #include "UnityCG.cginc" #include "Lighting.cginc" #pragma fragmentoption ARB_precision_hint_fastest #pragma multi_compile_shadowcaster #pragma only_renderers d3d9 d3d11 glcore gles #pragma target 3.0 uniform sampler2D _Height; uniform float4 _Height_ST; uniform float _HeightStrength; uniform float _Contrast; struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float2 texcoord0 : TEXCOORD0; float4 vertexColor : COLOR; }; struct VertexOutput { V2F_SHADOW_CASTER; float2 uv0 : TEXCOORD1; float3 normalDir : TEXCOORD2; float4 vertexColor : COLOR; }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.uv0 = v.texcoord0; o.vertexColor = v.vertexColor; o.normalDir = UnityObjectToWorldNormal(v.normal); float4 _Height_var = tex2Dlod(_Height,float4(TRANSFORM_TEX(o.uv0, _Height),0.0,0)); float node_3227 = 0.0; v.vertex.xyz += (o.vertexColor.r*(v.normal*(node_3227 + ( ((_HeightStrength*_Height_var.r) - _Contrast) * (1.0 - node_3227) ) / ((1.0 - _Contrast) - _Contrast)))); o.pos = UnityObjectToClipPos( v.vertex ); TRANSFER_SHADOW_CASTER(o) return o; } float4 frag(VertexOutput i) : COLOR { i.normalDir = normalize(i.normalDir); float3 normalDirection = i.normalDir; SHADOW_CASTER_FRAGMENT(i) } ENDCG } } FallBack "Diffuse" CustomEditor "ShaderForgeMaterialInspector" }
The console says that Pass 'FORWARD' has no vertex shader but as you can see above it does have a vertex shader. I suspect that something wrong is happening at compile time in unity. Console looks like this: Code (csharp): You can reduce your startup time if you configure your web server to host .unityweb files using gzip compression. UnityLoader.js:1 trying binaryen method: native-wasm UnityLoader.js:1 asynchronously preparing wasm UnityLoader.js:1 binaryen method succeeded. blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 Initialize engine version: 2017.2.0f3 (46dda1414e51) UnityLoader.js:1 Creating WebGL 2.0 context. blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 Renderer: WebKit WebGL blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 Vendor: WebKit blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 Version: OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium)) blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 GLES: 3 blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 EXT_color_buffer_float GL_EXT_color_buffer_float EXT_disjoint_timer_query_webgl2 GL_EXT_disjoint_timer_query_webgl2 EXT_texture_filter_anisotropic GL_EXT_texture_filter_anisotropic OES_texture_float_linear GL_OES_texture_float_linear WEBGL_compressed_texture_s3tc GL_WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb GL_WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info GL_WEBGL_debug_renderer_info WEBGL_debug_shaders GL_WEBGL_debug_shaders WEBGL_lose_context GL_WEBGL_lose_context blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level <OpenGL ES 3.0> ; Context handle 1 blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 WARNING: Shader blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 Unsupported: 'Shader Forge/MapSimple' - Pass 'FORWARD' has no vertex shader blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 WARNING: Shader blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 Unsupported: 'Shader Forge/MapSimple' - Pass 'SHADOWCASTER' has no vertex shader blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 WARNING: Shader blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 Unsupported: 'Shader Forge/MapSimple' - All passes removed blob:http://localhost:49962/c5fe5b65-6c47-4cba-9479-edb1239b0a8f:7561 UnloadTime: 0.690000 ms
In case anyone has the same issue the shader works if you delete this line: #pragma only_renderers d3d9 d3d11 glcore gles
Bit of a necro on my part but yeah, this does seem to solve it. I was tearing my hair out over this, I suspected it was a problem with assetbundles and the shader not being included properly but it's as you say, killing that line allows whatever substitute is in place to render the material properly. If anyone else runs into the same problem and finds this thread, now that you've found a solution, take a rest, you've earned it (Unity 2018.4 LTS).