Fresnel edge based on directional light?

Working on a shader and looking into using a fresnel based on the direction of the light hitting it.

here is what I have at the moment:

http://ss.myth.ro/t/r000V.png

I’m hoping for the edge to only really appear on the side the direction light is hitting. Any ideas?

(Something like this:)

http://drdave.co.uk/images/20100208_232052.jpg

The simplest version would be to hardcode the directional light direction into your shader and do this

Final = Fresnel * clamp(dot(-LightDirection, WorldNormal), 0, 1)

You might want to mess with the falloff of the dot product gradient based on look.

If you want it to be more robust you can make a material collection parameter for the directional light direction, which you set from a blueprint to update with the light’s rotation. Then all materials in the scene will pick it up.

Thank you for asking the question and for the reply!

@DanielW
However, can you further explain this technique? Why is it necessary to reverse the “LightDirection”?
I do not know what is the node “WorldNormal”? I did not find in the material expression library, what is the exact name? Can you make a screenshot of the network, in particular to control the gradient =)

@Skulburn
Share your work! What looks like your planet now?

Thank you in advance for enlighten me !!

You could do something like the attached pic (to follow what said above)

This allows you to control the fresnel, its falloff, and everything about the “directional” fake light.

Thank you very much tuxedost !!

I did not understand what corresponded “LightDirection” and “WorldNormal.” It’s better now !
I tried following your pic. I am getting closer to what I want to achieve.

When I have a little more time, I’ll post my work on this page.

If you have other blueprints with the image rendering to compare parameter, do not hesitate to share!

Thanks again !

Ok so, “LightDirection” is the node “FakeLightDir” in my network. Think of R G and B as X Y and Z. You can adjust the rim light direction with these numbers. The “world normal” is PixelNormalWS in the network. If you dot the two together, it gives you a gradient based on the fakeLightDir.

The easiest way to visualize this to understand it would be to create the graph below, and right click on the power node, and preview it.

You can then use this to multiply against a fresnel, to make that hard edge only on the side of the planet that you would like it to be on. Hope that helps.

hello, i just found this insightful thread. everything works with this shader, it is a good solution, thank you for this.
but assuming, that my sun is always in the middle of the world, what would i do, to find out the direction from the pixelnormal to the world center?
what vector math would this require?
the result would basically exchange the very left/top 3vector parameter but i do not know how to solve this.
thx in advance!

This ought to do it for you. So whats happening here is, the light position is set to 0,0,0. We then need to transform this light position to world space, inverse it, normalize it, then we can dot that against the pixel normal.

To explain the two 1X nodes, the first simply makes it so you can type values into your light position and have it correspond to the coordinate system. If that weren’t there, you’d have to type negatives to go positive. The second inverts the matrix (as DanielW says below). You’ll need to normalize the vector as well, in order for it to look right, then the rest looks like the earlier screengrab.

Making a planet go around a sun? :slight_smile:

Good luck!

thanks man, i just saw you replied long ago. sry for the late feedback! the solution works perfect!
i found out, when applied to an inverted sphere for a halo, the last “oneminus” has to be left out.
the last days i fiddled around and although i didn’t know what i was doing, i found a solution that does exactly what yours does, only that it is just one “absolute world position” node attached.
i do not know why it works or what it does, i just stumbled upon it.
see in my linked screenshot. can you explain what happens?
the night lights are done in the exact same manner.

other than that i have another question:

is there any possibility to get a longer falloff for the “shadow edge” in the middle of the planet, just like in the second screenshot? can i bend normals with vectors?

http://www.davenewson.com/_media/tutorials/udk/planet-earth/7.jpg