Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Build a Realistic Sphere  (Read 2114 times)

0 Members and 1 Guest are viewing this topic.

azoundria

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Build a Realistic Sphere
« on: January 05, 2014, 07:44:48 pm »
I am currently able to build nice beautiful circles like this:

void resetPlanetVertexes (sf::VertexArray* planet, sf::Vector2f* center, float size, sf::Color* color)
{
        int i;
        int count = (int)(planet->getVertexCount());
        for (i = 1; i < count-1; i ++) {
                float angle = ((float)(i) / (float)(count-2) * 360.f) * 3.14f / 180.f;
                ((*planet)[i]).position = *center + sf::Vector2f(
                        (float)(std::cos(angle) * size),
                        (float)(std::sin(angle) * size)
                );
                ((*planet)[i]).color = *color;
        }
        ((*planet)[count-1]).position = ((*planet)[1]).position;
        ((*planet)[count-1]).color = ((*planet)[1]).color;
}

void buildPlanet (sf::VertexArray* planet, sf::RenderWindow* window)
{
        int width = (int)(window->getSize().x);
        int height = (int)(window->getSize().y);
        sf::Color planetcolor = getPlanetColor();
        float size = getPlanetSize();
        std::cout << "Planet Size: " << size << std::endl;
        sf::Vertex* planetcenter = &((*planet)[0]);
        planetcenter->position = sf::Vector2f
                                ((float)(rand() % (width + (PLANET_BORDER<<1)))-PLANET_BORDER,
                                (float)(rand() % (height + (PLANET_BORDER<<1)))-PLANET_BORDER);
        planetcenter->color = planetcolor;
        resetPlanetVertexes(planet, &(planetcenter->position), size, &(planetcenter->color));
}

However, they look obviously flat and not like planets at all. They look like someone cut perfect circles out of construction paper.



If we look at a planet like Neptune, we see that the bottom right fades towards black, while the top left fades towards a slightly brighter color to create the appearance of a sphere and not a circle.

I think I can probably do something with the coloring to darken or lighten it. (Not sure the best way to do that.) Do I really have to modify each of the three rgb values to lighten/darken a colour?

I also thought there might be a way to build a 3D planet or something similar to that as well.

I want to make each planet random and different so I don't want to use a standard sprite.

the_mean_marine

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Build a Realistic Sphere
« Reply #1 on: January 06, 2014, 01:07:19 pm »
There are many ways to approach this problem and each has it's own advantages.

Probably the easiest way to do it if you any artistic skill is to combine several individuals textures with noise and colour variations in order to create the appearance of many different planets when in fact they are based off a small number of building blocks.

If I was taking this approach then I would generate the base like you have with a random colour and then I would apply spherical distortion to some random chosen, positioned, and possibly coloured decals and then overlay or blend them on top of the base. To handle lighting of the planet you can make a mask texture(s) that adds a corona on one side and darkens the other.

Other approaches include: using OpenGL directly to draw the scene in 3D with procedural textures or do the whole lot in a shader.

A good general approach to figuring out how achieve effects like this is to look at digital painting tutorials to understand the steps they take to create the final image. You can then take the concepts from the tutorials and apply it to what your application. Something like this: http://www.solarvoyager.com/images/tutorials/planet_tutorial_large.jpg should give you a decent idea about where to go from here. Once you have a general idea of how you can achieve your planets you can break this rather large problem into smaller sub-problems and research how to achieve them separately.

You may also want to look into general procedural generation techniques to get specific styles from random noise.

 

anything