Page 1 of 1

World light direction fallback

PostPosted: Mon Apr 08, 2019 2:15 am
by Kilerbomb
Hello! I am working on a toon shader that needs to work in both realtime and baked lighting situations. I am using a shading ramp texture and would like to have it fall back to a fake light direction of [0,1,0] when there is no directional light present. How would I test for this? I have tried using an If node testing for a vector of [0,0,0] from the World Light Direction node but have not had any success. I should also note that I have "safe normalize" turned off in the World Light Direction node. Maybe I am thinking about this wrong, but so far I have not been able to achieve what I am looking for. Any help would be greatly appreciated!

Re: World light direction fallback

PostPosted: Mon Apr 08, 2019 6:58 pm
by naitoookami
You were on the right track but instead of the light direction vector use light intensity. If there is a real time light in the scene, light intensity will always be greater than zero. You can get light intensity from the light color node.

Re: World light direction fallback

PostPosted: Tue Apr 09, 2019 12:07 pm
by Kilerbomb
naitoookami wrote:You were on the right track but instead of the light direction vector use light intensity. If there is a real time light in the scene, light intensity will always be greater than zero. You can get light intensity from the light color node.

Hmm that seems like it would work but wouldn't point lights and spot lights also change this? Or is that all in light attenuation? Either way it does seem that I found a solution. I was using If Community since it allowed for vector3 inputs, but I believe that the "equal threshold" part was the issue. Instead, I added each axis of the light direction vector and used a Compare (A == B) node to check if the resulting value was 0. This has worked so far without issues.

I am having another problem, though. As I said earlier I need this shader to work with baked lighting as well as realtime. Since this is a "toon" style shader, I have been attempting to find a way to apply the ambient diffuse light as a flat color across my object, as the shading created from the normal direction really clashes with the toon look of the shader. Is there any way to achieve this? I have seen other shaders do it but am unsure if it is possible in amplify, or how it would be done.

Re: World light direction fallback

PostPosted: Tue Apr 09, 2019 12:33 pm
by Amplify_Borba
Hello, there's a sample in this post that combines baked and realtime lighting through a custom lighting shader, which might be helpful.