Page 1 of 1

Light Direction issue

PostPosted: Mon Jan 21, 2019 12:25 am
by Frenk.1999.98K
Hi, it's me again.. :D
I'm creating my Custom Lighting for the ocean, and I'm trying to get the light to reflect on the water, but I can't quite figure out how to get the light direction right..

These are the nodes I'm using
Image
Which results in this
Image
And looks like this applied to the ocean
Image
And result also in this (from another angle)
Image
Which looks like this, when applied to the ocean
Image
Now, the light reflection looks right, but the direction of the reflection is not, as it should look like it's coming from the sun..
I'll try to explain better the current situation and scene setup, with the following "diagram"/top-view
Image

I tried to play a bit with the nodes but I can't get it to reflect from the right direction.

Also, another thing that I'm having a lot of trouble with lately, is that if I animate a texture's UV, either by panning or by just adding a value to the original UV (i.e. Time), the texture gets more and more pixelated as it goes faster. :? I really hope you can help me out on this one as well.

Thank you in advance!

Re: Light Direction issue

PostPosted: Mon Jan 21, 2019 3:13 pm
by Frenk.1999.98K
After some time I came up with this other version of the nodes
Image
Which made the situation better, but as you can see, the light has still a visible offset...
Image
I also noticed that by blending two normals together, the light has a higher offset and gets also significantly brighter...
Image
Now I'm even more confused..

Can I somehow clamp the dot value, or maybe clamp the normal, for the brightness?

Re: Light Direction issue

PostPosted: Thu Jan 24, 2019 3:25 pm
by Amplify_Borba
Hey there! You could use the Saturate or the Clamp node, although the Saturate is most commonly used for this type of situations where you need to limit a value's range to 0 - 1.

Regarding the Custom Lighting setup, I'm afraid I can't be of much help, I'd suggest looking into Unity's own Built-in shaders to investigate how they set it up.

Re: Light Direction issue

PostPosted: Fri Jan 25, 2019 2:28 am
by Frenk.1999.98K
Alright, thank you, I'll look them up!
Also, the clamp helped out a lot, but then I found that a remap worked better...

I still have the pixelated problem, though...

Still wave normal
Image
Fast moving wave normal
Image
I've never seen this happen before, and I really don't know how to fix it, or either what would be causing it... :?

Re: Light Direction issue

PostPosted: Fri Jan 25, 2019 2:47 pm
by Amplify_Borba
I'm not entirely sure of what could be causing that, but I'll be happy to take a quick look at your setup as you might've come across an issue. If possible, please send us a simple sample over to [email protected] so that we can run some tests on our side.

Re: Light Direction issue

PostPosted: Fri Jan 25, 2019 8:51 pm
by Frenk.1999.98K
Alright, I've just sent an email with a simple unity package, with which you'll be able to recreate the issue.

Re: Light Direction issue

PostPosted: Sat Jan 26, 2019 7:07 pm
by Frenk.1999.98K
Alright, after some research I found it's a thing of its own, in unity itself...

Let me explain better:
If you pan the image as you would normally do, it will result in the image getting more and more pixelated as it goes faster.
If instead you pan the image but keep the offset between 0 and 1, the panning won't result in a pixelated image.

To fix it from your side, you could add an option on the 'Panner' node, that when enabled, it subtracts the floored offset to the offset itself, before adding it to the output UVs...

Here is an example of how to simulate it with normal nodes
Image

Edit:
I had to do it for each axis and check if it was positive or negative, to decide if I had to subtract or not..
Otherwise it was snappy here and there..

Re: Light Direction issue

PostPosted: Mon Jan 28, 2019 10:42 am
by Amplify_Borba
Thank you for sharing your findings with us!

We've ran some tests on our side and concluded that the issue is due to precision issues that originate from using Unity's timer, so the viable solution would be for you to implement your own timer through script and feed its data into the shader as a property.

Your proposed solution seems to also be able to deal with the issue at hand and, although it would likely be useful for some users that could come across a similar issue, we can't add it as an option to the Panner node as it's more of a workaround for a specific issue rather than a proper solution such as the one suggested above.

Please let us know if you have any further questions or come across any other issues.

Re: Light Direction issue

PostPosted: Tue Jan 29, 2019 9:00 am
by Frenk.1999.98K
Alright, thank you for the info, I didn't realise the time was the issue.
I'll Implement my own then, as suggested.

Thank you again for all the help, have a nice day!

Re: Light Direction issue

PostPosted: Tue Jan 29, 2019 9:24 am
by Amplify_Borba
No problem, happy to help!

Please let us know if you come across any further question or issues.