Help with limiting light direction on material

Looking for a bit of help with my material functionality.

What I’m trying to do is limit the vertical range of the sun light for this material only, by a given amount. Using the float3values debug node, I thought it was simple - see below:

This worked as expected; when the sun is high in the sky the blue channel is capped at whatever value i give it, 0.25 in this case. Below that it works as normal. Left/Right rotating untouched, as expected.

However, when tying it into the VertexNormalWS node it stops behaving as I expect. The sun height is still influencing the material - not getting capped:

Its acting like a multiplier of the vertical component, rather than a cap. So setting it to zero gives the vertical component zero influence:

My understanding of the maths is clearly the limiting factor here. I’d appreciate any help if you know of a way of capping a vector component.

not sure what you mean by “clamping” (i know what it means, but not what you try to do).
ambient light doesn’t have a distance. is omnipresent, it only has a direction.

i’m not sure but i think sky light is the same thing. or any directional light for that matter.

I mean I am aiming to limit the direction of the directional sunlight affecting the material.

For example I’d like the vertical component limited to below 40 degrees above the horizon, but leaving the horizontal component as normal (and obviously I don’t want to limit the actual sunlight, it still needs to move around as normal)

It should be possible, I’d just like some help with figuring out how. I mean by setting the Blue channel to 0, it does clamp the vertical component to the horizon, which is a good step. I just want to be able to have more control

I thought I had it, with the debug values reading the behaviour I expected but in reality its not working quite right.

1 Like

i’m still not confident i understand what you try to do.

but maybe you can try converting the normal to the rotation on each axis, clamp said rotations, then convert back to a normal.

you need to understand what a normal is, and how it behaves. you can’t just modify one of the components, it stops being a normal and will have weird results.

I was able to get the results I wanted, embarrassingly using the AI helper thing.

As you see (if the short video works), the light direction works normally until 40 degrees above the horizon, where it stops, and stays there until the light direction dips back under 40 degrees.

Here is the solution - I’d be lying if I understood all of it

it does what i said, but instead of converting the normal to an angle it converts the angle into the normalized value and uses that.

im glad you found the solution.

Though im not sure that code is correct.

Is using only two components to get the length.

Not sure why would you want to get the length of a normal vector, as it’s supposed to be 1.