#How can I make both sides of this sprite be lit?

1 messages · Page 1 of 1 (latest)

west plank
#

I'm a complete beginner when it comes to all things shader/shadergraph related, so I copied this shader graph from a tutorial. It works great for allowing 2d sprites to cast 3d shadows and to be affected by lights, but one problem is that the back of the sprite is unaffected by lighting changes. It still casts shadows, but the sprite doesn't change color at all when hit from the back.

Any help is greatly appreciated.

crude thorn
#

While you might think that rendering the back face should work, it doesn't because it doesn't duplicate geometry(and thus normals).

It would require custom lighting calculationsif you really need it to work as is.

#

Though, perhaps a small hack might work: use the "is front face" node to determine if it's front or back face, and if it's back, then flip the normals.
Never tried it, but theoretically that might work.

gilded musk
#

maybe there is something else that we cannot modify in the fragment shader, like some tangent data used to do the conversion between spaces

crude thorn
#

Is that in deferred rendering path?

gilded musk
#

forward+

#

actually on second thought, it's only the corner vertices that are "correct"

crude thorn
#

Perhaps switching to deferred and looking at the gbuffer would reveal some more info

rancid anchor
#

Confirm by disabling shadow casting on the mesh if it actually is related to that

#

Because you are using flat geometry only, you should be able to flip the normal to be always non-negative from camera's perspective without the issue that a surface could have both flipped and non-flipped normals

gilded musk
#

that makes sense, indeed it is self-shadowing

rancid anchor
#

Although I'm not sure if that alone solves the problem

#

Maybe it does and I'm just not thinking right

gilded musk
#

it does, this works fine

rancid anchor
#

Great!

gilded musk
#

actually, well, maybe not, now the backside is dark again of course, I forgot something 😆

#

you actually need to know the light direction as well

#

so instead of WorldPos - CameraPosition it needs the main light position
then it works for a single shadow caster

#

the main light position (or direction from the POV of the vertex) isn't available in shader graph by default though iirc

#

I think the easiest solution is to just disable double-sided rendering, duplicate the sprite object, and invert the UVs (or scale the duplicate negatively on X I guess)