Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    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?