Closed Thread Icon

Topic awaiting preservation: math help please (color interpolation) (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=24298" title="Pages that link to Topic awaiting preservation: math help please (color interpolation) (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: math help please (color interpolation) <span class="small">(Page 1 of 1)</span>\

 
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-04-2004 19:54

ok, i have a variable running from 0 to 1.

depending on that i want to create a color gradient.

at 0 the color should be green (rgb<0,1,0>)

at 0.5 it should be red (rgb<1,0,0>)

and at 1 it should be white (rgb<1,1,1>)


for every other value it should smoothly interpolate between these three colors.

can anyone help me out with an algorithm that outputs me the correct r,g and b?

thanks!



(Edited by GRUMBLE on 12-04-2004 19:54)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 12-04-2004 20:03

Obviously you want to process 2 gradients, therefore treat them as such. In pseudo code it should look like :

code:
if( i < 0.5 )
{
I = i*2 // I = position ( in the range [ 0, 1 ] ) in the first gradient
color = rgb( I, 1-I, 0 );
}
else
{
I = (i-0.5)*2 // I = position ( in the range [ 0, 1 ] ) in the second gradient
color = rgb( 1, I, I );
}

Hope that helps,

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-04-2004 20:10

thanks,
i just figured it out myself and wanted to edit my post.

but your version is even more understandable than mine!

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 12-04-2004 20:26



GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-04-2004 20:30

if anyone is interested where i used this piece of code,
i just updated MDTerrain with a lot of bugfixes and small new features.

if you find any more bugs or have feature requests, let me know and i'll implement them in the next version.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-04-2004 20:37

Hmmm... needs screenshots.


 

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-04-2004 20:40

on the webpage you mean?

you can save a screenhost out of the file-menu.

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 12-04-2004 21:22

that's pretty cool. what are your plans for it?

It would be something good for use in RPG stuff. I'm doing a gaming website for a friend and this would be cool to use to make maps

Later,

C:\

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-04-2004 21:26

thanks!
well, i'm working a lot with all kind of artificial terrains for university. this is just the implementation and visulization of one algorithm.

if you want to make a map out of it, just go to File->Save Heightmap and it generatess a greyscaled TGA which you can use in other applications.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 12-04-2004 21:48

To improve the quality of the terrains generated, you should blur the heightfield several passes may be necessary.
Otherwise it's cool.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-04-2004 22:08

yepp, thats already planned for the next version.
but i dont know yet which filter kernel i should use for the blurring. gaussian, average?

warjournal
Maniac (V) Mad Scientist

From:
Insane since: Aug 2000

posted posted 12-04-2004 22:42

Before going with a blurring algorithm, what method are you using for the height maps?
If you are using Perlin Noise with 'octaves', you can easily modify it for smoothness.
All you have to do is toss in an extra power, commonly called k, and it will smoothify the results.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-04-2004 23:05

no, it's not perlin noise, it's Midpoint Displacement, which is also the main point of this software, hence the name "MDTerrain".

warjournal
Maniac (V) Mad Scientist

From:
Insane since: Aug 2000

posted posted 12-04-2004 23:26

Midpoint displacement, Perlin noise - almost the same thing. At least, they look very close at a glance.

I did a cursory search and the variable is the Hurst coefficient.

Great.
Now I'm going to have to do some serious research.
Thanks a lot, Grum.

edit:

Looks like the progression is something like:
1d Brownian motion
2d Midpoint Displacement
3d Perlin Noise

Apparently Mandelbrot has some interesting things to say about these things.
Yummy.

(Edited by warjournal on 12-04-2004 23:52)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-04-2004 23:51

Yeah, before adding smoothing, look at the algorithm you're using to see if smoothness can be built in.

Actually, by setting "roughness" to values of 1 and up, I was able to get fairly smooth results. (Strangely, after changing "roughness", the results didn't change until I decreased the iteration level and then increased it again; clicking the recompute button had no effect.)

But even with high roughness (which really seems to be smoothness), I had strange sharp peaks and valleys. So, overall, I don't really understand what the algorithm is doing, which limits my ability to use it.

Yes, I meant screenshots on the web page (probably just one) to motivate people to download it. =)

Does it output 16 bit height fields for POV-Ray (by using the red and green channels separately for a full 16 bits)?


 

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-04-2004 23:57
quote:
Midpoint displacement, Perlin noise - almost the same thing.


sorry, but thats not true in sense of the way they are generated.

quote:
At least, they look very close at a glance.


that's true. they have similar characteristics.

quote:
Great.
Now I'm going to have to do some serious research.
Thanks a lot, Grum.


You're welcome!

infact, i have just implemented some terrain algorithms and here are POV-Ray renderings of the two:

perlin

midpoint displacement

they may be looking similar, but their algorithms are completely different. tell me if you are further interested in them.

edit:
Slime, yes the displacement factor is 2^-roughness per iterationdepth, so higher values give smoother results.
thanks for noting that. there might be a bug with it, when regenerating.

it outputs greyscaled TGAs (type 3). they have no RGB, just one 8Bit channel. dunno if they can be used with POV-Ray directly. i usually just save them again as pngs with ACDSee or PS.

for more information on MidPoint Displacement:
http://www.gameprogrammer.com/fractal.html
http://www.lighthouse3d.com/opengl/terrain/index.php3?mpd2



(Edited by GRUMBLE on 12-05-2004 00:06)

warjournal
Maniac (V) Mad Scientist

From:
Insane since: Aug 2000

posted posted 12-05-2004 00:42

Grum, I just can't see the difference.
I think the difference is in the approach.

1. Low frequency, high amplitude. Higher frequency, lower amplitutde. Add them together.
2. Offset the endpoints. Find center(s). Offset again, but by lower numbers.

To me, those are exactly the same.

One of my favorite links:
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm


I'm gonna go soak my head.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-05-2004 01:04

interesting.

i thought this is the way perlin noise works:
http://www.robo-murito.net/code/perlin-noise-math-faq.html

(weighted dot product of two random vectors per grid point)

i will have to look into this some more.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-05-2004 01:13

Warjournal: I wouldn't use that page as an example of Perlin Noise. I think it's taking a lot of concepts, some of which are related to Perlin Noise, and calling it all "Perlin Noise." I don't think it's entirely accurate. At least, what I see on that page doesn't have much resemblance to the Perlin Noise algorithm I've seen in POV-Ray or in Perlin's own work. (In fact, the addition of multiple layers of noise to create a busy effect is not a requirement for Perlin Noise.)

The subdivision/midpoint fractal algorithm thingy that Grumble is using is something that must be used in a grid environment; you can double the width and/or height of an existing generation, but you can't evaluate the noise as a function at an arbitrary point.

Perlin Noise, on the other hand, is a continuous function defined by assigning gradients (and maybe values, I forget) to each point on the 3D lattice and interpolating with tri-linear interpolation. You can evaluate it at any point you want (f(x,y,z)) and there is no restriction to any sort of raster grid. It's also defined everywhere (generally through seamless repeatition, actually) as opposed to within a finite rectangular region.

I'm not sure what that page you showed thinks it's doing by taking raster images and blurring them. That's not how Perlin Noise is generated to my knowledge.


 

warjournal
Maniac (V) Mad Scientist

From:
Insane since: Aug 2000

posted posted 12-05-2004 01:22

Near as I can tell, the dot product/vector gradient is still the same thing.
Get the vectors, offset the points, then do another interation (sub-divide and offset by smaller numbers).

I've got some room in my bucket.
Care you to soak your head with me?

edit:

Okay, Perlin Noise = non-fractal
2d Perlin Noise + fractal = midpoint displacement

Does that sound right?

(Edited by warjournal on 12-05-2004 02:03)

edit again:

I think I got it.
I know what makes Perlin Noise = Perlin Noise.
I now understand the difference.
Cool beans.

(Edited by warjournal on 12-05-2004 02:22)

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-05-2004 12:00

thanks for explaining this, Slime!

wj, i think also perlin noise has fractal properties. as soon as you add an octave it gets self-similar.

« BackwardsOnwards »

Show Forum Drop Down Menu