#Default Unity Shadows causing artefacts

1 messages · Page 1 of 1 (latest)

glossy pivot
#

Hiya everyone, what is with unity's default shadow attenuation causing artefacting like this on surfaces? This is even present on the default lit shaders...

steady turtle
#

That's a common shadowmapping artefact. Try playing the shadow settings, like normal bias and such.

glossy pivot
#

I have, unfortunantly didnt change much, I'm using my own HLSL shader that samples mainlight.shadowattenuation

#

it's a toon shader so these artefacts are pretty visible

steady turtle
glossy pivot
#

This is found within the URP settings right?

steady turtle
#

Yes.
Make sure you're modifying the currently used urp asset.

#

By default there are several for different quality settings.

glossy pivot
#

Okay I found the right one, still no effect when I play around with depth and normal bias

#

Same artefacting

steady turtle
#

No change at all?

glossy pivot
#

no change

steady turtle
#

What do you have assigned in the active quality settings?

glossy pivot
#

Ultra, the other shadow settings do work like Max Distance and such

#

so it is the correct asset that is rendering

#

But the depth/normals bias doesnt want to work unfortunantely

steady turtle
#

Hmm... Try a standard(urp lit?) shader and see if the setting has effect on it.

glossy pivot
#

Well rather, it does work, just doesnt stop the artefacting on the surfaces that matter

glossy pivot
#

it's less visible

#

but still is there

steady turtle
glossy pivot
#

I'm wondering if this is something to blame unity's lighting system for, or rather my HLSL shader

steady turtle
#

The artefact is basically caused by a floating point error, so reducing your shadow distance might help.

glossy pivot
#

I have

steady turtle
#

Can you share your shadow settings?

glossy pivot
#

it's reduced by quite a bit

#

This is my shadow code

#

It self shadows with a dot product and also uses mainlight.shadowattenuation

#

ShadowCull is just culling the shadow attenuation smoothly

steady turtle
glossy pivot
steady turtle
# glossy pivot

It might be.
I'd start from getting issue solved with the urp lit shader first. This way you can eliminate the shader issue factor.

steady turtle
glossy pivot
steady turtle
#

Does this happen with urp lit?

glossy pivot
#

no... must be my shader then

steady turtle
#

Yep. So for shadow acne - > more cascades.

For switching between cascades - > investigate your shader.

glossy pivot
#

Are more cascades going to be less performant on low hardware?

glossy pivot
steady turtle
glossy pivot
#

Do you have a link to the code for that?

steady turtle
#

There's on github, but you call also open it in the package cache in your library folder. Just open the shader dirs with vs code or something and search through it.

#

Can also go to the urp lit shader code from the inspector.

#

One extra thing to try is to see if this issue is caused by the directional or point lights(try commenting out either). This would give some more clues as to what the cause is.
Commenting out any other logic might also help to isolate the issue.

glossy pivot
#

there are no point lights in the scene, just the main directional light

steady turtle
#

Indeed, but that doesn't mean there's no bug in that logic.

glossy pivot
#

Sorry I'm still trying to find the lit shader code

steady turtle
#

50% of debugging shaders is understanding what line causes the issue.

glossy pivot
#

I haven't written the shader to incorporate point lights into its shadow and light calculation

#

just the mainlight.direction

steady turtle
#

There should be shader and shader include directories. The shader source code is somewhere there.

glossy pivot
#

I found a shader called lit

#

sounds about right

#

in universal render pipeline folder

steady turtle
glossy pivot
#

Yep, I isolated the shadow attenuation result and it's that causing the artefacts

#

and the shadow cascading issue

steady turtle
#

Great, then looking at the unity implementation might provide some clues.

glossy pivot
#

It's important to note that I'm trying to make a toon shader

#

Not a default lit shader

#

I've got most of the toon stuff down

#

it's just shadow attenuation...

steady turtle
#

I get it, but applying shadows should be almost the same as in pbr.

glossy pivot
#

I'm looking through the lit shader, can't seem to find anything inparticular about shadow attenuation

steady turtle
#

It's likely gonna be in some include file. Gotta dig through the includes/macros, function calls.

glossy pivot
#

just seems to call a bunch of pragmas and includes and then ends

steady turtle
#

there should be a pragma specifying the fragment shader name. And the definition should be in one of the includes.

#

If you have github copilot or any other coding agent/assistant, asking it to navigate to where the shadow attenuation is applied should make it easy to find.

glossy pivot
#

I'm sorry to be such a pain

#

I haven't been doing HLSL for very long

#

This is all new to me

#

Deepseek seems to suggest it's in lighting.hlsl so I'm looking there

steady turtle
#

Yeah, actually, now that I think about it, you seem to mix up lighting calculations with shadows.🤔

glossy pivot
#

My apologies

#

I've been using shader-graph for a long time

#

I'm trying to move onto HLSL for more control

#

I'm getting closer to the solution though, it seems I just need to make it so shadow cascading works on my shader

glossy pivot
#

I may have solved it

#

@steady turtle

#

It was not what either of us anticipated

#

I think it was actually my shadow caster

#

The self casted attenuation was fucked I think... but gimme a moment to confirm

#

Yeah it was that

#

Lmao

#

looks far closer now to what I wanted

#

Thank you for your help Dlich! I think I've seen you here the past few times I had shader issues, I am thankful for your help and way of explaining stuff.

#

I've made it a goal for myself over the next year to get into HLSL so I'm better prepared for working around in-house engines as I take more contracts from local studios

steady turtle