Recent

Author Topic: Convert Image to NormalMap, AmbienctOcc, Bump map Images  (Read 1206 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Convert Image to NormalMap, AmbienctOcc, Bump map Images
« on: January 26, 2020, 12:59:23 am »
Hi,

I can't seem to find the code in the LazPaint code to convert an image to a NormalMap, Grayscale (heightmap/bumpmap) and Ambient Occusion images to use in Blender.

Any insight will be helpful.
Thanks
« Last Edit: January 26, 2020, 01:08:37 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 4450
    • https://lainz.github.io/
Re: Convert Image to NormalMap, AmbienctOcc, Bump map Images
« Reply #1 on: January 26, 2020, 01:16:09 am »
Well there are online tools to do that
https://cpetry.github.io/NormalMap-Online/

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Convert Image to NormalMap, AmbienctOcc, Bump map Images
« Reply #2 on: January 26, 2020, 01:21:33 am »
Yeah, I know.

Remember, you and circular helped me with code for phong in an app I made.

Now I want to add a way to save the phong image as normalmap, bumpmap and ambient occ map.
« Last Edit: January 26, 2020, 01:24:15 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 4450
    • https://lainz.github.io/
Re: Convert Image to NormalMap, AmbienctOcc, Bump map Images
« Reply #3 on: January 26, 2020, 01:30:46 am »
Well here is the source code of that online tool
https://github.com/cpetry/NormalMap-Online

I suppose can be converted to Pascal and BGRABitmap, but I think I don't have enough knowledge to convert that, I barely use BGRABitmap and do some stuff with it, but not knowing the hard pixel-matrix-graphics stuff  :)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Convert Image to NormalMap, AmbienctOcc, Bump map Images
« Reply #4 on: January 26, 2020, 02:03:39 am »
Okay... not what I am looking for.

I also have an awesome open source program called Materialize that does a great job creating all needed maps.

But,, I am wanting to add my own to my LAZ app.

Onward I go...  ;D
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Convert Image to NormalMap, AmbienctOcc, Bump map Images
« Reply #5 on: January 26, 2020, 11:48:31 am »
Hello

The code for computing normals in not accessible from the user in BGRABitmap. Though you can compute it yourself from the height map.

The normal is a 3D vector pointing upwards. From the site you mentioned, I suppose the up way is the z component equal to 1.

To compute the normal vector, you can do the cross product of the slope vector in x and the slope vector in y.

Sx: Slope vector in x
x = 1
y = 0
z = height difference in x = a

Sy: Slope vector in y
x = 0
y = 1
z = height difference in y = b

n: Normal vector:
n = Sx * Sy
x = -a
y = -b
z = 1

The vector is normalized to be of length 1. It is stored as RGB where :
red = x*127 + 128
green = y*127 + 128
blue = z*127 + 128

Regards
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018