0
\$\begingroup\$

I'm using Unity with URP and I'm trying to include a normal map in my shader graph.

Here is a basic graph that just display a normal map, with properties to control tiling and smoothness.

shader graph

When I render the scene, the sun reflection highlights the wrong parts of the surface.

In this example, we can see the shadow direction of the cube, and the light itself. The sun reflection is clearly at the wrong place.

wrong reflection

I tried with several normal maps from the web, all maps behave exactly like this one, so I think I'm missing something.

Ah, and strangely, when I rotate the object, the light reflection origin seems to change!

Of course, without the normal map, the light reflects gracefully.

working reflection

What am I missing?

\$\endgroup\$
2
  • \$\begingroup\$ Remember, with a directional light, it's the rotation direction that matters. The "position" of the light object is irrelevant. It's effectively an infinite distance away, along its -z vector. What you have here looks like exactly the expected result for a directional light that's shining downward and slightly to the left relative to the current view. If you want to see the specular highlight in the middle of your view, the directional light should be aimed toward the camera. \$\endgroup\$ – DMGregory Oct 9 '20 at 17:14
  • \$\begingroup\$ @DMGregory hum... i know about the directional light, and i'm sure there is still a problem because 1/ the default specular light (without normal map) reflects in the center of the screen (check the capture I added) and 2/ when I rotate the plane around Y axis, the reflection position changes. \$\endgroup\$ – Martin Oct 10 '20 at 11:45
0
\$\begingroup\$

Okay.
I found it.

The Sample Texture 2D has a type property, with options Default and Normal...

enter image description here

I don't know how I missed it. By selecting Normal, the reflection is not dependent anymore of object orientation and behaves... "normaly" (haha). Setting to Normal replace the use of the Unpack Normal node (or the hlsl relative function).

However, I'm curious of what upack normal really do.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I don't believe this is a "replacement" to unpack normal, since the documentation you link to says explicitly it's to be used in conjunction with this setting. What this does is ensure Unity is using an appropriate texture format/compression/pre-processing for normal maps on each target platform, and applying a matching processing when reading the map, so that the normal data survives the trip without visible compression errors/biases that might eg. shift a plain soft blue pixel in your input from mapping to a direct perpendicular in your shader. \$\endgroup\$ – DMGregory Oct 12 '20 at 9:29
  • \$\begingroup\$ Thanks a lot @DMGregory for your precious help! (one this subject and the other one ;) ) \$\endgroup\$ – Martin Oct 12 '20 at 11:08
  • \$\begingroup\$ Don't forget to mark your answer accepted if it worked for you. \$\endgroup\$ – DMGregory Apr 10 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.