Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Procedural night sky  (Read 8364 times)
0 Members and 1 Guest are viewing this topic.
Offline philfrei
« Posted 2012-08-07 08:30:27 »

*****************
[EDIT:
   web demo  http://hexara.com/Starfield
   runnable jar with source code  http://hexara.com/Starfield/StarfieldTest.jar
   posted 8/10/12
Original post is below]
*****************

A while back dario3004 included a beautiful photo of a starry sky in a post. I recall asking him at the time if it was a graphic or procedural, and he said it was a NASA photo. But that got me itching to see if I could do something similar procedurally. The inspiring post is below:

http://www.java-gaming.org/topics/best-way-to-render-glowing-lines-rectangles/26246/msg/229321/view.html#msg229321

So, I recently (finally!) started to figure out how to use Simplex Noise, and went back to the idea of making  a procedural starry sky. Here is a screen shot:

Was kind of proud of it and wanted to show it off, even if the use of the Simplex noise was really basic (just used the main formula and only two "octaves"). Just the little splash seems to add a lot in terms of making this look like a plausible NASA photograph.

I'm happy to make the java code available. Maybe someone wants to have some night sky? But I wanted to find out if there was any interest first, before putting a lot of time into it. Same thing with adding to the api. Right now it is really simple:

Constructor: give it the rectangular bounds, the number of stars and a seed for the random function.
There are also two methods:
1  
2  
void update()
void draw(Graphics2D g2)

These can go in a game loop to add animation: the stars twinkle, and occasionally there is a shooting star.

Please let me know if there is any interest.
Suggestions for gnarly nebulae creation gladly accepted!

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #1 - Posted 2012-08-08 00:32:09 »

Well done!

I have a interest in procedurally generated games / artwork... not that I have any time to do games any more Sad

I think my interest is because I have no artistic talent what so ever Tongue

You have any plans to use it in a game?
Offline philfrei
« Reply #2 - Posted 2012-08-08 03:35:04 »

Quote
You have any plans to use it in a game?

I have a puzzle game I'm working on that uses a night sky as a background element. I just replaced the old starry sky with the new version, and nothing crashed.  Grin

Maybe will get a demo up and have a link in a few.

I hear you about the "artistic talent" issue. I also like to avoid copyright issues and downloading resources issues. But that doesn't justify this case. There are lots of nice free star jpegs, and the code is about 10KB (not counting the simplex routine).

More likely I am just a dithering control freak. Nice to be able to make changes via code rather than by PhotoShopping.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-08-08 04:37:39 »

Sometimes I miss the usual java2D procedural things, it's really fun to play. Higher API like libgdx is no Sad

Offline coltonoscopy

Junior Member


Medals: 2



« Reply #4 - Posted 2012-08-08 06:22:58 »

That's really cool! I'm heavy into procedural game development and am working on making an RPG myself, which will include day and night cycles. More than wanting to copy and use your code (which nonetheless would probably be nice and easy), I'm actually interested more in how you went about it! I knew I wanted to use somewhat of a procedural system for the stars at night, but you have a few other cool things going on here, and I'm not terribly familiar with simplex noise, so more insight would be awesome! Cheesy

Straight flippin.
Offline _Al3x

Senior Member


Medals: 7


Indie Games FTW!


« Reply #5 - Posted 2012-08-08 15:39:12 »

I'd love to try it, please? Smiley

Offline philfrei
« Reply #6 - Posted 2012-08-08 16:23:00 »

@coltonoscopy There is so much to explain! Below are links to tutorials I found most helpful. If you have more questions, I'm happy to give them my best shot.

I only used the Simplex Noise with the Galactic Cloud. The stars (made using BufferedImage) and their placement just uses the good old Java Random function (with an exponential function thrown in to inversely bias the relationship of the size of the star to the quantity generated).

This was a helpful tutorial on using Simplex Noise, and it has an important link to a paper and free Java implementation (that I use) by Stefan Gustavson. The tutorial was written by JGO member ShannonSmith.
http://www.angryoctopus.co.nz/?p=11

I'm still grappling with how best to use Simplex Noise. In this StarField, I call it to fill a BufferedImage, but the result then is of course rectangular. I've made a tool for tapering to alpha = 0 so as to be able to blend it into a background. Am still trying to figure out how best handle other transforms, am building a couple tools to help with that.

This next tutorial uses Simplex Noise to create a Java Paint object. (He calls it "Perlin Noise" but he uses the Java reference implementation Perlin wrote for his Simplex algorithm.) If you use that approach, you can use it as fill for shapes or letters. But I suspect it is not the best way to go if you are continually repainting a screen. Wouldn't that require regenerating the noise with each render?
http://asserttrue.blogspot.com/2010/02/procedural-paint-in-java-perlin-noise.html

Dzzd has posted his "FastNoise" on JGO. You might want to check it out.
http://www.java-gaming.org/topics/fastest-perlin-noise-gradiant-amp-value-noise/24197/view.html
http://www.java-gaming.org/topics/fastest-perlinnoise-improved-version-bicubic-amp-bilinear-grad-amp-value-noise/23771/view.html

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline philfrei
« Reply #7 - Posted 2012-08-08 16:33:54 »

Quote
I'd love to try it, please? Smiley
Hi _Al3x - I was wondering if you were still interested in this!

I made a jar but there is a bug I want to fix, and hope to have it handled before the end of the day. In the api, one specifies the bounds of the area that the StarField is to display within. But the GalacticCloud I made is not staying within the bounds. I'm working on some code that will allow me to rotate and clip the cloud image to fit.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline coltonoscopy

Junior Member


Medals: 2



« Reply #8 - Posted 2012-08-08 22:48:25 »

philfrei,

Thanks, I'll be sure to take a look! It sounds like you're doing a decent thing with painting to a BufferedImage, and with the applications I could use something like that for, I would most likely do the same. For the repainting issue, it sounds like that would have to unfortunately be the case. If I were going to use it in a game engine, I would probably incorporate objects into the sky (in this case, the galactic cloud) that are dynamically updated and can have certain effects applied to them (like shimmer or whatever for aurora borealis-type effects) while retaining the static starry background and night colors. Thus, they would sort of be in-game entities or at least animations that are stored or manipulated, and I'm sure they could still be generated using simplex algorithms either way. All hypothetical until I actually test it, however. :] Thank you!

Best regards,
Colton

Straight flippin.
Offline _Al3x

Senior Member


Medals: 7


Indie Games FTW!


« Reply #9 - Posted 2012-08-09 05:10:50 »

Hi _Al3x - I was wondering if you were still interested in this!

Well, hi Smiley !

I am still interested! I can´t use it right now, but I´d love to see it working and keep a sample for later deep study  Cool

Keep it up, wish you the best Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grunnt

JGO Wizard


Medals: 68
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #10 - Posted 2012-08-09 08:03:45 »

Looks good, I could use something like this for a space strategy thing I'm working on. I imagine it would be nice to generate randomized background nebulas before starting a new game, to make each galaxy feel unique. Thanks for the links!

Alternatively I'll just use edited NASA images, which also looks cool.

Online Roquen
« Reply #11 - Posted 2012-08-09 08:52:21 »

As a completely gratuitous side comment: I can't think of any reason to use simplex noise (vs improved gradient noise) if you're sampling function is less that 3D.
Offline philfrei
« Reply #12 - Posted 2012-08-09 09:53:47 »

Hi Roquen -

I kind of looked at this and that and couldn't really tell the difference, so I rolled the dice and chose Simplex rather than trying to stress it out.

My decision was mostly due to Stefan Gustavson's paper and implementation. I was very impressed with his paper. He claims Simplex has "fewer defects" in addition to being faster at 3D & up. He also claims his updated implementation (2012!) runs a bit quicker than Perlin's reference implementation. And, since his program emphasizes clarity, there seemed like more upside for possible optimizing if one wants to go down that rabbit hole for whatever reason.

I also just like the math behind Simplex. It seems very elegant, from my surface view.

Have you found the ImprovedNoise implementation to be superior in any regard? I have no experience really with either and am not locked in. I am all ears!

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Online Roquen
« Reply #13 - Posted 2012-08-09 09:59:44 »

The only issue here is that if you put equal working into an improved gradient vs. simplex (for 1D & 2D) then the gradient noise version should be faster and equal in quality...that's it.  With a working simplex noise there's zero reason to revisit improved gradient...even if performance issues pop up because you'd have to redesign all your stuff (different frequency contents between the two).  So my comment was really gratuitous (or informational depending on your perspective).
Offline Best Username Ever

Junior Member





« Reply #14 - Posted 2012-08-10 02:03:18 »

That looks great. I have a few requests.
1. Can you post more images of different skies and in a lossless image format?
2. Source code soon please? Smiley
3. If not can you post something showing the animation?
Online Roquen
« Reply #15 - Posted 2012-08-10 03:47:07 »

This was a helpful tutorial on using Simplex Noise, and it has an important link to a paper and free Java implementation (that I use) by Stefan Gustavson. The tutorial was written by JGO member ShannonSmith.
http://www.angryoctopus.co.nz/?p=11
Quickly scanned this article.  It would have been easier (and cheaper) for creating the planet image to calculate the 3D coordinate of the surface and use a 3D noise function instead of 2D.

If anyone plays with any 3D simplex noise, I'm curious how my implementation compares: http://www.java-gaming.org/topics/simplex-noise-3d/23962/view.html.  Also a post further down has a link to an alternate GPU version.

Offline philfrei
« Reply #16 - Posted 2012-08-10 07:13:05 »

@Roquen - Cool! I didn't realize you had written a version also. I might have passed over it when I saw 3D in the title, since I am still poking around with 2D, and then forgotten about it since I didn't add it to my "favorites" list. I'm truly impressed that you are able to tackle and write such code! I'm just at the level of using the function call of an existing reference copy.

Maybe we should have a page (is there already one?) dedicated to "Perlin" based references.

@BestUsernameEver - I've been busy writing and testing utilities for rotating and clipping the "GalaxyCloud" image. (This was my first time writing a basic 2D Transform program.) Since I'm just beginning with generating textures, I only know how to stretch vertically and horizontally and very much wanted the cloud to be at an angle in the sky. Also, I wanted the GalaxyCloud to display correctly (not spill over the edges) if the StarField display area is set to be smaller than the GalaxyCloud image. I couldn't figure out a way to both rotate and clip the image using Java's AffineTransforms--so resorted to writing versions that work on images rather than on the graphical space.

So, blah, blah, I've only used the rotator on this cloud, still haven't tried it on other images, so I don't know how good the algorithm is, and assume the code has a lot of room for improvement (constructive criticism gratefully accepted). But it seems to work okay.

I forgot that I'd have to write an enclosing applet to display the animation, and I'm beat. So for the short-term, I'll go ahead and post a jar you can download and run. It includes the source code.
http://hexara.com/Starfield/StarfieldTest.jar

Realize, the animation and randomizing do NOT include the GalaxyCloud moving around, nor Auroras or other possible cool stuff. That is yet to be built and if anyone wants to contribute or do their own, I'm happy. The animation doesn't have as many meteorites as it could, or twinkle as much as it could. But again, these things can be altered and can become settings of a more customizable version.

If you decide to try using the jar or code in a program, the main item is the StarField object. At this point the only things that can be specified:

1) dimensions and location of the rectangle in which it appears,
2) number of stars in that area,
3) it is possible to include a seed for the Random function if you want the same stars to appear every time. I'm unclear if this affects the meteorite sequence as well. Maybe it does.

Oh, I included a Timer for animation. The animation could also be done via a GameLoop.

I'll try to make a website that displays the animation soon, but might not get to it for a few more days.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Online Roquen
« Reply #17 - Posted 2012-08-10 07:57:11 »

Having a local wiki page on noise would probably be a very good idea.
Online princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #18 - Posted 2012-08-10 08:52:06 »

Having a local wiki page on noise would probably be a very good idea.
Well, you know what they say about suggestions...  Pointing

Cas Smiley

Online Roquen
« Reply #19 - Posted 2012-08-10 08:53:50 »

Stub is already in place. Tongue
Offline philfrei
« Reply #20 - Posted 2012-08-10 21:06:10 »

I've posted a web demo.
http://hexara.com/Starfield/

Links is also at the top of this thread, and runnable jar with source code link, too.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline _Al3x

Senior Member


Medals: 7


Indie Games FTW!


« Reply #21 - Posted 2012-08-10 23:42:47 »

Thanks for sharing, looks awesome! Smiley

Would you mind making the main post a little bit nicer? just for future reference and quick find for download link and the web demo Smiley

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #22 - Posted 2012-08-14 12:01:26 »

Are the 'nebula' generated too?

Endolf

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 131
Projects: 4
Exp: 3 years



« Reply #23 - Posted 2012-08-14 16:45:45 »

It's 'nebulae' (plural)
 Tongue
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #24 - Posted 2012-08-14 17:08:58 »

It's 'nebulae' (plural)
 Tongue

Whatever, the question still stands Smiley

Offline philfrei
« Reply #25 - Posted 2012-08-14 17:58:28 »

Quote
Are the 'nebulae' generated too?
Yes. The object is called GalacticCloud. At this point, the api is just a rectangular size, and the object returns a BufferedImage generated with a bit of Simplex noise and a utility I wrote to blend the edges to alpha = 0 (fully transparent). I then use another utility I just wrote to rotate the image slightly. All this code is in the jar, and folks are free to use it.

If anyone does, I'd be pleased to get a link to post so as to brag on my blog (in the works still) about writing code that is actually useful.  Smiley

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline OpenGLShaders

Junior Member


Medals: 4
Exp: 2 years



« Reply #26 - Posted 2012-08-30 00:14:04 »

Quote
<snip>All this code is in the jar, and folks are free to use it.

If anyone does, I'd be pleased to get a link to post so as to brag on my blog (in the works still) about writing code that is actually useful.  Smiley
I probably won't use the src, but I will use the inspiration! Looks amazing, and I am definitely going to put something like that in my game.
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #27 - Posted 2012-08-30 08:46:21 »

Quote from: philfrei
A while back dario3004 included a beautiful photo of a starry sky in a post. I recall asking him at the time if it was a graphic or procedural, and he said it was a NASA photo.

NASA? Not familiar with that algorithm, although it does spark my Curiosity...


Lame joke aside, when playing Freelancer, I always noticed how the skyboxes (starboxes) were carefully designed to reflect your position in the game's starmap (So if you took the jumpgate towards a distant green nebula, you'd end up finding said nebula). So when thinking about making a similar space exploration game, actually having a procedurally generated background based on the player's position is something I find very attractive and have mused about quite a bit.

So yeah, can't get enough of procedural sky generation  Grin

Offline philfrei
« Reply #28 - Posted 2012-08-30 09:44:50 »

@Oskuro -- For 3D, I'd give each star a Z coordinate to go with the X & Y, and instead of having two shapes for the twinkling, there would be a larger series of shapes for a given star, one of which would be selected based on distance.

I haven't taken the time to play around with 3D very much yet. But it seems quite doable, albeit with a lot of trig calculations. (I'm assuming there are known 3D techniques for optimizing that sort of thing which I have yet to learn.)

@OpenGLShaders -- Thank you. I look forward to seeing your game!

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (72 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (43 views)
2014-09-07 01:13:42

Longarmx (27 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!