Jump to content


Photo

3d Star Map Using A D3d Model Filled


  • Please log in to reply
22 replies to this topic

#1 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 10 October 2009 - 06:35 AM

Download 3dStarMap.gmk Last Update May 09, 2010, 1:10 AM


This method for generating 3d star fields was originaly shown to me by Tepi... Thanks man.
I added 2d star field since the method is the same.
I added a warp field star map, a la Star Trek TNG style

Posted Image
Posted Image

The method consist of generating a 3d model using triangles that face the centre of the model.
Each triangle is located at a random distance from the centre of origin, each triangle displays a star from a texture.

The model is usually drawn at the location of the player.

Most of us have been brainwashed to make a square/plane with 2 triangles and set up the uv of the 2 triangle to display a texture... But this can be done using a single triangle as long as all the data resides in a triangle on the texture. Sure, a waste of space on the texture, but not a waste of space in the 3d model.

In this case, the system is smart enough to map multiple uv triangles from the texture for use by the multitude of 3d facets in charge of displaying the stars in the 3d world. So no space is wasted on the texture and a variety of stars can be displayed by the model. You can even animate the sprite if you want.

The system uses vertAPI2 to calculate the proper orientation and positions of the triangles

The function is
MakeStarMapModel(numstars, inerradius, outerradius, mizsize, maxsize, xshape, yshape, zshape, numcels):

numstars, number of stars
inerradius, radius where the stars start
outerradius, radius where the stars end
minsize, min star radius
maxsize, max star radius
xshape, shape, 0 (plate) to 1 sphere to 2 or more (egg)
yshape, shape, 0 (plate) to 1 sphere to 2 or more (egg)
zshape, shape, 0 (plate) to 1 sphere to 2 or more (egg) .5 would flatten the sphere. .05 would be like our milky way
numcels, 2 for 2 stars like Template2Large, 4 for that 4x4 template, 8 for that 8x8 template and so on


I have included a few sprites in there, just change the sprite used in the create of the StraMapObj and the numcels parameter


Running in power saver mode, the field of 1000 stars displays at 500 fps on my laptop.

BUG:
If you make the stars large enough, there is an overlap of the triangles over further stars; there is what seems to be a flaw somewhere. The black area (it's pure black and the stars are drawn with bm_add) shows dimly over the distant stars, as if the black was not pure black and even acting like bm_subtract, dimming the stars behind it... Fixed using alpha mask

UPDATE
Warp Field functions

UPDATE
Add 2d star field functions

UPDATE
Followed Tepi's advise,

Added MakeStarMapModelTrueCol, same params, use a grayscale image for texture, the colors will be added to the model data, using the 7 common colors specified in by web site referenced by Tepi. FPS is 400, compared to 550

Added true color stars template... using 7 colors + one color duplicated, it's a color that is most common so it turned out right. So you can be back to that 550 FPS. the result is almost identical to the new function using the original function

Demo now places all stars at same distance, only the triangle size varies. So you can't really walk through the stars, which was never intended anyway. You loose perspective, which would be very minute in real world anyway. But the ability is still there via the parameters to the function in case you want some other wordly packed stars like the original demo

Added image alpha mask, and uses set_alpha_from sprite. this fixes the BUG above

Removed the original crappy texture with the odd star colors...

Added a tiny motion to the stars, so they seem to shimer, varying in intencity due to pixelation as well as the original dual draw method...

UPDATE
The default is now varying distance and constant size... The effect with the offset drawing and pixelation makes the stars glitter more, like atmospheric distortion.

Edited by icuurd12b42, 09 May 2010 - 05:26 AM.

  • 1

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#2 T-Bird

T-Bird

    GMC Member

  • New Member
  • 1326 posts

Posted 10 October 2009 - 06:47 AM

Didn't DL it. But reading it that's a very good point, there isn't always a need for more than one triangle, especially when using transparent textures. I wonder if it's more efficient to do billboards like trees and grass as a single triangle or as a transformed sprite?
  • 0

#3 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 10 October 2009 - 07:07 AM

Didn't DL it. But reading it that's a very good point, there isn't always a need for more than one triangle, especially when using transparent textures. I wonder if it's more efficient to do billboards like trees and grass as a single triangle or as a transformed sprite?


As in do the transform and draw the sprite vs do the transforms and draw a triangle (1 facet) model with the texture? I would venture a guess and say no but probably not by much.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#4 T-Bird

T-Bird

    GMC Member

  • New Member
  • 1326 posts

Posted 10 October 2009 - 07:16 AM

I meant more along the lines of having no transform and just drawing the triangle in it's desired position. Although I was forgetting that many billboard effects rotate to face the camera, so since you require a transform then the triangle has lost it's advantage. If your billboards aren't going to be rotating, then just drawing a triangle in the orientation and texturing it *should* be faster. Then too animating the texture on the triangle isn't as easy as just drawing a sprite.

Anyway, I'll keep the technique in mind and some day I'll get around to doing some tests.

Edited by T-Bird, 10 October 2009 - 07:18 AM.

  • 0

#5 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4248 posts
  • Version:GM:Studio

Posted 10 October 2009 - 02:56 PM

Good idea to make an example about this. Now this kind of scene can be used also by those who don't know how to properly set up a system like this.

There are, however, some things that I don't like too much.
  • There doesn't need to be any change in the distance of the star... doing it this way just screws up the mathematical value of defining the star size limits.
  • The colors of the stars are (intentionally?) exaggerated. Try to keep the colors realistical and decrease the saturation. This will make the stars look really realistical (in the example model you got through the planet movement system, some stars appeared brightly teal. I have no idea why they transformed into that as they were the right color at the point when they weren't saved into a model file... a gm6 bug, perhaps.)
  • The distribution of the star sizes should not be even close to linear. There exists 120 stars with the apparent magnitude in the interval [2,3], but only four of which apparent magnitude is smaller than 0.
Also, would you mind explaining me what the:
//random direction;
	xx = (random(1)-.5) * xshape;
	yy = (random(1)-.5) * yshape;
	zz = (random(1)-.5) * zshape;
part in the generation code is supposed to do?


In case anyone wants the real stars, forming the known constellations and such, construct a script that reads a star catalog (can be found and sorted here) and generate the model accordingly or PM me.
  • 0

#6 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 10 October 2009 - 11:17 PM

Good idea to make an example about this. Now this kind of scene can be used also by those who don't know how to properly set up a system like this.

There are, however, some things that I don't like too much.

  • There doesn't need to be any change in the distance of the star... doing it this way just screws up the mathematical value of defining the star size limits.

I wanted the ability to have bigger stars further away from nearer stars so the perspective would be preserved...

I could have
1) Places all the stars at the exat same distance and play with only the triangle size or
2) like you original model, use the distance to define the size/radiance

In anycase, the script permits both as you have control over the min max distance and min max size, use values that place everything on at the same distance and only use size to change the size... or do the oposite. give a distance range to play with but set the size params to keep all the stars the same size.

See update info in first post

  • The colors of the stars are (intentionally?) exaggerated. Try to keep the colors realistical and decrease the saturation. This will make the stars look really realistical (in the example model you got through the planet movement system, some stars appeared brightly teal. I have no idea why they transformed into that as they were the right color at the point when they weren't saved into a model file... a gm6 bug, perhaps.)


  • Good. I needed that... After having spent 2 hours making the grayscale texture, I attempted to colorise the stars properly, but paint.net would not do it right... +I did not have the true stars color. After 3 hours, I gave up and used what I had. Basically, it was to show how to do it. To show you can place all the stars of various colors on the texture.

    I was tempted to use color_alpha params to change the color... I think I'll ad another script for that. But I think the resulting model is slower to draw.

    Using multiple images on the same texture allows you to define star clusters or galaxy images in the texture as well as having contro over how each star type shine... eg round, or cross or x patern like.

    See update info in first post

  • The distribution of the star sizes should not be even close to linear. There exists 120 stars with the apparent magnitude in the interval [2,3], but only four of which apparent magnitude is smaller than 0.

  • Also, would you mind explaining me what the:
    //random direction;
    	xx = (random(1)-.5) * xshape;
    	yy = (random(1)-.5) * yshape;
    	zz = (random(1)-.5) * zshape;
    part in the generation code is supposed to do?

    originally, I had direction = random 360 and elevation = random 360. But that glustered the stars at the top zand bottom of the sphere. So I opted for the more linear distribution method... the *shape is used to flatten the sphere. zshape 0 would give a flat disk, .2 would look more like our milky way (viewed from us... It's not real world real though.

    In case anyone wants the real stars, forming the known constellations and such, construct a script that reads a star catalog (can be found and sorted here) and generate the model accordingly or PM me.


    I'll add the ability in there if I have time... I can see how useful it would be. But for sure I'll grab that color info and try to make a proper texture and possible another script that makes random stars using one image + true colors...

    See update info in first post

    [edit]
    I have trouble figuring out the data files... You know where they are documented. And so many varying sources. Your suggestion on which file to use would be great.

    I'd like one from our perspective and I think I saw one from the perspective of the center of our galaxy

    Edited by icuurd12b42, 11 October 2009 - 01:14 AM.

    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #7 fredcobain

    fredcobain

      GMC Member

    • GMC Member
    • 165 posts

    Posted 11 October 2009 - 09:44 PM

    Beautifull!! I liked it!!
    =)


    Congratulations!
    • 0
    I am an Posted Image in the GM Quiz!

    #8 Tepi

    Tepi

      GMC Member

    • Global Moderators
    • 4248 posts
    • Version:GM:Studio

    Posted 12 October 2009 - 12:57 PM

    [edit]
    I have trouble figuring out the data files... You know where they are documented. And so many varying sources. Your suggestion on which file to use would be great.

    I'd like one from our perspective and I think I saw one from the perspective of the center of our galaxy

    I used the Hipparcos main catalog (in Firefox do ctrl+F and search for Hipparcos and it should be the first one found). I didn't know for sure that 3-dimensional data about the star positions could be found but after a quick search apparently there is possibility for that. (However, you do understand you can't dynamically choose a viewpoint between triangular stars without seeing them as triangles.)

    The link to the ASCII file (hipparcos.xyz) is found here (this also contains direct link to the Hipparcos and Tycho catalogues). It contains the cartesian coordinates for each star (113710 of them ?) as well as the calculated errors for them. Pretty neat, huh? Now I don't know whether they are sorted according to the magnitude, but I don't think you're going to need all 113710 of them. :) As for the main catalog, it can be sorted in the viewer (and chosen how far the list goes).

    I'll check out the new version later.

    EDIT: Oh and almost forgot to mention, the coordinates are supposed to be around Sun. I really doubt that technology has evolved far enough for constructing a 3-dimensional star catalog from the center of our galaxy. :P

    Edited by Tepi, 12 October 2009 - 01:05 PM.

    • 0

    #9 icuurd12b42

    icuurd12b42

      Self Formed Sentient

    • GMC Elder
    • 18181 posts
    • Version:GM:Studio

    Posted 12 October 2009 - 08:59 PM

    [edit]
    I have trouble figuring out the data files... You know where they are documented. And so many varying sources. Your suggestion on which file to use would be great.

    I'd like one from our perspective and I think I saw one from the perspective of the center of our galaxy

    I used the Hipparcos main catalog (in Firefox do ctrl+F and search for Hipparcos and it should be the first one found). I didn't know for sure that 3-dimensional data about the star positions could be found but after a quick search apparently there is possibility for that. (However, you do understand you can't dynamically choose a viewpoint between triangular stars without seeing them as triangles.)

    The link to the ASCII file (hipparcos.xyz) is found here (this also contains direct link to the Hipparcos and Tycho catalogues). It contains the cartesian coordinates for each star (113710 of them ?) as well as the calculated errors for them. Pretty neat, huh? Now I don't know whether they are sorted according to the magnitude, but I don't think you're going to need all 113710 of them. :) As for the main catalog, it can be sorted in the viewer (and chosen how far the list goes).

    I'll check out the new version later.

    EDIT: Oh and almost forgot to mention, the coordinates are supposed to be around Sun. I really doubt that technology has evolved far enough for constructing a 3-dimensional star catalog from the center of our galaxy. :P



    Cool, I'll go back to it soon. I'm making a rain and snow system using the same method...

    As for the stars relative to center of galaxy. I misread this link
    3. 1011 Proper Motions of 8790 Stars with Ref to Galaxies (Klemola+ 1971)



    Looks like I have to combine a few files to figure the right color and intensity.

    http://en.wikipedia....Russell_diagram

    Edited by icuurd12b42, 12 October 2009 - 09:31 PM.

    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #10 sub

    sub

      EVIL GENIUS

    • GMC Member
    • 1905 posts
    • Version:GM6

    Posted 24 February 2010 - 11:25 PM

    i tried making my own starmap before i got to this..

    i had an array store the x,y,z locations [just random].. i was drawing them as little floor shapes high in the sky.. it looked ok, but the ones that were outside the room dimensions didn't seem to draw [is that an inbuilt GM thing?]
    • 0

    #11 icuurd12b42

    icuurd12b42

      Self Formed Sentient

    • GMC Elder
    • 18181 posts
    • Version:GM:Studio

    Posted 25 February 2010 - 02:50 AM

    i tried making my own starmap before i got to this..

    i had an array store the x,y,z locations [just random].. i was drawing them as little floor shapes high in the sky.. it looked ok, but the ones that were outside the room dimensions didn't seem to draw [is that an inbuilt GM thing?]


    no. maybe they were too far to be seen. the room has no effect on the drawing, the view does though on tiles and objets with no draw event on some/most cards things are not drawn ouside the view for most people

    Edited by icuurd12b42, 25 February 2010 - 02:50 AM.

    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #12 rinkuhero

    rinkuhero

      Paul Eres

    • GMC Member
    • 1919 posts
    • Version:GM:Studio

    Posted 26 April 2010 - 04:11 AM

    very pretty

    i noticed a large number of very short scripts in this example -- things like

    with(argument0)
    {
    	return ds_list_find_value(Zs,argument1);
    }
    return -1;

    wouldn't it be faster (at least in gm7) to just copy and paste that in when you need it, rather than having such short scripts (with a lot of script-calling overhead)?

    also, i know nothing about 3d programming in gm, so this may be a naive question, but would it be possible to use this star field in 2d mode, just displaying it over the game graphics, as a type of special effect or background? or is this only something that's usable in 3d mode?
    • 0

    #13 icuurd12b42

    icuurd12b42

      Self Formed Sentient

    • GMC Elder
    • 18181 posts
    • Version:GM:Studio

    Posted 26 April 2010 - 05:54 AM

    very pretty

    i noticed a large number of very short scripts in this example -- things like

    with(argument0)
    {
    	return ds_list_find_value(Zs,argument1);
    }
    return -1;

    wouldn't it be faster (at least in gm7) to just copy and paste that in when you need it, rather than having such short scripts (with a lot of script-calling overhead)?

    That is from the vertAPI interface. the scripts hide the implementation, the vertices are stored in an instanced that holed a fiew variables and a few ds_list (for the x,y,z vertices)

    also, i know nothing about 3d programming in gm, so this may be a naive question, but would it be possible to use this star field in 2d mode, just displaying it over the game graphics, as a type of special effect or background? or is this only something that's usable in 3d mode?


    You can use the same method in 2d, however, you would not need the vertAPI stuff. Just make a model with random (right angled) triangles, random sizes at random position in the room. The model generator script shows how to select a portion of the texture and define triangle properly uv mapped. Just remove the sphere code and the code that flips the triangles towards the center of the sphere.

    I actually discussed this in another thread.
    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #14 icuurd12b42

    icuurd12b42

      Self Formed Sentient

    • GMC Elder
    • 18181 posts
    • Version:GM:Studio

    Posted 01 May 2010 - 02:55 AM

    I added 2d star field since the method is the same.
    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #15 rinkuhero

    rinkuhero

      Paul Eres

    • GMC Member
    • 1919 posts
    • Version:GM:Studio

    Posted 01 May 2010 - 03:30 AM

    I added 2d star field since the method is the same.


    very nice. you forgot to update the 'last updated date' though.
    • 0

    #16 Endorel

    Endorel

      GMC Member

    • Banned Users
    • 191 posts

    Posted 01 May 2010 - 03:30 AM

    Was this made with GM7 or GM8? I only have GM7. It always takes me a while to upgrade my things. So anyway, can you post a screenshot please? Thanks man!

    Edited by Endorel, 01 May 2010 - 03:31 AM.


    #17 icuurd12b42

    icuurd12b42

      Self Formed Sentient

    • GMC Elder
    • 18181 posts
    • Version:GM:Studio

    Posted 01 May 2010 - 03:36 AM

    I added 2d star field since the method is the same.


    very nice. you forgot to update the 'last updated date' though.


    Done

    Was this made with GM7 or GM8? I only have GM7. It always takes me a while to upgrade my things. So anyway, can you post a screenshot please? Thanks man!


    Download it. It's gm7. A screen shot is comming.
    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #18 rinkuhero

    rinkuhero

      Paul Eres

    • GMC Member
    • 1919 posts
    • Version:GM:Studio

    Posted 01 May 2010 - 05:25 AM

    btw, it's not mentioned in the thread, but what is the "license" for this script and the included graphics files? i.e. are we free to use this script and those files in commercial games (like with your sound library)? i just tried it in my current game (for the intro background when 'new game' is selected) and it looks pretty nice there. i gave it a slight rotation too. also, currently i'm only using a model generated by this script rather than creating a new model within the game, but i am using the graphic files too and was wondering if that's okay, or if i should make my own.

    Edited by rinkuhero, 01 May 2010 - 05:26 AM.

    • 0

    #19 icuurd12b42

    icuurd12b42

      Self Formed Sentient

    • GMC Elder
    • 18181 posts
    • Version:GM:Studio

    Posted 01 May 2010 - 06:47 AM

    The file has nothing 3rd party, I made everything in it including the sprites so feel free to use it.

    eg: "Like your sound library", for comercial games, unlike the sound library, there are no licencing needed for this, where as fmod you need at least a fmod hobbiest license <which I was able to re-instate> if you sell your product.

    Edited by icuurd12b42, 01 May 2010 - 06:51 AM.

    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #20 rinkuhero

    rinkuhero

      Paul Eres

    • GMC Member
    • 1919 posts
    • Version:GM:Studio

    Posted 01 May 2010 - 07:46 AM

    understood, thanks

    if you're curious, here's a video i just made of the game's intro, with this star effect used (star effect begins at 38 seconds in):

    http://www.youtube.c...h?v=6Py9VksvCsI
    • 0

    #21 icuurd12b42

    icuurd12b42

      Self Formed Sentient

    • GMC Elder
    • 18181 posts
    • Version:GM:Studio

    Posted 01 May 2010 - 03:25 PM

    Ah great stuff. Looks cool and the game looks very nice too!
    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #22 icuurd12b42

    icuurd12b42

      Self Formed Sentient

    • GMC Elder
    • 18181 posts
    • Version:GM:Studio

    Posted 09 May 2010 - 05:24 AM

    Added warp field. The method could be used for 3d rain as well. The model is a series of 2 crossed triangles so to be seen from all sides (except dead on). The animation draws a stack of models, or sequence, one after the other while reseting the position back to 0 with modulus on z, z mod (the size of the model)...

    Basically, the demo creates a 2000 deep model. the z is modulus 2000 so it's alsways drawing from 0 to 2000 and it resets it's position. I also draw the model 4 more times, 2 above and 2 below so not to see the end of the field. Since it's the same model, you dont see the z reset.

    Edited by icuurd12b42, 09 May 2010 - 05:58 AM.

    • 0

    gmcbanner.pnggmcbanner_tools.png

    ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

    I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
    Now I'm squirming not to hit that reply button


    #23 raisins

    raisins

      GMC Member

    • GMC Member
    • 349 posts
    • Version:GM:Studio

    Posted 07 December 2014 - 11:19 PM

    This is amazing!


    • 0

    fxYmZ6o.png

     

    Visit my blog for GM tutorials and more! Ask.fm me a question! :D

     

    kWb6ZYf.png  Vd9fN4l.png