Author Topic: Reconstructing geometry shape with a normal map  (Read 5237 times)

2017-12-21, 14:35:32

maru

  • Corona Team
  • Active Users
  • ****
  • Posts: 12758
  • Marcin
    • View Profile
Something is confusing for me, so I decided to start a forum thread to hear opinions of users and explanation from devs, as it seems I am missing something.

Goal: render some geometry from above (in this case a sphere), save the result as a normal map, re-use it to have the same "spherical" shading on a flat surface. Should be pretty simple. Typical workflow for rendering something like a repeating button pattern.

So:
Scene setup for baking normals. The sphere is spherical. Its center is in the center of the ground plane. Camera is above it, orthographic projection:


The real sphere rendered for reference:


Then I render:
-shading normals element
-z-depth element (using camera ranges for min and max values)

Then:
Hide the sphere, leave the flat plane only. Add a new material.
Let's start with displacement using the z-depth rendered from the sphere (black = ground plane, white = top of the sphere):



Everything as expected, great!


Now let's try with normals. Add a Corona Bitmap, select the rendered out normal map, plug it into a Corona Normal map, check "flip green". This is what we get:


Huh? That's definitely not a spherical shape! So here is the 1st question: why?


To fix this, set "strength mult" to 0,5 in the Corona Normal map:


This makes the "curvature" more sphere-like. So here is the 2nd question: why?


I also tried changing gamma and flipping red/green/swapping red and green, but this was the closes I could get.
Any hints appreciated! The idea is simply to get the same "shape" or "curvature" of the original geometry on a normal map.
Marcin Miodek | chaos-corona.com
3D Support Team Lead - Corona | contact us

2017-12-21, 15:27:22
Reply #1

PROH

  • Active Users
  • **
  • Posts: 1219
    • View Profile
Hi maru. Tried something similar some time ago, and I remember having the same experience. IIRC I found out, that the best result for my normal-maps (jpg), was when it was saved with gamma 2.2 and loaded with gamma 1. If I saved it with gamma 1 (as I originally did), and loaded it with gamma 1, I got a result similar to yours.

So I wonder how you saved your normal map, and if you have tried to save it with gamma 2.2?

2017-12-21, 15:34:47
Reply #2

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8844
  • Let's move this topic, shall we?
    • View Profile
    • My Models
In the example with normal map, you're rendering it on flat plane, without displacement, right?
It's easy to check wether it's a gamma issue or not, just right click on flat portion of your texture, it should be 128, 128, 255
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2017-12-21, 16:08:17
Reply #3

maru

  • Corona Team
  • Active Users
  • ****
  • Posts: 12758
  • Marcin
    • View Profile
In the example with normal map, you're rendering it on flat plane, without displacement, right?
It's easy to check wether it's a gamma issue or not, just right click on flat portion of your texture, it should be 128, 128, 255
Yes, it's a flat plane. If I open the exr normal map in PS, the flat area is 128, 128, 255.
Marcin Miodek | chaos-corona.com
3D Support Team Lead - Corona | contact us

2017-12-21, 16:11:27
Reply #4

rozpustelnik

  • Active Users
  • **
  • Posts: 149
    • View Profile
Could it be a camera set to perspective not to parallel?

2017-12-21, 16:18:26
Reply #5

Juraj

  • Active Users
  • **
  • Posts: 4761
    • View Profile
    • studio website
Despite what you write, it definitely seems like gamma issue.

You write that you open .exr, so your normal map is saved linearly, which is not very common and to get it to the format Corona for some odd reason expects, you would need to apply gamma again... or lower it by half, which is roughly the same (0.5 & 0.454)
« Last Edit: 2017-12-21, 16:23:07 by Juraj Talcik »
Please follow my new Instagram for latest projects, tips&tricks, short video tutorials and free models
Behance  Probably best updated portfolio of my work
lysfaere.com Please check the new stuff!

2017-12-21, 19:39:46
Reply #6

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8844
  • Let's move this topic, shall we?
    • View Profile
    • My Models
I don't have time to do proper test now, but it looks like indeed there's something broken. It looks like Corona inverting red channel instead of green. I'm on latest DB.
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2017-12-21, 23:01:52
Reply #7

maru

  • Corona Team
  • Active Users
  • ****
  • Posts: 12758
  • Marcin
    • View Profile
I don't have time to do proper test now, but it looks like indeed there's something broken. It looks like Corona inverting red channel instead of green. I'm on latest DB.
I'm on latest DB as well, but AFAIK it worked exactly the same in 1.7 regular.
I don't think it's channel flipping. I tried all possible combinations. It looks more like gamma, but I also tried changing it. So far Juraj's explanation with 0,454 gamma sounds the most reasonable.
Marcin Miodek | chaos-corona.com
3D Support Team Lead - Corona | contact us

2017-12-21, 23:47:18
Reply #8

PROH

  • Active Users
  • **
  • Posts: 1219
    • View Profile
Hi Maru. Isn't this exactly the same as saving the normal map with gamma 2.2 and loading it with 1?
« Last Edit: 2017-12-22, 11:04:20 by PROH »

2017-12-22, 10:59:42
Reply #9

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8844
  • Let's move this topic, shall we?
    • View Profile
    • My Models
As i said, i don't have time for testing unfortunately, but here's what i get when i saved Normal REs from Vray and Corona and also when inverted red and green channels of Corona's Normal RE. As you can see Corona's normal with inverted red channel, is matching Vray's Normal. I don't think that such result is expected.

EDIT: hmm, it seems that actually Corona is giving "normal" normal and V-Ray is reversing red channel for some reason...
« Last Edit: 2017-12-24, 11:22:54 by romullus »
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2017-12-24, 12:09:18
Reply #10

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8844
  • Let's move this topic, shall we?
    • View Profile
    • My Models
On further investigation:
1. it's not a bake issue, i tried to bake it externally and it still gives the same issues.
2. V-Ray gives the same wrong result as Corona.
3. Mental Ray renders it perfectly
4. Corona 1.3 still wrong, so it's a long standing issue.
« Last Edit: 2017-12-24, 12:28:05 by romullus »
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures