#[Help] Custom Cel Shader – Lighting Not Diffusing on Hard Edges (HLSL Normal Fix?

1 messages · Page 1 of 1 (latest)

exotic current
#

Hey folks, I’m building a custom cel-shading system in Unity using Shader Graph with custom lighting. I’ve added a diffuse ramp and it works great on smooth objects like spheres. But on meshes with hard edges (like cubes), the lighting breaks—it doesn’t diffuse properly across the faces.

I’m currently using the Normal node in Shader Graph, but I think that’s the problem—on cubes, the normals are split per face, so the lighting ends up super flat and disconnected between faces.

Is there a way to fix this using a custom HLSL node in Shader Graph? Ideally I’d like to smooth or fake the normals across hard edges to get more consistent lighting, or some way to approximate what smooth normals would look like even on low-poly meshes.

Any help or pointers would be awesome—thanks

terse notch
#

It sounds to me like you're doing vertex displacement or something of sorts.
Maybe provide more details/screenshoots of the issue and the shader graph

vestal blaze
exotic current
vestal blaze
#

I guess you can't blend to sharp normals from smooth because that causes a split
And can't blur normals because fragments don't know what's around them (except in screen space )

#

So maybe the way to do it is to store sharpness as UV or vertex color data of a smooth shaded mesh, and "bias" the smoothing towards the sharpness value using screen space derivatives

#

Maybe those aren't that "low poly" but what you're after won't have a low poly appearance anyway

#

Or let the shader do the light ramp using smooth normals, but use sharp normal lighting as an overlay separately from the light ramp

exotic current
#

I’m making a game that involves a crap load of voxels and stuff so I can’t just not. I have no idea because I checked how unity does it in the URP lit shader but all it is is just a normalize()

exotic current
#

Interesting, I’d just need to figure out a way to do smooth normals while I’m generating a mesh

#

Via C#

vestal blaze
#

Easier to calculate hard from smooth than smooth from hard
Smooth normals are also cheaper because vertices can be shared by polygons

exotic current
#

This is actually an amazing idea

#

I will try this once I wake up

vestal blaze
exotic current
#

The shader im using doesn’t have a light ramp if you are referring to a texture

#

I’m too lazy to get a photo of this right now plus it’s 5:40 (am)

exotic current