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

Thread: Volumetric Clouds

  1. #21

    Volumetric Clouds

    Robert Kosek:
    The procedure expects a pointer type.
    I shall try your suggestion. Thanks.

    User137:
    Well im not really any good with c/c++ and my only experiance with it was a simple hellow world application about 5years ago, but here is the C++ version:

    Code:
    		*(vp++) = Puff->Position + Corner1 * Puff->Size;
    		*(tp++) = v1;
    		*(cp++) = ParticleColor;
    		
    		*(vp++) = Puff->Position + Corner2 * Puff->Size;
    		*(tp++) = v2;
    		*(cp++) = ParticleColor;
    		
    		*(vp++) = Puff->Position + Corner3 * Puff->Size;
    		*(tp++) = v3;
    		*(cp++) = ParticleColor;
    		
    		*(vp++) = Puff->Position + Corner4 * Puff->Size;
    		*(tp++) = v4;
    		*(cp++) = ParticleColor;
    When the cloud is created, it goes to the manager and randomly chooses a cloud data file (this data file contains information on each puff), it then resizes the vBuffer, etc to the required size to fit with the amount of puffs:

    [pascal]
    GetMem(vBuffer, SizeOf(TVector3f)*(Length(Puffs)*4));
    [/pascal]

    Now on every update and render the vBuffer, etc seems to get updated to fit with the position of the camera and sun.

    How ever in an attempt to speed things up, i have moved the code to only work in the update, so now it looks like:
    [pascal]
    procedure AddToMem(Cloud: TVolumetricCloud; Index: Integer; v2: TVector2f; v3: TVector3f; v4a,v4b: TVector4f);
    begin
    Cloud.vBuffer^[Index] := v3;
    // Inc(Cloud.vBuffer^);
    Cloud.cBuffer^[Index] := v4a;
    // Inc(Cloud.cBuffer^);
    Cloud.IcBuffer^[Index] := v4b;
    // Inc(Cloud.IcBuffer^);
    Cloud.tBuffer^[Index] := v2;
    // Inc(Cloud.tBuffer^);
    end;

    procedure TGLVolumetricClouds.buildArrays(Cloud: TVolumetricCloud; Camera,Sun: TVector3f; Alpha: Single);
    var
    i,j: Integer;
    omega2,costheta,phase: Single;
    v1,v2,v3,v4: TVector2f;
    iv3,vx,vy,Light,vv3,Omega,Corner1,Corner2,Corner3, Corner4: TVector3f;
    pColor,pColor2: TVector4f;
    mat: Array [0..15] Of Single;
    begin
    vv3 := Vector3fMake(Camera[0]-Sun[0], Camera[1]-Sun[1], Camera[2]-Sun[2]);
    Light := VectorNormalize(vv3);

    glGetFloatv(GL_MODELVIEW_MATRIX, @mat);

    vx := Vector3fMake(mat[0], mat[4], mat[8]);
    vy := Vector3fMake(mat[1], mat[5], mat[9]);

    v1 := Vector2fMake(1, 0);
    v2 := Vector2fMake(0, 0);
    v3 := Vector2fMake(0, 1);
    v4 := Vector2fMake(1, 1);

    Corner1 := Vector3fMake(-vx[0]-vy[0], -vx[1]-vy[1], -vx[2]-vy[2]);
    Corner2 := Vector3fMake( vx[0]-vy[0], vx[1]-vy[1], vx[2]-vy[2]);
    Corner3 := Vector3fMake( vx[0]+vy[0], vx[1]+vy[1], vx[2]+vy[2]);
    Corner4 := Vector3fMake( vy[0]-vx[0], vy[1]-vx[1], vy[2]-vx[2]);

    j := 0;
    For i := 0 To High(Cloud.Puffs) Do
    Begin
    Omega := Vector3fMake(Cloud.Puffs[i].Position[0]-Camera[0],
    Cloud.Puffs[i].Position[1]-Camera[1],
    Cloud.Puffs[i].Position[2]-Camera[2]);

    omega2 := Omega[0]*Omega[0]+Omega[1]*Omega[1]+Omega[2]*Omega[2];
    omega2 := carmack_func(omega2);

    //omega2 is now 1 / Mag(Omega)
    Omega[0] := Omega[0]*omega2;
    Omega[1] := Omega[1]*omega2;
    Omega[2] := Omega[2]*omega2;

    costheta := VectorDotProduct(Omega, Light);
    phase := 0.75*(1.0+costheta*costheta);

    // 3D
    pColor[0] := (0.3+Cloud.Puffs[i].Color[0]*phase)*Alpha;
    pColor[1] := (0.3+Cloud.Puffs[i].Color[1]*phase)*Alpha;
    pColor[2] := (0.3+Cloud.Puffs[i].Color[2]*phase)*Alpha;
    pColor[3] := Cloud.Puffs[i].Color[3]*Cloud.Puffs[i].Life*Alpha;

    // Imposter
    pColor2[0] := 0.3+Cloud.Puffs[i].Color[0]*phase;
    pColor2[1] := 0.3+Cloud.Puffs[i].Color[1]*phase;
    pColor2[2] := 0.3+Cloud.Puffs[i].Color[2]*phase;
    pColor2[3] := Cloud.Puffs[i].Color[3]*Cloud.Puffs[i].Life;

    iv3 := Vector3fMake(Cloud.Puffs[i].Position[0]+Corner1[0]*Cloud.Puffs[i].Size,
    Cloud.Puffs[i].Position[1]+Corner1[1]*Cloud.Puffs[i].Size,
    Cloud.Puffs[i].Position[2]+Corner1[2]*Cloud.Puffs[i].Size);
    AddToMem(Cloud, j, v1, iv3, pColor, pColor2);
    Inc(j);
    iv3 := Vector3fMake(Cloud.Puffs[i].Position[0]+Corner2[0]*Cloud.Puffs[i].Size,
    Cloud.Puffs[i].Position[1]+Corner2[1]*Cloud.Puffs[i].Size,
    Cloud.Puffs[i].Position[2]+Corner2[2]*Cloud.Puffs[i].Size);
    AddToMem(Cloud, j, v2, iv3, pColor, pColor2);
    Inc(j);
    iv3 := Vector3fMake(Cloud.Puffs[i].Position[0]+Corner3[0]*Cloud.Puffs[i].Size,
    Cloud.Puffs[i].Position[1]+Corner3[1]*Cloud.Puffs[i].Size,
    Cloud.Puffs[i].Position[2]+Corner3[2]*Cloud.Puffs[i].Size);
    AddToMem(Cloud, j, v3, iv3, pColor, pColor2);
    Inc(j);
    iv3 := Vector3fMake(Cloud.Puffs[i].Position[0]+Corner4[0]*Cloud.Puffs[i].Size,
    Cloud.Puffs[i].Position[1]+Corner4[1]*Cloud.Puffs[i].Size,
    Cloud.Puffs[i].Position[2]+Corner4[2]*Cloud.Puffs[i].Size);
    AddToMem(Cloud, j, v4, iv3, pColor, pColor2);
    Inc(j);
    End;
    end;
    [/pascal]

    Many Thanks
    Nic
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #22

    Volumetric Clouds

    Im completly stumped now,

    If it helps, i have updated the ZIP file (as mentioned before).

    Many thanks
    Nic
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  3. #23

    Volumetric Clouds

    I'm afraid this is the limit of my knowledge here. I was thinking pointers might speed things, but I really just don't know. Maybe for functionality and ease of maintenance you should just stick with arrays.

  4. #24

    Volumetric Clouds

    Ok many thanks anyway

    i think i shall start from the beginning and try converting it without GLScene for now.

    I shall post the demo if im successfull

    Thanks again
    Nic
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

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
  •