Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Space Graphics Toolkit & Planets

Discussion in 'Assets and Asset Store' started by Darkcoder, Aug 18, 2012.

  1. broesby

    broesby

    Joined:
    Oct 14, 2012
    Posts:
    118
    Thx a bunch,.. I'll try later :p
     
  2. broesby

    broesby

    Joined:
    Oct 14, 2012
    Posts:
    118
    Forgive me... I'm not a very seasoned coder :-(

    I made an editable starfield copy and I found the public list/array of stars. What would be the easiest way to actually use all these positions to place 3d stars in a somewhat automated way??

    EDIT: Actually I'm fine with a starfield of only billboarded sprites.... Only issue is now: Why are my sprites transparent? I know it's to do with alpha or render queue. But I can't seem to figure out how to make them solid... :-(
     
    Last edited: Apr 16, 2015
  3. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    The starfield uses an additive blending shader which is why they're always transparent. Sprites normally use alpha blending, but changing this would require sorting the stars by camera distance every frame, which is very expensive to do.

    To spawn stuff at your stars in C#, you can use something like:

    Code (csharp):
    1.  
    2. foreach (var star in yourCustomStarfield.Stars)
    3. {
    4.     Instantiate(yourStarPrefab, star.Position, Quaternion.identity);
    5. }
     
  4. broesby

    broesby

    Joined:
    Oct 14, 2012
    Posts:
    118
    I'm sorry - not really a coder - hope you will bear with me :(

    So I made the editable starfield copy . in your example = yourCustomStarfield, I suppose?

    Then I made a small new C# script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class star : MonoBehaviour {
    5.  
    6.    
    7.     void Start () {
    8.    
    9.         foreach (var star in SgtCustomStarfield.stars) {
    10.                         Instantiate (probe.prefab, star.Position, Quaternion.identity);
    11.                 }
    12.     }
    13.    
    14.    
    15.     void Update () {
    16.    
    17.     }
    18. }
    ... and added it to the same gameobject as SGTCustomStarfield script is... OFC compiler error: No definition for "stars".

    I know I do this totally wrong. Just hope you would help me get it right -sry for being newb :confused:
     
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    Your code doesn't work because 'Stars' is both upper case, and is an instance field, but you're trying to access it like it's a static field.

    Your foreach loop should instead look something like this:

    Code (csharp):
    1. foreach(var star in GetComponent<SgtCustomStarfield>().Stars){
    Alternatively, you could add a public SgtCustomStarfield reference to your 'star' class, and drag and drop it in the inspector, then access it like I described before.
     
  6. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    192
    I'm trying to make some procedural planet maps using substance designer but I'm still working on making them look good. I might put them up on the asset store if they turn out any good.
     
    Darkcoder likes this.
  7. broesby

    broesby

    Joined:
    Oct 14, 2012
    Posts:
    118
    Thx,... Worked like a charm :p

    Do you have an idea how I could make each instantiated prefab have a unique name instead of just "prefab(clone)"??
    Or perhaps add an unique variable to each one. I know there i Object.GetInstanceID or something like that... But that number changes when you reload the scene.

    I need each star to be unique to add functionality to it - I will do that with playmaker but before I can do that I need them to be different from eachother :cool:

    TYVM, Jesper, Denmark
     
  8. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    You can set the 'name' property on the new GameObject that gets returned from Instiantiate. You should probably ask on the Unity IRC channel for basic questions like this, or just experiement yourself while looking through the scripting reference: http://docs.unity3d.com/ScriptReference/
     
  9. Liviuss

    Liviuss

    Joined:
    Apr 2, 2014
    Posts:
    101
    Last edited: Apr 17, 2015
  10. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    Your SgtAccretionDisc's 'Dust Tex' texture must have the 'Wrap Mode' set to 'Repeat'
     
  11. Liviuss

    Liviuss

    Joined:
    Apr 2, 2014
    Posts:
    101
    Yep, my bad, thanks!
     
  12. kzaurckichz

    kzaurckichz

    Joined:
    Nov 5, 2013
    Posts:
    52
    Is there a way to set a specific 8192x8192 Heightmap on all 6 faces individually instead of the global spherical map ?
    My guess is I would have to add a heightmap field to SgtPatch to bypass the global heightmap for each face, similar to the Material field..
    Do you have any suggestion on how to proceed ?
    Thank you.
     
  13. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    The easiest method is to modify or duplicate the SgtDisplacedTerrain component, and modify the GetSurfaceHeightLocal method to sample your heightmaps instead of sampling the spherical map. You could also modify the SgtPatch component as you say, which would require you to modify the SgtPatchBuilder's GenerateMesh method on line 84 to sample your patch heightmap using the coordB & coordT variables from line 93 & 94.
     
  14. raydekk

    raydekk

    Joined:
    Mar 14, 2013
    Posts:
    100
    Hey Darkcoder,

    Quick question: How can you create a custom starfield from code?
    For example, creating a new empty game object, then adding the custom script component (with no stars) and then inserting stars through code something like:

    SgtStarfieldStar x = new SgtStarfieldStar();
    x.Radius = 10;
    x.Color = Color.red;
    x.Position = Vector3.zero;

    starScript.Stars.Add(x);
     
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    You need to call:

    Code (csharp):
    1. starScript.MarkMeshAsDirty();
    Which will then update the mesh at the next LateUpdate.
     
  16. SiBlack

    SiBlack

    Joined:
    Jun 12, 2013
    Posts:
    22
    Thought I better let you know that the Jovian and Ring components still go see through when reducing the ambient intensity;
    Unity5.0.1, deferred rendering, Linear.
     
  17. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    Did you upgrade to SGT 3.1.0? Because I can't replicate this issue any more.
     
  18. BES

    BES

    Joined:
    Feb 26, 2013
    Posts:
    212
    The new planets seem to be way different than before ...
    Displaced Terrain ... does it require 6 materials?... I cant use just one? ...like the old tessellator?

    The old planets I would build the terrain in L3DT(terrain generator) ..use it for the main wrapped texture(norm,spec,detail), then add the surface tessellator, surface tessellator collider, and surface displacement ... it seemed to work fine..

    Now I am scratching my head on the new planets...any plans on explaining in more detail the Displaced Terrain? ...the PDF for it is like less than half a page..
     
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    If you set a material in the SgtDisplacedTerrain component then it will automatically propagate to the children. However, I removed the ability to write spherical texture UVs (due to complexity), so it's easiest if you convert your spherical textures into cube faces and create 6 materials (this tool comes with SGT). If you really want to use a single spherical texture then you'll have to use a shader that calculates them, but I imagine it will produce artefacts around the seams.
     
  20. BES

    BES

    Joined:
    Feb 26, 2013
    Posts:
    212
    Ok ... so why isn't the gravity working when I add it to my ship and to the planets? ...can you explain how it works to see if I am doing it right? ...
     
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    Look at the 'Gravity' demo scene. You just attach a GravitySource to your planet, then a GravityReceiver to your spaceship that has a rigidbody and it should work. You may have to play with the settings to get the gravity to be strong enough though.
     
  22. BES

    BES

    Joined:
    Feb 26, 2013
    Posts:
    212
    Hmm... it is as simple as I thought ..... but my ship seems to be unaffected.... the settings are crazy high.. and still the ship flies around without being pulled by anything..

    Example:
    Main Planet Mass 100000
    Moon Mass 50000
    Sun Mass 1e+07

    and I have a 50 mass space ship with a gravity receiver attached to it ...angular drag 5, drag 2 ...

    I also have a piece of code attached to the ship that is supposed to align the ship to the moon and main planet for landing but those don't seem to work either..

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AlignShip : MonoBehaviour
    5. {
    6.     public float rotationSpeed = 3f;
    7.     public float alignDistance = 200f;
    8.     public Transform planet;
    9.  
    10.     private Quaternion targetRotation = Quaternion.identity;
    11.     void FixedUpdate()
    12.     {// align to planet surface
    13.         if (planet != null)
    14.         {
    15.             float distanceToPlanetCore = Vector3.Distance(transform.position, planet.position);
    16.             //Debug.Log(distanceToPlanetCore);
    17.             if (distanceToPlanetCore < alignDistance)
    18.             {
    19.                 Vector3 gravityVector = planet.position - transform.position;
    20.                 targetRotation = Quaternion.LookRotation(transform.forward, -gravityVector);
    21.                 transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.fixedDeltaTime * rotationSpeed * 3f);
    22.             }
    23.         }
    24.     }
    25. }
    26.  
     
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    I imagine one of your other scripts is interfering with the gravity. Maybe you can try disabling the other scripts to see what's going on?
     
  24. WarpBubble

    WarpBubble

    Joined:
    Dec 4, 2013
    Posts:
    33
    Any luck with the SgtObserver problem? The same issue seems to be affecting my stars when it comes to the "Stretch To Observers" option.
     
  25. BES

    BES

    Joined:
    Feb 26, 2013
    Posts:
    212
    I have gravity in the scene set to zero ....to I actually need to turn it off via code? ...since gravity still doesn't seem to work...I have tried a lot of things ...even revamping my whole scene and correcting some scripting errors ...still no gravity..
     
  26. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    I fixed the thrusters rotating to the wrong observer issue, but it looks like I forgot to submit it, oops. I still need to fix the thruster raycasting issue, so I'll send you a build as soon as I fix it. Also, I can't seem to find any issue with the Stretch To Observers? HERE's a screenshot showing two observers with different speeds, and it seems to render as expected.

    [Edit] I've fixed the raycast issue, but you seem to have converations disabled, so I can't PM you the build.


    Setting it to 0 should be fine. The gravity code itself is rather simple, so I'm not too sure what the issue could be. Does the 'Gravity' demo scene work fine? If so, maybe you can try modifying it to more closely match your scene and see where it starts to break.
     
    Last edited: May 1, 2015
  27. driconmax

    driconmax

    Joined:
    Jan 25, 2015
    Posts:
    5
    Captura de pantalla 2015-05-07 23.39.03.png
    I have this problem. The Moon texture repeats 6 times. Do i have to create the XYZ (+/-) textures? How can i do it?
     
  28. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    You can generate the 6 textures by first making a Cubemap in Unity, then using the Cubemap face extraction tool that comes with SGT (see the documentation for how to use this). I also plan to write an alternative planet shader that takes spherical textures. Though the cube face approach is probably more efficient.
     
  29. zulubo

    zulubo

    Joined:
    Mar 1, 2014
    Posts:
    4
    I was wondering how to go about making stars visible in the night sky of a volumetric atmosphere? I saw that it was done in the web demo, but in my project the sky is just bluish black. Something like additive rendering for the atmosphere so that it doesn't block them. Also, making a moon visible in the daytime sky like our moon? Can you give me a pointer on the settings required to do this?

    EDIT:
    note I'm using unity 5, so it may be something about that. I downloaded the solar system pack and the same thing was happening.
     
    Last edited: May 11, 2015
  30. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    You can adjust the opacity of your atmospheres
    You can make the dark side of a planet's atmosphere transparent by adjusting the alpha level in the 'Lighting Brightness' gradient. For example if you open up the Earth demo scene, you can select Earth and open the Lighting Brightness gradient and change the top right alpha node to 0.0, and the dark side will be transparent.

    However, as you notice the atmosphere uses alpha blending and it's not possible to have a solid atmosphere color and also show the moon or similar (at least without changing the render queues manually). Using additive blending would indeed allow this, and it would be more realistic, but it would also only work properly in specially designed HDR scenes, and it would make setting things up a lot more complicated, and not work on many mobile devices, etc.
     
  31. kulesz

    kulesz

    Joined:
    Jul 1, 2012
    Posts:
    138
    Hello,

    I'm trying to achieve a specific effect with your package and I have some difficulties.
    I have a static star background (EllipticalStarfield with a 'Follow observers' ticked). It works great - background doesn't move as I rotate and move camera (imitates very far background).
    Now I'd like to have a 'stretched stars warp effect', when my camera gets faster and the view blurs. However when I enable 'stretch to observers' the stars change shape, but don't move. To achieve dynamic effect I need to use WrappedStarfield, but I cannot synchronize them - same size and seed does not change background seamlessly from Elliptical to Wrapped (and back). Stars looks different in those two kinds of starfields.
    Is there any chance to fix this?
     
  32. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    The WrappedStarfield component generates a box of stars (and wraps them around using a box shape), whereas the EllipticalStarfield component generates a sphere/ellipsoid of stars, so there is no way to directly map them across.

    If I understand your scenario correctly, you should be able to just use a WrappedStarfield with the FadeNear setting, and it should look pretty much the same as a background EllipticalStarfield. If you look at the 'Infinite Starfield 3D Warp' demo scene, then you can see how I mix two starfields with the same seed so it looks good when static, and when moving.
     
  33. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    Your asset has vastly improved the visual quality of my early prototype within minutes!

    http://gfycat.com/NervousNewCoot

    Note that the game is 2D - I couldn't really think of how to incorporate some of the other stuff in a 2D game, so if you have any ideas then let me know :)
     
  34. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    Looks great, you can definitely incorporate the infinite dust and maybe some 3D warp star fields to add more sense of speed. For games like this I also like to place stars and planets behind the main scene, so you can fly over them, but not crash into them. Good luck with the game!
     
  35. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Does anyone know if there are any playmaker scripts for SGT? Or does anyone know how to change the alpha on a SGT object, I'm having trouble getting the material in the hidden folder.
     
  36. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    All transparent SGT materials (e.g. Jovian, Ring) have the 'Color' setting, which you can adjust from the relevant component inspector. So to change the alpha you just need to adjust the alpha of the color, and you can fade it in/out. I don't know of any Play Maker binding for the latest version though.
     
  37. phoenixrising

    phoenixrising

    Joined:
    Aug 9, 2013
    Posts:
    57
    Hi, firstly, I love your toolkit!!!
    But I cannot understand why on the default Earth Clouds it is taking up 32 megs for a png which is <500k?
    This is probably more of a unity question then specific to your toolkit, but I figured you would have someinsight on how to shrink the size??

    Screen Shot 2015-06-17 at 1.31.24 PM.png Screen Shot 2015-06-17 at 1.31.37 PM.png
     
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    PNG is a compressed file format (not that it matters, as your final build will not include the original files), and that texture in question is loaded as Automatic Truecolor, which requires 4bytes of data per pixel. To save memory, use less pixels, or use a format that requires less data per pixel.
     
  39. driconmax

    driconmax

    Joined:
    Jan 25, 2015
    Posts:
    5
    Sin título32.png
    Still not working, i have the 6 textures and the original, then i did a new material (Unlit/Texture) and put it in the sgt displaced terrain. Can you make a video tutorial or something more detailed? Because i follow the steps in the pdf and it doesn't work.
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    There are 6 child GameObjects of the DisplacedTerrain, each with their own Material property. You have to make 6 materials, one for each side, and apply them to these children, and it will work fine. Right now you're using the same material (thus the same 1 of 6 texture face) across all 6 sides, so it looks wrong.
     
  41. driconmax

    driconmax

    Joined:
    Jan 25, 2015
    Posts:
    5
    I apply the texture to the children, but when i hit play the 6 texture faces auto-resets.
    Moon1.png

    Moon2.png
     
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    You probably have to set the Displaced Terrain's Material slot to null/none, else it will automatically propagate to the children.
     
  43. driconmax

    driconmax

    Joined:
    Jan 25, 2015
    Posts:
    5
    I set Displaced Terrain's Material slot to null/none this make the "moon" all purple, then i put the 6 materials in the children and the main in the slot but same thing when i hit play i have the main texture 6 times.
     
  44. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    Can you create a package with this scene, textures, materials, and PM or e-mail it to me?
     
  45. driconmax

    driconmax

    Joined:
    Jan 25, 2015
    Posts:
    5
    I sent you a message to you with the package!
     
  46. MadMapp

    MadMapp

    Joined:
    Nov 15, 2012
    Posts:
    49
    hi, i bought this asset a while back, look fantastic, went to put it in to my new project, and missing alot of the older demo scenes, i was specificly looking for the asteroid with the fog in the crevices, any way, links sent me here to find what are now called free assets, where should i be looking to find all the old examples?
     
  47. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    Although I remade many of the old demo scenes, the infinite asteroid one (I think that's what you're referring to) no longer exists. This is mainly because I didn't rewrite the debris spawner component for SGT 3, but I'll see if I can update it and put it in the next version.
     
  48. kzaurckichz

    kzaurckichz

    Joined:
    Nov 5, 2013
    Posts:
    52
    I am about to add this feature myself for a game I'm working on.
    Can you tell me any insight that may help me start ?
    I'm looking especially at making voxel asteroids.
    I thought that to easily get their positions to change them into game objects, it would be as simple as using the same algorithm it uses in the shader, but in a CSharp script and fill a placeholder array.. Should reproduce the positions exactly.. What do you think ?

    Also, here's something I came up with that people asked for and you didn't include yet :
     
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,406
    Yes, that's the method I thought of. The asteroids just orbit in circles, so you just need to rotate them around the X/Z axis based on the time, their orbit speed, and the initial orbit angle.

    However, because the asteroids orbit at different speeds I can't think of an easy way to find which asteroids are currently near you without calculating them all at the same time, which sounds slow for large asteroid rings.
     
  50. kzaurckichz

    kzaurckichz

    Joined:
    Nov 5, 2013
    Posts:
    52
    Actually I forgot to mention, I don't use your orbit system for the asteroids since the gas giant has a 3000 KM diameter, hence if the asteroids rotate around it they actually skip by kilometers at a time.
    In my case the orbits are actually very complex but I only need their initial positions.

    However, I think I will be doing it from scratch like I always do since nothing that exists in this world seams to ever fit my very specific needs for this game.
    Unless you have another solution ?
    Thank you.