Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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?