Stylized Shading + Point Light Troubles

Node-based Shader Editor

Stylized Shading + Point Light Troubles

Postby ori0n » Thu Jan 18, 2018 3:27 am

Hello! I'm making a very stylized game where I'm micromanaging the way shading and environmental effects look using Custom Lighting shaders. Everything's great so far when I use just one directional light, but introducing a point light causes problems. It seems to be pretty common, here's a thread I found about it so far: https://forum.unity.com/threads/getting ... es.442757/

The real shader is much more complicated, but here's a really boiled-down example to show what's happening for me. The desired outcome is to have all lighting and shadows lerp from red to blue:
PointLightTroubles.jpg
PointLightTroubles.jpg (198.26 KiB) Viewed 2304 times


To me it looks like what's happening is the final result of the lerp is getting evaluated and added for each individual light, instead of the result of all lights being used to drive the alpha of the lerp. Has anyone tried to do something similar to this with success? Am I just going about it completely the wrong way? Just looking for any insight or workarounds to get the result I want. I'm pretty new to doing Custom Lighting shaders in Amplify/Unity3d. (I did a bunch back in Unreal 3 which is where my maybe weird assumptions are coming from.) My current work-around is to manually implement a fake pointlight in the shader itself, which is really cumbersome and can't cast shadows, so it's not ideal. Thanks a bunch for any help!
ori0n
 
Posts: 2
Joined: Thu Jan 18, 2018 2:36 am

Re: Stylized Shading + Point Light Troubles

Postby Amplify_Borba » Thu Jan 18, 2018 12:47 pm

Hello ori0n, thank you for getting in touch!

You're correct to assume that the Lerp is being interpolated by each light, since it's not possible to use the result of all lights to drive the alpha through the shader.

Because each light is being calculated separately the operation you've set up is being performed twice, once for each light type, and as a result the area of effect of the Point light is being shown, which is the square you see.

One possible workaround for this, that would have the point lights behave to the lerp operation correctly, is to filter the light operations through multiplying the values prior to the Alpha input for the light type, which can be accessed through the World Space Light Pos node, as it returns 0 for directional lights and 1 for other light types.

You may also refer to the link you've shared which also provides a viable workaround regarding a custom falloff for the point lights, however, this would require altering Unity's built-in shaders.

Please let me know if this helps, thanks!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Stylized Shading + Point Light Troubles

Postby ori0n » Thu Jan 18, 2018 8:21 pm

Amplify_Borba, thanks so much for that suggestion about World Space Light Pos Type and filtering the point lights. That gets me a result very close to what I was looking for! Here's what I did in case this helps anyone else down the line:
FilterLights.jpg
FilterLights.jpg (235.77 KiB) Viewed 2279 times


Thank you!
ori0n
 
Posts: 2
Joined: Thu Jan 18, 2018 2:36 am

Re: Stylized Shading + Point Light Troubles

Postby Amplify_Borba » Fri Jan 19, 2018 9:57 am

Glad to be of assistance, and thank you for taking the time to share your sample with the community!

Have you had the chance to rate and review Amplify Shader Editor? It would be awesome if you could share your experience with the Unity community, the Unity Asset Store thrives on user interaction and direct feedback.

Feel free to get back in touch if you have any questions, thanks!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests