Page 1 of 1

DecodeDirectionalLightmap

PostPosted: Mon Feb 18, 2019 3:51 pm
by b0kkie
Hi,

I am wondering if there is a way to use DecodeDirectionalLightmap in ASE.
I want to use a ramp in a custom lighting shader with directional lightmap support.
For this reason I'm baking a directional lightmap, but I am having trouble implementing this ASE.
I want to do a dot product between the directional lightmap and normal direction to drive the ramp.

Hope someone could point me in the right direction.

Cheers,
J

p.s.

I found this information, to give an idea.
https://catlikecoding.com/unity/tutoria ... g/part-16/
4.3 using direction

Re: DecodeDirectionalLightmap

PostPosted: Tue Feb 19, 2019 3:34 pm
by Amplify_Borba
Hello, thank you for getting in touch and for your support!

Since we do have a custom node for the Decode Lightmap, it does make sense to also offer the one you've requested as well, so we've set up a Shader Function that I'm attaching to this post:

DecodeDirectionalLightmap.unitypackage
(1.19 KiB) Downloaded 396 times


We did this using a Custom Expression node, you may double click the function in order to see how it was set up.

Please let us know if this helps and if you have any further questions, thanks!

Re: DecodeDirectionalLightmap

PostPosted: Wed Feb 20, 2019 9:38 pm
by b0kkie
Thank you so much for the help.

Only wondering how to implement this. I figured I would multiply this with my albedo texture.
Like you would multiply the albedo and light attenuation and light color after the ndotl in custom lighting.
decodelightmap gives a proper attenuation as you would expect where decodedirectionallightmap does not give the same result as I hoped. This is something i suspect related to unity and not ASE.

I will have to dig a bit deeper and hope to find a way of having baked lighting with custom lighting.

Re: DecodeDirectionalLightmap

PostPosted: Thu Feb 21, 2019 2:53 pm
by Amplify_Borba
No problem, happy to help!

Since Amplify Shader Editor generates Standard Surface shaders by default, the results should be exactly the same as if you were using an equivalent Unity shader ( we often set up simple ASE and Unity shaders to test this ourselves ).
If you manage to confirm that the ASE generated standard shaders are producing an outcome that differs from Unity's, please let us know and we'll investigate it on our side.

Regarding the lightmap data, I believe that you'd have to multiply it by the final result of your texture data.

Please let us know if you have any further questions, thank you!

Re: DecodeDirectionalLightmap

PostPosted: Thu Feb 21, 2019 5:40 pm
by b0kkie
Hi,
I've played around a bit and decided to take apart the decodedirectionallightmap function.
Atleast as I found in the UnityCG.cginc. It works perfectly and is identical to standard shader with baked lighting.

The problem however arises when I add a realtime light. It creates issues as seen from the screenshots.
With custom lighting I've seen you multiply the light attenuation and lightcolor at the end, however this
does not work for me in this case.
Would it be possible to get this to work both with baked lights and realtime lights as it works in the standard shader?
Any tips would be greatly appreciated. Thanks again!

Re: DecodeDirectionalLightmap

PostPosted: Fri Feb 22, 2019 3:06 pm
by Amplify_Borba
It seems that you might have stumbled into a possible issue, I'll need to escalate this to the developer for further investigation.

Could you please share a simple sample so that we can examine it on our side using the exact same data as you?
You can share it privately through [email protected] if you prefer, thank you!

Re: DecodeDirectionalLightmap

PostPosted: Mon Feb 25, 2019 4:06 pm
by b0kkie
Hi again thanks for assisting with this.
You can get the sample package below. I've shared it through google drive.
https://drive.google.com/file/d/1Grh9mc ... sp=sharing
If you need anything else let me know.

Cheers,
J

Re: DecodeDirectionalLightmap

PostPosted: Fri Mar 01, 2019 6:11 pm
by Amplify_Borba
Thank you for taking the time to prepare a sample, I'll be sure to get back in touch as soon as we have any developments to share!

Re: DecodeDirectionalLightmap

PostPosted: Wed Mar 06, 2019 2:22 pm
by Amplify_RnD_Rick
Hey b0kkie,

Ricardo (the ASE developer here). Again thank you so much for taking the time on preparing that amazing sample.

I took at it and those artifacts are there because you aren't correctly considering the point lights on your custom lighting calculations.

I've tweaked the sample you sent ( link over here ) so in the Forward Add pass ( when the point lights contribution are added ) it now applies a simple N.L and multiply it by both the point light color and attenuation.

Please let us know if you have further questions!

Re: DecodeDirectionalLightmap

PostPosted: Tue Mar 12, 2019 9:37 am
by b0kkie
Hi Ricardo,

Thanks a lot for helping out with this.
I've had a look at the tweaked example and it does work.
It combines the baked and realtime lighting as you pointed out with the forward add pass.
It's still giving me some issues but I have to investigate this myself first.

Thanks again for the help.
Cheers,
J