Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: [OpenGL] Earth atmosphere effect

  1. #21

    [OpenGL] Earth atmosphere effect

    Ok, nevermind. I decided to go with the TGLAtmosphere class from GLScene and here's the result (no optimizations yet).
    .

  2. #22

    [OpenGL] Earth atmosphere effect

    Well maybe that looks better but doesn't mean glow texture couldn't be split and colorized like that aswell

    This is what i came up with the glow texture (new texture):
    http://i30.tinypic.com/iqlt8x.jpg

    Read the nehe link or something about rotating the matrix and it works. In my sample program the planet follows cursor and glow is always placed properly around planet.

    [pascal]// * Atmosphere effect *
    glPushMatrix;
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);

    glGetfloatv(GL_MODELVIEW_MATRIX,@mat);
    // Store position from modelview
    pos.x:=mat[3,0]; pos.y:=mat[3,1]; pos.z:=mat[3,2];
    // Look-at vector from position to 0 (camera)
    look.x:=-pos.x;
    look.y:=-pos.y;
    look.z:=-pos.z;
    norm(@look.x);
    // Define a temporary up vector
    up.x:=0; up.y:=1; up.z:=0;
    // Crossproduct look and up to get right
    right:=crossproduct(@look,@up);
    // Crossproduct look and right to get proper up vector
    up:=crossproduct(@look,@right);
    // Place vectors back to matrix
    copymemory(@mat[0,0], @right.x, sizeof(single)*3);
    copymemory(@mat[1,0], @up.x, sizeof(single)*3);
    copymemory(@mat[2,0], @look.x, sizeof(single)*3);

    glLoadIdentity;
    glMultMatrixf(@mat);
    tex.SetTex(0);
    AddBlend(true);
    glColor3f(0.4,0.6,1);
    RectT(A_rad,-A_rad,-A_rad,A_rad); // Render quad

    AddBlend(false);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
    glPopMatrix;
    // * End atmosphere effect *[/pascal]

  3. #23

    [OpenGL] Earth atmosphere effect

    Thanks for your effort, User137. I'mma use your code, too. Looks decent!

  4. #24

    [OpenGL] Earth atmosphere effect

    Oops, I've just noticed that it works, but not quite good enough yet. :roll: When the observer is too far away from the sphere, the glow is too big, but when it's too close, the glow is too small! Here are the screenshots.
    Screen #1 - far from the planet
    Screen #2 - close to the planet
    What do you think about it?

  5. #25

    [OpenGL] Earth atmosphere effect

    Far and normal ranges are fine in my testing, but when you get too close it starts to shrink the glow inside sphere for some reason. :? Tried normalizing all vectors but doesn't do anything.

    Could be that perspective "eye point" is not at 0 but more behind or forward some amount. Fov near plane was at least not that.

    Edit: Oh i know what happens... Because of perspective view the sphere front becomes much wider than center part of sphere when zoomed close in and therefore glow will be smaller than visible sphere. Imagine looking at a cube from straight front, the front face will cover everything up when watching it closer, and it is the same thing. Solution could be scaling up the glow when coming down to certain range... just goes very unformal and tricky again. I have no idea how to calculate correct scaling and if it's worth it.

  6. #26

    [OpenGL] Earth atmosphere effect

    Quote Originally Posted by User137
    Oh i know what happens... Because of perspective view the sphere front becomes much wider than center part of sphere when zoomed close in and therefore glow will be smaller than visible sphere. Imagine looking at a cube from straight front, the front face will cover everything up when watching it closer, and it is the same thing. Solution could be scaling up the glow when coming down to certain range... .
    Yip, you are absoultely right. When it comes to calculating the scaling - I think that it could be something with the distance between the observer and the sphere. I believe that there's an equation that would help us solve it, but I'm not good at maths. :?

    But there's a ray of hope. This function taken from GLScene looks interesting and could help us getting the scaling work properly:
    [pascal]
    procedure TGLCamera.AdjustDistanceToTarget(distanceRatio : Single);
    var
    vect : TVector;
    begin
    if Assigned(FTargetObject) then begin
    // calculate vector from target to camera in absolute coordinates
    vect:=VectorSubtract(AbsolutePosition, TargetObject.AbsolutePosition);
    // ratio -> translation vector
    ScaleVector(vect, -(1-distanceRatio));
    AddVector(vect, AbsolutePosition);
    if Assigned(Parent) then
    vect:=Parent.AbsoluteToLocal(vect);
    Position.AsVector:=vect;
    end;
    end;
    [/pascal]

    Anyway, I'm waiting for your opinions.

  7. #27

    [OpenGL] Earth atmosphere effect

    I don't think i have GLScene installed and not fussed to But seeing the code it looks that distanceRatio parameter given to function may be the key, where is it calculated and how?

  8. #28

    [OpenGL] Earth atmosphere effect

    It's not calculated anywhere, the user is supposed to use something as a value. Here's a little example of how it's done in one of GLScene's demos:
    [pascal]
    procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
    WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    var
    f : Single;
    begin
    if (WheelDelta>0) or (GLCameraControler.Position.VectorLength>0.90) then begin
    f:=Power(1.05, WheelDelta*(1/120));
    GLCameraControler.AdjustDistanceToTarget(f);
    end;
    Handled:=True;
    end;
    [/pascal]

  9. #29
    farcodev_
    Guest

    [OpenGL] Earth atmosphere effect

    Quote Originally Posted by Brainer
    Ok, nevermind. I decided to go with the TGLAtmosphere class from GLScene and here's the result (no optimizations yet).
    .
    hehe good news, yup its rock

    you can even change colors and density, i'll upgrade my engine with atmosphere colors following atmosphere type, doesn't change much for the game itself but i must do it lol.

  10. #30
    farcodev_
    Guest

    [OpenGL] Earth atmosphere effect

    Quote Originally Posted by Brainer
    Yip, you are absoultely right. When it comes to calculating the scaling - I think that it could be something with the distance between the observer and the sphere. I believe that there's an equation that would help us solve it, but I'm not good at maths. :?

    But there's a ray of hope. This function taken from GLScene looks interesting and could help us getting the scaling work properly:
    [pascal]
    procedure TGLCamera.AdjustDistanceToTarget(distanceRatio : Single);
    var
    vect : TVector;
    begin
    if Assigned(FTargetObject) then begin
    // calculate vector from target to camera in absolute coordinates
    vect:=VectorSubtract(AbsolutePosition, TargetObject.AbsolutePosition);
    // ratio -> translation vector
    ScaleVector(vect, -(1-distanceRatio));
    AddVector(vect, AbsolutePosition);
    if Assigned(Parent) then
    vect:=Parent.AbsoluteToLocal(vect);
    Position.AsVector:=vect;
    end;
    end;
    [/pascal]

    Anyway, I'm waiting for your opinions.
    Its the function i use for the zoom/unzoom in my game, so its ok

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •