#Default Unity Shadows causing artefacts
1 messages · Page 1 of 1 (latest)
That's a common shadowmapping artefact. Try playing the shadow settings, like normal bias and such.
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
Normal or depth bias should have at least some effect then. If it doesn't, then perhaps you're modifying settings that are not actually used in rendering currently.
This is found within the URP settings right?
Yes.
Make sure you're modifying the currently used urp asset.
By default there are several for different quality settings.
Okay I found the right one, still no effect when I play around with depth and normal bias
Same artefacting
No change at all?
no change
What do you have assigned in the active quality settings?
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
Hmm... Try a standard(urp lit?) shader and see if the setting has effect on it.
Well rather, it does work, just doesnt stop the artefacting on the surfaces that matter
It does
it's less visible
but still is there
That's an important distinction.
I'm wondering if this is something to blame unity's lighting system for, or rather my HLSL shader
The artefact is basically caused by a floating point error, so reducing your shadow distance might help.
I have
Can you share your shadow settings?
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
Does adding more cascades fix the issue a bit?
It does but it causes another issue that's even worse
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.
What issue?
Does this happen with urp lit?
no... must be my shader then
Yep. So for shadow acne - > more cascades.
For switching between cascades - > investigate your shader.
Are more cascades going to be less performant on low hardware?
Do you know how I'd implement switching between shadow cascades on a shader like mine?
Not out of the top of my head.
I'd look at the urp lit shadow implementation to see if you're missing something.
Do you have a link to the code for that?
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.
there are no point lights in the scene, just the main directional light
Indeed, but that doesn't mean there's no bug in that logic.
Sorry I'm still trying to find the lit shader code
50% of debugging shaders is understanding what line causes the issue.
I haven't written the shader to incorporate point lights into its shadow and light calculation
just the mainlight.direction
Open your project libraty/psckagecache/universal
There should be shader and shader include directories. The shader source code is somewhere there.
I found a shader called lit
sounds about right
in universal render pipeline folder
One thing to try is to output the shadowAttenuation(and after that you shadow product) directly as the final color and see if the issue persists. That would eliminate any other culprits.
Yep, I isolated the shadow attenuation result and it's that causing the artefacts
and the shadow cascading issue
Great, then looking at the unity implementation might provide some clues.
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...
I get it, but applying shadows should be almost the same as in pbr.
I'm looking through the lit shader, can't seem to find anything inparticular about shadow attenuation
It's likely gonna be in some include file. Gotta dig through the includes/macros, function calls.
just seems to call a bunch of pragmas and includes and then ends
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.
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
Yeah, actually, now that I think about it, you seem to mix up lighting calculations with shadows.🤔
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
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
Wasn't very helpful this time, but you're welcome.