#Writing a shadow vertex pass for a billboard shader

1 messages · Page 1 of 1 (latest)

deep silo
#

I have a shader in URP (I am NOT using shader graph!!) for instancing billboards (i.e. for grass or leaves). In the case of leaves, I want them to cast some sort of shadow however them being billboards makes that difficult.

I've attached screenshots that show how the leaves cast shadows when just applying the standard translations (object to world to h-clip) without billboarding, and one where they're transformed to be billboarding.

I'm wondering if transforming the geometry such that it's pointing in the direction of the scene's directional light would be better, but I can't even test that at the moment as I have no idea HOW to do that.

Here is my current vertex shader code in the shadow vertex pass.

float4x4 detailToWorld = _TerrainDetail[instanceID].TRS;

float3 scale = float3(length(detailToWorld[0].xyz), length(detailToWorld[1].xyz), length(detailToWorld[2].xyz));

float4 worldPos = mul(detailToWorld, float4(0.0,0.0,0.0,1.0));
//Apply vertex offset and scaling
float3 viewPos = TransformWorldToView(worldPos) + input.positionOS.xyz * float3(scale.x,scale.y,1.0);

//ToDo: use _LightDirection/_LightPosition to transform the geometry to face the directional light



float4 clipPos = TransformWViewToHClip(viewPos);
#if defined(_ALPHATEST_ON)
output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
#endif

output.positionCS = clipPos;
sullen latch
#

I think the billboarding here should already be pointing towards the light source when used in the shadowcaster pass, as "view space" should be relative to the light when rendering the shadowmaps

deep silo
#

I guess trhat makes since. In that case, why do the leaves all in shade?

sullen latch
#

Ah probably self shadowing. Offsetting a bit along the light direction might help prevent that (to the worldPos, or offset along (0,0,-1) in viewPos)

deep silo
#

I'll try that, thanks!