Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Flashlight Spotlight Causes Shadow Around Object, Doesn't Project On Wall

Discussion in 'Universal Render Pipeline' started by codylarkindev, May 21, 2023.

  1. codylarkindev

    codylarkindev

    Joined:
    May 16, 2018
    Posts:
    4
    When using the spotlight from my flashlight on any object, the shadow appears to act as a clone of the object's mesh and projects around it. I can even clip into the shadow. In my pictures I have a second spotlight off to the side showing how the shadows should actually project.

    shadow000.png shadow001.png

    It's the same problem in this thread: https://gamedev.stackexchange.com/questions/162063/strange-realtime-shadows-in-unity3d but I wasn't sure how to implement what the answer explained.

    I did a lot of messing around with the bias values and random light/shadow settings on the camera/light sources/URP quality settings. I made sure the light source isn't being affected by the flashlight model's collider.
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,971
    Send URP settings and the settings on the spotlight.
    Also check the spotlight in the scene view. If the spotlight goes inside of the mesh, it will give weird results yes
     
  3. ciaranhappy1

    ciaranhappy1

    Joined:
    Oct 22, 2018
    Posts:
    15
    that second image makes it looks like your light source is some distance away from the front lense of your flashlight model. This can cause clipping a lot of weird clipping issues. I would have the light source be right at the very front of the flashlight. That way that weird lighting artefact should only occur if your flashlight is clipping (there are ways to prevent the flashlight from clipping also, but that's a separate post altogether)


    As for the rest of the problem - just experiment with the settings. Honestly, too me that first image looks mostly fine anyway.
     
  4. codylarkindev

    codylarkindev

    Joined:
    May 16, 2018
    Posts:
    4
    urp settings.jpg


    spotlightsettings.jpg
    I also tested out having the spotlight far from the flashlight so there's no chance of it clipping but it still produced the same results.

    Also pretend that near plane value on the spotlight is 0.1. It still produces the same results but I was messing with it's value which is why it's at that random higher value.
    spotlight01.png


    spotlight02.png


    spotlight04.png

    It also seems the shadows projects onto the wall correctly in scene view, but in game view the shadow projects as a mesh around the object. The second image shows that I can clip into the shadow's mesh and it projects the clipping onto the wall in the scene view.
     
    Last edited: May 21, 2023
  5. codylarkindev

    codylarkindev

    Joined:
    May 16, 2018
    Posts:
    4
    spotlight03.png

    the spotlight was a tiny bit away from the flashlight lens so now I placed it right at the tip, or at least what seems to be as close as I can. I also have it to where the light culls out the flashlight model so it shouldn't clip even if the light was inside the flashlight model.

    yeah I'm pretty sure there's some setting value that would fix this all but my monke brain just cant find it lol. the first image does look like it is fine, but when I move towards that shadow it was actually a mesh near the model rather than a projection on the wall.
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,971
    Lower shadow casting clipping plane on the light.
    Increase high shadow resulution to 2K maybe?
    Maybe try lowering total shadow distance to 50 to see if that helps?
    Set depth and normal bias to default maybe, I think it's 1?
     
  7. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    Hi, this is expected because URP doesn't support accurate soft shadows (percentage closer soft shadow).

    More accurate soft shadow:


    You can try reducing the shadow resolution to make it more blurry.

    As for the shadow clipping, maybe you can reduce the shadow near plane value. (it's the near plane of a camera at the perspective of light for shadowmap rendering)

    If the light is nearly inside an object, the shadow clipping may also appear.
     
    Last edited: May 22, 2023
  8. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,971
    For this you need the hdrp beta or alpha. I think cilinder shadows got added recently
     
  9. codylarkindev

    codylarkindev

    Joined:
    May 16, 2018
    Posts:
    4
    Okay, yeah it seems like it's a URP thing where the first person perspective makes shadows look kinda off when it's actually projecting correctly on the wall. As DevDunk said, it seems HDRP can only give off better looking shadows. I did mess with the resolution and other settings to make it a bit blurry and it does kinda help it a bit. Thanks for the input and everyone else who helped out!
     
    ciaranhappy1, wwWwwwW1 and DevDunk like this.