Hello, I've been following this example from the Unity documentation on custom shaders: https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html And I can't seem to get shadow casting to work for URP. I've applied the following shader to both the plane and the cube shown in the photo. It seems receiving shadows works, there is just a problem with casting shadows. Any ideas on what could be missing here? Thank you! Code (CSharp): Shader "Custom/Radial_Bend" { Properties { _MainTex("Sprite Texture", 2D) = "white" {} } SubShader { Pass { Tags { "LightMode" = "UniversalForward" "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit" "IgnoreProjector" = "True" } HLSLPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile __ BEND_ON #pragma multi_compile __ BEND_OFF #include "UnityCG.cginc" #include "Lighting.cginc" #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight #include "AutoLight.cginc" float4 _MainTex_ST; sampler2D _MainTex; struct v2f { float2 uv : TEXCOORD0; SHADOW_COORDS(1) fixed3 diff : COLOR0; fixed3 ambient : COLOR1; float4 pos : SV_POSITION; }; uniform float _HORIZON = 0.0f; uniform float _ATTENUATE = 0.0f; uniform float _SPREAD = 0.0f; float4 BendEffect(float4 v) { // Put the given vertex in world space float4 t = mul(unity_ObjectToWorld, v); // Calculate z-depth float dist = max(0, abs(_HORIZON - t.z) - _SPREAD); // Apply parabola formula (-ve to bend down) t.y -= dist * dist * _ATTENUATE; // Put vertex back in object space t.xyz = mul(unity_WorldToObject, t).xyz * 1.0; return t; } v2f vert(appdata_base v) { v2f o; o.pos = UnityObjectToClipPos(BendEffect(v.vertex)); o.uv = v.texcoord; // For lighting half3 worldNormal = UnityObjectToWorldNormal(v.normal); half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz)); o.diff = nl * _LightColor0.rgb; o.ambient = ShadeSH9(half4(worldNormal, 1)); // compute shadows data TRANSFER_SHADOW(o) return o; } fixed4 frag(v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); // compute shadow attenuation (1.0 = fully lit, 0.0 = fully shadowed) fixed shadow = SHADOW_ATTENUATION(i); // darken light's illumination with shadow, keep ambient intact fixed3 lighting = i.diff * shadow + i.ambient; col.rgb *= lighting; return col; } ENDHLSL } // shadow casting support // UsePass "Legacy Shaders/VertexLit/SHADOWCASTER" UsePass "Universal Render Pipeline/Lit/ShadowCaster" } }
The samples are only intended for the built in renderer, and are not expected to work for the URP. Some of the unlit ones will, but the built in renderer and the URP shaders are structured completely differently. The "correct" solution (from Unity's point of view) is to use Shader Graph to construct your shaders for URP. There's zero official documentation on writing vertex fragment shaders for the URP, and no guarantee hand written shaders will work between versions of the URP as they can (and often do) change significantly between revisions. This is also the reason why you won't find any tutorials on how to do it written by the community, because a few people have attempted to do so and they were obsolete shortly after, or sometimes before they were finished. Because, again, the URP was changing so rapidly between revisions. Unfortunately the way this kind of world bend shader works can't be reproduced within Shader Graph as you can't modify the vertex position without also modifying how lighting affects it in Shader Graph. The easiest option for you right now might be to create a basic shader using Shader Graph that does what you need, minus the world bend, and then copy the generated shader code into a new .shader file and hand modify it to do what you need.