POV-Ray : Newsgroups : povray.general : Generate normal map Server Time
22 Dec 2024 22:07:46 EST (-0500)
  Generate normal map (Message 1 to 10 of 18)  
Goto Latest 10 Messages Next 8 Messages >>>
From: Josh
Subject: Generate normal map
Date: 1 Oct 2019 17:35:01
Message: <web.5d93c59f47aa2457bde26add0@news.povray.org>
Hi all,

Does anyone know how I would generate a normal map of an object in povray? I
have a scene with a single asteroid in it, and I need to generate a normal map
of it so it can be lit up properly in a 2D game.

Also, how would I render the asteroid with only ambient light? Since there are
already lights in the game...

Thanks!

Josh


Post a reply to this message

From: Bald Eagle
Subject: Re: Generate normal map
Date: 1 Oct 2019 18:10:07
Message: <web.5d93cde6892ac194eec112d0@news.povray.org>
"Josh" <nomail@nomail> wrote:
> Hi all,
>
> Does anyone know how I would generate a normal map of an object in povray? I
> have a scene with a single asteroid in it, and I need to generate a normal map
> of it so it can be lit up properly in a 2D game.
>
> Also, how would I render the asteroid with only ambient light? Since there are
> already lights in the game...
>
> Thanks!
>
> Josh

I'm not sure you want to use a normal map, or even just a normal for what you
want to do.

http://wiki.povray.org/content/Reference:Normal_Map

I'd probably use an isosurface sphere and perturb the surface with a noise
function to get real 3D displacement.

http://www.econym.demon.co.uk/isotut/simple.htm#sphere
http://www.econym.demon.co.uk/isotut/builtin1.htm#sphere1
http://www.econym.demon.co.uk/isotut/parametric.htm#sphere2
http://www.econym.demon.co.uk/isotut/patterns.htm#noise

http://www.econym.demon.co.uk/isotut/combine.htm#add


As for the lighting, you can use
http://wiki.povray.org/content/Reference:Global_Settings#Ambient_Light

combined with

http://wiki.povray.org/content/Reference:Finish

however, to give a "realistic" look to the object, I'd think you'd want to try
to create a light source in your scene so the POV-Ray light source is in
approximately the same relative position as the one in the game.

We'd need more details and perhaps a diagram or screenshot to really give you
better advice.
Are you animating this?


Post a reply to this message

From: Josh
Subject: Re: Generate normal map
Date: 1 Oct 2019 19:05:00
Message: <web.5d93dab5892ac19bde26add0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Josh" <nomail@nomail> wrote:
> > Hi all,
> >
> > Does anyone know how I would generate a normal map of an object in povray? I
> > have a scene with a single asteroid in it, and I need to generate a normal map
> > of it so it can be lit up properly in a 2D game.
> >
> > Also, how would I render the asteroid with only ambient light? Since there are
> > already lights in the game...
> >
> > Thanks!
> >
> > Josh
>
> I'm not sure you want to use a normal map, or even just a normal for what you
> want to do.
>
> http://wiki.povray.org/content/Reference:Normal_Map
>
> I'd probably use an isosurface sphere and perturb the surface with a noise
> function to get real 3D displacement.
>
> http://www.econym.demon.co.uk/isotut/simple.htm#sphere
> http://www.econym.demon.co.uk/isotut/builtin1.htm#sphere1
> http://www.econym.demon.co.uk/isotut/parametric.htm#sphere2
> http://www.econym.demon.co.uk/isotut/patterns.htm#noise
>
> http://www.econym.demon.co.uk/isotut/combine.htm#add
>
>
> As for the lighting, you can use
> http://wiki.povray.org/content/Reference:Global_Settings#Ambient_Light
>
> combined with
>
> http://wiki.povray.org/content/Reference:Finish
>
> however, to give a "realistic" look to the object, I'd think you'd want to try
> to create a light source in your scene so the POV-Ray light source is in
> approximately the same relative position as the one in the game.
>
> We'd need more details and perhaps a diagram or screenshot to really give you
> better advice.
> Are you animating this?

Sorry, I should have been more clear. I need to create a normal map of the
asteroid because the generated sprite (lit only with ambient light) and normal
map, are going to be used in a 2D game that has its own lights. The game engine
uses the sprite and normal map to properly light the sprite. Also, I had found a
script that generates the mesh, so at this point I'm just trying to figure out
how to generate a normal map of it, and to light it with only ambient light.
Thanks!


Post a reply to this message

From: Bald Eagle
Subject: Re: Generate normal map
Date: 1 Oct 2019 19:10:00
Message: <web.5d93dc6d892ac194eec112d0@news.povray.org>
Here's a quick example:


#version 3.8;
global_settings {
 assumed_gamma 1.0
}
#include "colors.inc"
#include "functions.inc"

camera {
 location  <0, 0, -10>
 look_at   <0, 0,  0>
 right     x*image_width/image_height
 up y
}

light_source {<-5, 1, -10> colour rgb 1}

#declare Noise = function {f_noise3d (x, y, z) }

#declare P = pigment {Gray50}

#declare Radius = 2;
#declare NS = 0.2; // NoiseScale
#declare NoiseStrength = 0.15;
isosurface {
 //function {y - Noise (x, 0, z) * 2 }
 function {sqrt(pow (x, 2) + pow (y, 2) + pow (z, 2)) - Radius - (Noise (x/NS,
y/NS, z/NS)*NoiseStrength) }

 max_gradient 2
 accuracy 0.001
 contained_by {box {<-Radius, -Radius, -Radius>*1.1, <Radius, Radius*3,
Radius>*1.1} }
 scale <1, 1.5, 1>
 texture {
  pigment {P}
  finish {diffuse 0.4 specular 0.2}
 }
}

---------------------------------------------------------------------------

Also, maybe if you have a uv-mappable image of an asteroid, you could use a
bump_map normal on a [scaled] sphere.

From the drop-down Insert Menu
Textures and Materials > Textures > Texture Maps > bump_map normal

// texture normal {} attribute
// create a texture that has a bumpiness corresponding to color index
// image maps into X-Y plane from <0,0,0> to <1,1,0>
bump_map { // uses image color or index as bumpiness
  png "plasma3.png" // the file to read (iff/tga/gif/png/jpeg/tiff/sys)
  map_type 1        // 0=planar, 1=spherical, 2=cylindrical, 5=torus
  interpolate 2     // 0=none, 1=linear, 2=bilinear, 4=normalized distance
  // once           // for no repetitive tiling
  // [use_color | use_index]
  bump_size 0.5     // 0...3
} // bump_map


Post a reply to this message

From: Bald Eagle
Subject: Re: Generate normal map
Date: 1 Oct 2019 19:25:00
Message: <web.5d93df42892ac194eec112d0@news.povray.org>
"Josh" <nomail@nomail> wrote:

> Sorry, I should have been more clear. I need to create a normal map of the
> asteroid because the generated sprite (lit only with ambient light) and normal
> map, are going to be used in a 2D game that has its own lights.

> The game engine
> uses the sprite and normal map to properly light the sprite. Also, I had found a
> script that generates the mesh, so at this point I'm just trying to figure out
> how to generate a normal map of it, and to light it with only ambient light.
> Thanks!

So, looks like we just crossed paths  :D

If you're going to use a mesh - a real mesh - then isn't that a bunch of
triangles, and the surface normal is inherent to each triangle face?

I'm not sure how your game engine interprets your input...


Maybe if you use the mesh object in POV-Ray and then "scan" the surface with the
trace () function, that will return the normal at the point that the ray
intersects the mesh.
Use a parametric sphere as the surface to scan inwards from, and then you can
write that vector data to a file in the format the engine expects it...

I think POV-Ray normal_maps do different things than your game engine does.


Post a reply to this message

From: Bald Eagle
Subject: Re: Generate normal map
Date: 2 Oct 2019 15:50:01
Message: <web.5d94fef1892ac194eec112d0@news.povray.org>
"Josh" <nomail@nomail> wrote:

> Sorry, I should have been more clear. I need to create a normal map of the
> asteroid because the generated sprite (lit only with ambient light) and normal
> map, are going to be used in a 2D game that has its own lights. The game engine
> uses the sprite and normal map to properly light the sprite. Also, I had found a
> script that generates the mesh, so at this point I'm just trying to figure out
> how to generate a normal map of it, and to light it with only ambient light.
> Thanks!

Can you describe / link to your game engine?
Provide an example of the mesh file and what the requirements for the "sprite"
and the normal map are?

If you plug the three vertices of each triangle into the plane equation, you get
A, B, C and D and that will give you the normal vector.

I'm assuming that you want some sort of even, shadowless 50% gray "ambient
light" result from the render so that it can be _re_lit in the game engine using
that as a starting point...   But without specifics, I'm only guessing and can
only help you so much.


Post a reply to this message

From: Josh
Subject: Re: Generate normal map
Date: 3 Oct 2019 03:15:01
Message: <web.5d959f5d892ac19bde26add0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Josh" <nomail@nomail> wrote:
>
> > Sorry, I should have been more clear. I need to create a normal map of the
> > asteroid because the generated sprite (lit only with ambient light) and normal
> > map, are going to be used in a 2D game that has its own lights. The game engine
> > uses the sprite and normal map to properly light the sprite. Also, I had found a
> > script that generates the mesh, so at this point I'm just trying to figure out
> > how to generate a normal map of it, and to light it with only ambient light.
> > Thanks!
>
> Can you describe / link to your game engine?
> Provide an example of the mesh file and what the requirements for the "sprite"
> and the normal map are?
>
> If you plug the three vertices of each triangle into the plane equation, you get
> A, B, C and D and that will give you the normal vector.
>
> I'm assuming that you want some sort of even, shadowless 50% gray "ambient
> light" result from the render so that it can be _re_lit in the game engine using
> that as a starting point...   But without specifics, I'm only guessing and can
> only help you so much.

Sorry for the slow reply. I am using the godot game engine (godotengine.org) to
make a 2D game. So I am just trying to generate sprites, one of the asteroid,
and another of the normal map. You can see the kind of assets I am using by
looking at the space ships here
https://millionthvector.blogspot.com/p/free-sprites_12.html

With a 2D sprite of a spaceship and a normal map, the game engine is able to use
lights to make it appear as if the scene is a fully rendered 3D scene. The space
ships with lights look amazing, and obviously it doesn't cost the rendering time
of 3D.

So I was wanting to add asteroids using a similar method. I have found nice
looking asteroids online, but none with normal maps. So I found a povray script
to generate asteroids and am now trying to modify it to generate a 2D sprite of
the asteroid along with a normal map.

When I get more time I can give more detail. Thanks for your help.

I found this thread which looks helpful, but so far haven't managed to get
everything working.

http://news.povray.org/povray.advanced-users/thread/%3Cweb.4500845a5dce606226c7adc80%40news.povray.org%3E

Josh


Post a reply to this message

From: Bald Eagle
Subject: Re: Generate normal map
Date: 3 Oct 2019 07:25:01
Message: <web.5d95d9b3892ac194eec112d0@news.povray.org>
Super - I have a MUCH better understanding of what you need, but still no
details.

How are the normals encoded in the image?
What's the equation?
It looks to me like maybe it's R, G, and B separated at 120 deg from each other?

I could guess - but I'd just be guessing.

Is there a spec?


OK, off to work.


Post a reply to this message

From: Josh
Subject: Re: Generate normal map
Date: 4 Oct 2019 13:15:00
Message: <web.5d977d8f892ac19bde26add0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Super - I have a MUCH better understanding of what you need, but still no
> details.
>
> How are the normals encoded in the image?
> What's the equation?
> It looks to me like maybe it's R, G, and B separated at 120 deg from each other?
>
> I could guess - but I'd just be guessing.
>
> Is there a spec?
>
>
> OK, off to work.

Sorry, I thought I replied to this a couple days ago with a longer explanation,
but didn't see the message show up.

This page explains pretty well the concept.
https://en.wikipedia.org/wiki/Normal_mapping

That's all I have time for now.

Josh


Post a reply to this message

From: Bald Eagle
Subject: Re: Generate normal map
Date: 4 Oct 2019 14:25:00
Message: <web.5d978e57892ac194eec112d0@news.povray.org>
I adjusted the blue channel and - I guess it looks to me like it's right.

The gray asteroid has
finish {ambient 0.5 diffuse 0.25 specular 0.25}
because ambient 1 just gives a flat gray object with no visible features...

Do you need a specular map as well?

Does this need to be rendered with a transparent background (alpha channel) ?


Post a reply to this message

Goto Latest 10 Messages Next 8 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.