Light Attenuation + Texture Sample Misconception

Node-based Shader Editor

Light Attenuation + Texture Sample Misconception

Postby Dreezn » Sat Oct 06, 2018 4:12 pm

I fear I need someone to straighten my misconception.

My goal is to let the U component of a Texture Sample depend on the Attenuation value.
See attached screenshot for a testcase.

I cannot make sense of the output here.
I was expecting to see the same colors as in the sampled texture:
Blue closest to the light, going to green, and lastly red.
This result is indeed showing, but it turns out that the R Component of the sample output is not 0, even if we are sampling from the Green or Blue pixels in the texture.

My expectation was that, using the Texture Sample node, any UV value should return the rgb value of a pixel in the image. No matter what value we would plug into the U component.
I tried all sorts of weird inputs, just for my own sanity, and always got pure R, G or B values, as the texture contains no pixels with other values.

Only when using the Attenuation node, I get a result as demonstrated in the picture.
Clearly I am missing something. I tried to find as much documentation on the Custom Lighting mode, output and the Light Attenuation node as possible, although i did not find more than the node information, and the mention of the Custom Lighting feature.

It would be a big help to have this output clarified. Any additional knowledge about the Custom Lighting mode is very much appreciated.

Using
Amplify Shader Editor 1.5.6
Unity 2018.1.1f1

Love Amplify Shader,
Concrats to the team.
Thanks in advance.

-Edited to add version information-
Attachments
AttenuationTestSmall.png
Screenshot of testcase.
AttenuationTestSmall.png (173.41 KiB) Viewed 2471 times
Dreezn
 
Posts: 3
Joined: Sat Oct 06, 2018 3:35 pm

Re: Light Attenuation + Texture Sample Misconception

Postby Dreezn » Mon Oct 08, 2018 4:13 pm

Having experimented some more I have made an extra observation.

It turns out the excess Red values in my test are somehow related to the color value of the U=0 V=0 position in the texture.
Flipping the RGB test texture horizontally, the same effect occurs;
Only then, there is an excess of Blue in the samples, since the leftmost pixel in this example sampled texture is then pure blue.
Dreezn
 
Posts: 3
Joined: Sat Oct 06, 2018 3:35 pm

Re: Light Attenuation + Texture Sample Misconception

Postby Amplify_Borba » Mon Oct 08, 2018 4:20 pm

Hello, thank you for your kind words!

Would you please elaborate on the effect you're trying to achieve? An example image or video would help us better understand the type of effect you're looking for, and we might be able to point you the right way!

Regarding the color issue, I'm not entirely sure if it's an expected result of using the Light Attenuation node in this specific setup, as it's meant to be used together with the Light Color for specific types of light related effects. The node contains Unity's light and shadow information and outputs data that is dependent on the type of light being used: directional lights returns the white and black areas where the object is directly lit or in shadow and point and spot lights also contain the smooth falloff information of the light that changes accordingly to the range setting.

Node-based shader authoring is as powerful and flexible as it is complex, and you must understand that certain nodes output data that might only be useful in certain specific scenarios. There's much more information being handled in the background than it might look like, and the previews aren't always the best reference, as they simply provide a visual hint for the data they handle.

Also, you may edit the ASE shader's code and check what calculations each node is doing, or what functions are being used, in order to have more insight into what data you're getting and how its being transformed.

Looking forward to your reply!
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: Light Attenuation + Texture Sample Misconception

Postby Dreezn » Thu Oct 25, 2018 7:27 am

Thank you for the reply!

Off course, context could prove helpful, although I felt it was a bit much, so I focused on a specific test-case before.
I'll outline the target effect:

I would like to achieve a pixelised dithered lighting effect.

The following features would be needed to have the full effect:
I will elaborate my thinking process for each step
1 overlay a dithered mask sampled from a dither gradient texture, based upon the light attenuation
2 scale the dither 'pixels' to match the albedo 'pixels' (Not a relevant step for this post)
3 mixing in the dither mask with the albedo to create the final color (The relevant step for this post)
4 have the light falloff be discrete, so that the dither mask would match the albedo 'pixels' (Not a relevant step for this post)

See attached project for my current progress.
I used Unity version 2018.1.0f2

1 Overlay a dithered mask sampled from a dither gradient texture, based upon the light attenuation
(solved, see example project)
. If there are other methods to get this done without the attenuation node, that would also be worth considering. The amount of light present on the surface could be calculated, but then i see no way to include shadows. So this option seems kind of a work around if the attenuation node exists specifically for this purpose.

2 Scale the dither 'pixels' to match the albedo 'pixels'
(i forsee no real difficulties here. Figuring out how to match the scale based on the albedo pixel size does not seem problematic)

3 Mixing in the dither mask with the albedo to create the final color where:
. the black in the mask would darken the albedo, based upon the attenuation value. (higher attenuation = less effect)
. the albedo itself would get darker the further we are from the light. (not sure about how this would look, but I would like to see the effect)
. ambient light could be included, that way, the dark areas are not completely black.

while working on this, I found that my lack of knowledge on the custom lighting feature prevents me from finishing this feature.
Figuring this out is the reason of this post.

4 Have the light falloff be discrete, so that the dither mask would match the albedo 'pixels'
Irrelevant for this post, but I thought I'd mention it for completeness
. if we naively sample on the attenuation value, we get circular artifacts, where the output mask covers only part of a albedo 'pixelsized' area.
These artifacts are noticeable in the example.
. ideally either the whole 'pixel' should be masked or be clear.
(I see no way of accomplishing this, since naturally attenuation differs per fragment)

If this feature is not feasible, I'd be just as happy not to include it.
I imagine fixing this would be a whole study on it's own. I would like to take it one step at a time, and focus on step 3.

With this context in mind, I here are my current questions:

- As stated: my current goal is finding a way to output the correct color value based on the specifications noted in step 3. While exploring different outputs, I felt that, as long as I did not understand the test-case posted before,
there was no use in chasing a solution any further.

- Based on my experimentation, and your previous answer, it would seem that I lack knowledge
of what happens with the color value when outputed through the Custom Lighting node.

(a) Where can I find more documentation on how this pipeline is handled?
The most specific documentation I found regarding this matter is located here:
http://wiki.amplify.pt/index.php?title= ... ting_Model

(b) How should the Albedo slot be appreached when used in a Custom Lighting context

(c) How should the Emission slot be appreached when used in a Custom Lighting context

(d) How do I handle multiple lights correctly? I see the output gets computed differently based on the amount of lights that influence the face. (none, one, multiple)

(e) In first post, I replicated color output that seemed inconsistent with the sampled texture position. If I understood why this happened, I feel I would have a better understanding of the Custom Lighting feature.

I realize these are a lot of questions. That is why I stated a more directed question first.
I hope more context sheds some light (no pun intended) on my current understanding of the problems I'm trying to solve.

The most important aspect for me is that I get a more thorough understanding of the Custom Lighting workflow,
but I failed to find more relevant documentation on this point.

Thank you for your time.
Attachments
DitherEffectExample.zip
Demonstration Project. Unity 2018.1.0f2
(34.58 KiB) Downloaded 176 times
Dreezn
 
Posts: 3
Joined: Sat Oct 06, 2018 3:35 pm

Re: Light Attenuation + Texture Sample Misconception

Postby Ricardo Teixeira » Thu Oct 25, 2018 2:41 pm

Dreezn wrote:Thank you for the reply!

Off course, context could prove helpful, although I felt it was a bit much, so I focused on a specific test-case before.
I'll outline the target effect:

I would like to achieve a pixelised dithered lighting effect.

The following features would be needed to have the full effect:
I will elaborate my thinking process for each step
1 overlay a dithered mask sampled from a dither gradient texture, based upon the light attenuation
2 scale the dither 'pixels' to match the albedo 'pixels' (Not a relevant step for this post)
3 mixing in the dither mask with the albedo to create the final color (The relevant step for this post)
4 have the light falloff be discrete, so that the dither mask would match the albedo 'pixels' (Not a relevant step for this post)

See attached project for my current progress.
I used Unity version 2018.1.0f2

1 Overlay a dithered mask sampled from a dither gradient texture, based upon the light attenuation
(solved, see example project)
. If there are other methods to get this done without the attenuation node, that would also be worth considering. The amount of light present on the surface could be calculated, but then i see no way to include shadows. So this option seems kind of a work around if the attenuation node exists specifically for this purpose.

2 Scale the dither 'pixels' to match the albedo 'pixels'
(i forsee no real difficulties here. Figuring out how to match the scale based on the albedo pixel size does not seem problematic)

3 Mixing in the dither mask with the albedo to create the final color where:
. the black in the mask would darken the albedo, based upon the attenuation value. (higher attenuation = less effect)
. the albedo itself would get darker the further we are from the light. (not sure about how this would look, but I would like to see the effect)
. ambient light could be included, that way, the dark areas are not completely black.

while working on this, I found that my lack of knowledge on the custom lighting feature prevents me from finishing this feature.
Figuring this out is the reason of this post.

4 Have the light falloff be discrete, so that the dither mask would match the albedo 'pixels'
Irrelevant for this post, but I thought I'd mention it for completeness
. if we naively sample on the attenuation value, we get circular artifacts, where the output mask covers only part of a albedo 'pixelsized' area.
These artifacts are noticeable in the example.
. ideally either the whole 'pixel' should be masked or be clear.
(I see no way of accomplishing this, since naturally attenuation differs per fragment)

If this feature is not feasible, I'd be just as happy not to include it.
I imagine fixing this would be a whole study on it's own. I would like to take it one step at a time, and focus on step 3.

With this context in mind, I here are my current questions:

- As stated: my current goal is finding a way to output the correct color value based on the specifications noted in step 3. While exploring different outputs, I felt that, as long as I did not understand the test-case posted before,
there was no use in chasing a solution any further.

- Based on my experimentation, and your previous answer, it would seem that I lack knowledge
of what happens with the color value when outputed through the Custom Lighting node.

(a) Where can I find more documentation on how this pipeline is handled?
The most specific documentation I found regarding this matter is located here:
http://wiki.amplify.pt/index.php?title= ... ting_Model

(b) How should the Albedo slot be appreached when used in a Custom Lighting context

(c) How should the Emission slot be appreached when used in a Custom Lighting context

(d) How do I handle multiple lights correctly? I see the output gets computed differently based on the amount of lights that influence the face. (none, one, multiple)

(e) In first post, I replicated color output that seemed inconsistent with the sampled texture position. If I understood why this happened, I feel I would have a better understanding of the Custom Lighting feature.

I realize these are a lot of questions. That is why I stated a more directed question first.
I hope more context sheds some light (no pun intended) on my current understanding of the problems I'm trying to solve.

The most important aspect for me is that I get a more thorough understanding of the Custom Lighting workflow,
but I failed to find more relevant documentation on this point.

Thank you for your time.


Hello,

Before we proceed I recommend checking the thread below or even contacting the original poster as you seem to going for something similar.

Dithered Highlights

We thank you for the additional information but I'm afraid the answer to most of your questions is that it really depends on how you intend to implement those specific effects, that's not something we can advise you on unless we were to do it ourselves. That said, I would be happy to elaborate on a few specific points.

(a) ASE provides support for custom lighting within what Unity offers, we don't have any additional information that we can share with you besides our Light Nodes wiki pages. You can likely find additional information in the Unity documentation but for an in-depth course I recommend looking into specific Shader Lab/Unity Shader Dev books.

(b,c) The Albedo and Emission input allow you to override the baked lighting information, your actual Albedo and all the accompanying operations go into the Custom Lighting input.

(d) What do you mean by correctly? If possible, please describe a specific case.

(e) Not sure what to recommend here as it seems to be working as expected. Perhaps a simple example can help us identify any possible issues.

3. It's a combination of all your operations, can we assist you with anything more specific?

I hope the additional info helps you find the right solution, thanks.
Sales & 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
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 18 guests

cron