Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Flat, per object shading

Discussion in '2D Experimental Preview' started by Armadous, Feb 15, 2021.

  1. Armadous


    Apr 6, 2013
    This is a repot of my post on Graphics > URP, I believe this a more appropriate location.

    Straight to the point, I'm to achieve a flat shading on normals from 2D lights.

    How shading currently works.

    How I want it to work.

    The working example comes from modifying LightingUtility.hlsl to take either 1 or 0.5 color values based on the normal angle to the light and only works when objects are placed at the origin, I'm not using pixel position for the following reason.

    Normally lighting is computed per pixel but I need every pixel on the sprite to see the same angle to the point light. This solves undesirable artifacts introduced by the pixels at the top of the post having a different angel to the light from those at the bottom and the same for every pixel between. This causes the shadow that slides up and down the post as well as the irregular shading on the ground.

    Very generally, is there a better way to achieve this effect besides messing with the shader guts? Very specifically, is it possible to determine the object position in world space from the input.positionWS available in LightingUtility.hlsl APPLY_NORMALS_LIGHTING?