#.shader file coding. foliage / windshader. Add shadows.
1 messages · Page 1 of 1 (latest)
Especially for lit shaders it's recommended to instead use Shader Graphs in URP as it can handle lighting/shadows for you - as well as SRP batcher support and define other passes you'd need to properly support other URP features (e.g. DepthOnly/DepthNormalsOnly passes for the camera depth and normals textures, which may be required for other shaders, SSAO, etc)
But if you want to handle it in code :
-
For casting shadows, you need to add a Shadowcaster Pass. Is basically a duplicate of the pass with
Tags { "LightMode" = "Shadowcaster" }. Fragment can justclip(...)andreturn 0. May be able to use the Lit.shader and ShadowCasterPass.hlsl as a template. But you'd still want your same vertex displacement & alpha clipping. -
For receiving shadows on the foliage, you need to define keywords and call functions in URP's ShaderLibrary. (found under the URP package in the Project window - Shadows.hlsl, Lighting.hlsl and RealtimeLights.hlsl are relevant files here). e.g.
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
// in Frag function
float4 shadowCoord = TransformWorldToShadowCoord(IN.worldPos);
Light mainLight = GetMainLight(shadowCoord);
float shadows = mainLight.shadowAttenuation;
/*
Light struct also contains other data like .direction and .color
*/