PDA

View Full Version : Sun Flares



Bejelit
09-07-2011, 12:28 PM
Hello!
I would be very grateful if someone could help me :) I am a newbie at this so I need help T_T

My aim is to create solar flares in opengl. Since the sun is made of gas and there is a differential rotation that depends on
particle's position, I used an equation in order to create a sphere with them!I gave different velocities to them... and the
next step is colouring the particles! I wish to give to them this kind of effect:

http://www.astronomia.com/wp-content/uploads/2009/11/sole-big.gif

So, my question is: How to give that? I mean the vivid colours, luminosity,... it is a very cool effect so I want to learn it.
You can give me just the name of the effect ... just what I have to apply.

Please, help me!
Thank you very much :)

ZbuffeR
09-07-2011, 03:26 PM
Color is mainly dependent on local density, and age could be interesting too, like a cooling effect.

Bejelit
09-07-2011, 10:57 PM
Do you mean changing the intensity of the assigned components rgb depending on the age of the particle??? I thought that the age of a particle should be assigned just in case it has a life time... in my case,it is needed for flares but not for sun surface. However, thank you for opening up my mind :) I will try an age for
the sphere too... I hope to do a good job:) Thank you again!

Bejelit
09-19-2011, 01:16 PM
Heyyyy that's me... again =D

I have another problem ... just have a look :

http://imageshack.us/photo/my-images/560/uploadanimage.png/

Don't mind about the uglyness of the product... I am still working on it lol BUT, I cannot understand why , when I use a texture to color my rays in a good way, I got the black borders... why?! What should I do? Can you help me?

THANKS again :)

ZbuffeR
09-19-2011, 02:02 PM
Did you provide an alpha channel to your textures and enable blending ?

MaxH
09-19-2011, 03:15 PM
I have another problem ... just have a look :Looks like you're pretty close to what you want. As ZbuffeR said, it's just a matter of setting up transparency correctly.
The code below shows you how I do it. 'bug' is a visual debugging flag I use when my particle system isn't working the way I want it to. When 'bug' is TRUE, I turn off blending so I can see the edges of the quads I'm texturing on. I also put a blue, wireframe edge on each quad to clearly show it's size and orientation. The Blendfunc statement is what turns transparency on correctly. The image I'm using is simply a white star that fades to black towards the edges. It's a .bmp file without an alpha channel.


//---+----3----+----2----+----1----+---><---+----1----+----2----+----3----+----4
//---------------------------- Draw_Particles ------------------------------

void Draw_Particles (short update, float skale, int mission, short bug)
{
int p, particles;

glDisable (GL_LIGHTING);
glEnable (GL_DEPTH_TEST);

glEnable (GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE);

if (bug) glDisable (GL_BLEND);
else glEnable (GL_BLEND);

particles = skale * MAX_PARTICLES;

if (skale > 1.0) {
BELL
printf (" Draw_Particles: skale = %.2f\n", skale);
STOP
}

for (p = 0; p < particles; ++p) {
Thrusta[p].Draw (update, skale, mission, bug);
}

glDisable (GL_BLEND);
glDisable (GL_TEXTURE_2D);
}
The screen grabs below show my particle system with blending off and on.
With blending off, my scene looks a lot like yours, except that I have much
more overlap between my quads (and I put blue edges on each quad).

http://www.mfwweb.com/OpenGL/Blend_Off.jpg

http://www.mfwweb.com/OpenGL/Blend_On.jpg

Bejelit
09-20-2011, 02:21 AM
Hello!!! Thank you so much for helping me!

I got the result that I want for the rays but when I apply the same code to the sun surface I get very bad results... just look:

Front Sun:
http://imageshack.us/photo/my-images/846/im1e.png/

Back Sun:
http://imageshack.us/photo/my-images/13/im2y.png/

So why can I have good results with my rays and not with the sun surface?

Here is my code:

void Draw()
{


if (Label == false)
{
Tex.LoadBMP("data/New.bmp",GL_LINEAR,GL_LINEAR);
Label = true;
}

glDisable(GL_LIGHTING);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Tex.ID);
glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE);


const float size = 0.15f;
glBegin(GL_QUADS);
vector<Particle>::iterator pIt;
for(pIt = _particles.begin(); pIt !=_particles.end(); pIt++)
{
Vector3&amp; pos = pIt->pos;
Vector3&amp; col = pIt->col;
glColor4f(col.x,col.y,col.z,1.f);

glTexCoord2d(0,0);
glVertex3f(pos.x - size, pos.y - size, pos.z);
glTexCoord2f(0, 1);
glVertex3f(pos.x - size,pos.y + size, pos.z);
glTexCoord2f(1, 1);
glVertex3f(pos.x + size, pos.y + size, pos.z);
glTexCoord2d(1, 0);
glVertex3f(pos.x + size, pos.y - size, pos.z);

}
glEnd();


glDisable(GL_BLEND);
}

So... I am wondering about why I am wrong ... I added blending as you told me T_T

Ah! Here is my texture! http://imageshack.us/photo/my-images/849/newppa.png/
It's in bmp format 32 bit.

Thanks again :)

Bejelit
09-20-2011, 02:47 AM
I am trying using GL_POINTS instead of GL_QUADS too.. without texturing it ... and I got this kind of result :
http://imageshack.us/f/853/immagine90.png/

applying the code:

void Draw(float size)
{
glPointSize(size);
glEnable(GL_POINT_SMOOTH);

glDisable(GL_LIGHTING);

glEnable(GL_TEXTURE_2D);

vector<Particle>::iterator pIt;
for(pIt = _particles.begin(); pIt != _particles.end(); pIt++)
{

Vector3&amp; pos = pIt->pos;
Vector3&amp; col = pIt->col;

glColor4f(col.x, col.y, col.z, pIt->TimeAlive);

glVertex3f(pos.x, pos.y, pos.z);

}

glEnd();

}

But Color4f doesn't work ... it has always given me the same opacity T_T

Thanks again :)

ZbuffeR
09-20-2011, 09:01 AM
Please use code tags.

Blending does not work correctly with depth testing enabled.

Bejelit
09-20-2011, 09:33 AM
So sorry... I am new about posting in forums too lol

However, this is my code for quads:



void Draw()
{


if (Label == false)
{
Tex.LoadBMP("data/New.bmp",GL_LINEAR,GL_LINEAR);
Label = true;
}

glDisable(GL_LIGHTING);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Tex.ID);
glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE);


const float size = 0.15f;
glBegin(GL_QUADS);
vector<Particle>::iterator pIt;
for(pIt = _particles.begin(); pIt !=_particles.end(); pIt++)
{
Vector3&amp; pos = pIt->pos;
Vector3&amp; col = pIt->col;
glColor4f(col.x,col.y,col.z,1.f);

glTexCoord2d(0,0);
glVertex3f(pos.x - size, pos.y - size, pos.z);
glTexCoord2f(0, 1);
glVertex3f(pos.x - size,pos.y + size, pos.z);
glTexCoord2f(1, 1);
glVertex3f(pos.x + size, pos.y + size, pos.z);
glTexCoord2d(1, 0);
glVertex3f(pos.x + size, pos.y - size, pos.z);

}
glEnd();


glDisable(GL_BLEND);
}


and this is the one for points mode:



void Draw(float size)
{
glPointSize(size);
glEnable(GL_POINT_SMOOTH);

glDisable(GL_LIGHTING);

glEnable(GL_TEXTURE_2D);

vector<Particle>::iterator pIt;
for(pIt = _particles.begin(); pIt != _particles.end(); pIt++)
{

Vector3&amp; pos = pIt->pos;
Vector3&amp; col = pIt->col;

glColor4f(col.x, col.y, col.z, pIt->TimeAlive);

glVertex3f(pos.x, pos.y, pos.z);

}

glEnd();

}



However, I have used the :
glDepthMask GL_FALSE);
but it doesn't work too :(

MaxH
09-20-2011, 09:10 PM
Blending does not work correctly with depth testing enabled. Yet in my particle system (above), it doesn't seem to make a difference whether or not depth testing is enabled. The rocket flame looks the same either way. However the flame is incorrectly drawn relative to the rocket body if depth testing is disabled.

Live_MusIc
09-21-2011, 05:49 AM
If I remember correctly you have to enable depth test, set z-buffer as read-only and set glDepthFunc(GL_LEQUAL) to avoid z-fighting between particles :)
Also you may consider doing some kind of billboarding to every particle, to make it look better when the camera moves.

BionicBytes
09-21-2011, 06:38 AM
When rendering lots of particles close together it's often best to enable depth test but disable depth mask.

Bejelit
09-21-2011, 02:12 PM
Ok, I am trying ... at the moment...this is my result :

http://imageshack.us/f/854/sole.png/

Thanks again, guys :)

MaxH
09-21-2011, 03:12 PM
Your sun's surface looks pretty good except at the edges.
The edge looks too perfect, too hard, as if you put a red circle behind the sun.
The flares need some structure to them.

Bejelit
09-21-2011, 04:06 PM
Yeah, you are right ... I will post a new pic as soon as I get something better! Thanks!

Bejelit
09-24-2011, 03:56 PM
http://imageshack.us/photo/my-images/38/immagineneg.png/


What do you honestly think of this result? >_<

Bejelit
09-24-2011, 04:50 PM
How can I get it better?? At the moment I did just rays not flares... Thank you so much :)

MaxH
09-25-2011, 05:41 PM
You're trying to do something fairly difficult, particularly the flares. If your goal is to get something similar to the original picture you posted, I wouldn't know where to start. I still think your solar surface is pretty good, though in the last picture the flares (or rays) have messed it up a bit. You might not be able to get those thin filaments making up solar flares with the particle system approach you're using because the individual particles are too big. I'm guessing that CGI professionals would use a volumetric rendering approach to do the flares.

Bejelit
09-26-2011, 07:41 AM
Yeah... I know ... I didn't notice the difficul at the start ... even because my laptop is not that powerful... so it cannot deal with a large amount of particles... My surface + rays are very heavy :P I think I will show to my teacher just something like this :

http://www.megaupload.com/?d=1S32UWX8

just rays... since it's an examination based on a first approach to opengl, I hope it will be enough >_<

Thanks =D