Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Volumetric Clouds

  1. #11

    Volumetric Clouds

    Thanks for that, i always woundered what the difference between the two was
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #12

    Volumetric Clouds

    Quote Originally Posted by M109uk
    Ah sorry, i forgot to post that bit ops:

    type
    PVector2f = ^TVector2f;
    PVector3f = ^TVector3f;
    PVector4f = ^TVector4f;

    TVolumetricCloud = Class
    //
    vBuffer: PVector3f;
    tBuffer: PVector2f;
    cBuffer: PVector4f;
    IcBuffer: PVector4f;
    end;

    Thanks
    Okay, this is the problem and is my fault. What you need is this type for the buffers:
    Code:
    type
      TVector3fArray = array of Vector3f;
      PVector3fArray = ^TVector3fArray;
      //...
    
      TVolumetricCloud = Class
        vBuffer&#58; PVector3fArray;
        //...
      end;
    
    //..
    
    //OnCreate...
    var cur&#58; PVector3f;
          counter&#58; Integer;
    begin
      GetMem&#40;vBuffer, SizeOf&#40;TVector3f&#41; * Length&#40;Puffs&#41;&#41;;
      cur &#58;= Pointer&#40;vBuffer^&#91;0&#93;&#41;;
      counter &#58;= Length&#40;Puffs&#41;;
      while counter > 0 do begin
        // Manipulation here...
        Inc&#40;Cur&#41;;
        Dec&#40;Counter&#41;;
      end;
    end;
    You should understand how to expand upon this by now, but I'll give you the basics. Sometimes pointers really aren't worth it--especially for arrays. Now, you could do a single/double linked list, but there would be no increase in speed to set the vertex buffer that way (the API's are C and want arrays...).

  3. #13

    Volumetric Clouds

    Quote Originally Posted by M109uk
    I have changed the code to use pointers instead, however i am getting an access violation error when i add data to the pointer (around the 20th item to be added)

    am i doing something wrong...

    heres the code im using:
    [pascal]//---- add data to pointers
    procedure AddToMem(Cloud: TVolumetricCloud; v2: TVector2f; v3: TVector3f; v4a,v4b: TVector4f);
    begin
    Cloud.vBuffer^ := v3;
    Inc(Cloud.vBuffer); <-------------- ERROR HERE
    Cloud.cBuffer^ := v4a;
    Inc(Cloud.cBuffer);
    Cloud.IcBuffer^ := v4b;
    Inc(Cloud.IcBuffer);
    Cloud.tBuffer^ := v2;
    Inc(Cloud.tBuffer);
    end;[/pascal]
    im sure i've missed something really dumb..
    Propably That code is trying to increase pointers by 1 like you showed in class definition. Try
    Inc(Cloud.vBuffer^);
    etc...

  4. #14

    Volumetric Clouds

    User137:
    Thanks for the idea,
    i gave it a try, and it just kept coming back with an invalid typcast error.

    Robert Kosek:
    Thanks again,
    I had to make a small adjustment (otherwise i kept getting access violations again)

    TVector3fArray = Array [0..0] Of TVector3f;
    PVector3fArray = ^TVector3fArray;

    I hav'nt properly tested it to see if the values are going in ok, since now i have another problem i completly forgot about, haha.

    I have another procedure that sorts the records depending on the puffs distance from the camera, now i know my sort routine is uterly trash, and probably contributes to the most of the lack of speed, however here it is:

    [pascal]
    procedure TGLVolumetricClouds.SortParticles(Cloud: TVolumetricCloud; mode: Integer);

    procedure swap(iFrom,iTo: Integer);
    var
    tmpPuff: TCloudPuff;
    begin
    tmpPuff := Cloud.Puffs[iFrom];
    Cloud.Puffs[iFrom] := Cloud.Puffs[iTo];
    Cloud.Puffs[iTo] := tmpPuff;
    end;

    procedure sort(Toward: Boolean);
    var
    i,j: Integer;
    tmpPuff: TCloudPuff;
    begin
    For i := 0 To High(Cloud.Puffs) Do
    For j := 0 To High(Cloud.Puffs) Do
    Begin
    If ((Toward) And (Cloud.Puffs[i].DistanceToCam > Cloud.Puffs[j].DistanceToCam)) Or
    ((Not Toward) And (Cloud.Puffs[i].DistanceToCam < Cloud.Puffs[j].DistanceToCam)) Then
    swap(i, j);
    End;
    end;

    var
    done,do_swap,useSTL: Boolean;
    i,j: Integer;
    begin
    done := False;
    useSTL := True;

    If useSTL Then
    Begin
    Case mode Of
    SORT_AWAY: sort(False);
    SORT_TOWARD: sort(True);
    End;
    End Else
    Begin
    while (Not done) Do
    Begin
    done := True;
    For i := 0 To High(Cloud.Puffs) Do
    For j := i+1 To High(Cloud.Puffs) Do
    Begin
    do_swap := false;
    Case mode Of
    SORT_AWAY: do_swap := (Cloud.Puffs[i].DistanceToCam <Cloud> Cloud.Puffs[j].DistanceToCam);
    End;

    If do_swap Then
    Begin
    swap(i, j);
    done := False;
    End;
    End;
    End;
    End;
    end;
    [/pascal]

    Im guessing this would'nt effect the pointers, but i have an assign procedure for the cloud, which needs to copy the pointer, now im assuming if i just did Cloud.vBuffer := Source.vBuffer; that if i make changes this will effect both clouds. would it be best to clear and recreate the pointer (cloud.vBuffer) and then copy the memory (somehow)?

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

  5. #15

    Volumetric Clouds

    Well, the sorting is beyond me, but not the swappage of pointers. That's really simple once you figure it out. Here's the gist:
    Code:
    procedure SwapPointers&#40;var p1,p2&#58; Pointer&#41;;
    var
       tmp&#58; pointer;
    begin
      tmp &#58;= p1;
      p1  &#58;= p2;
      p2  &#58;= tmp;
    end;
    It really is that simple. If it complains about the pointer type or anything, just typecast it into a pointer when you pass it.

  6. #16

    Volumetric Clouds

    Great thanks

    seems to work, now i seem to be having problems again with the following section, it loops through a few times and then an access violation:

    [pascal]
    glVertexPointer(3, GL_FLOAT, 0, Cloud.vBuffer);
    glColorPointer(4, GL_FLOAT, 0, Cloud.cBuffer);
    glTexCoordPointer(2, GL_FLOAT, 0, Cloud.tBuffer);

    glDrawArrays(GL_QUADS, 0, Length(Cloud.Puffs)*4);
    [/pascal]

    i assumed to change from '@Cloud.vBuffer[0]' to 'Cloud.vBuffer'?

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

  7. #17

    Volumetric Clouds

    Try this instead, as far as I can remember this is the correct form. Though, why do you keep multiplying the size by 4? That is beyond me a little, since I'm trying to figure out why you need 4 times the size of the one array.

    Code:
       glVertexPointer&#40;3, GL_FLOAT, 0, Pointer&#40;Cloud.vBuffer^&#91;0&#93;&#41;&#41;;
       glColorPointer&#40;4, GL_FLOAT, 0, Pointer&#40;Cloud.cBuffer^&#91;0&#93;&#41;&#41;;
       glTexCoordPointer&#40;2, GL_FLOAT, 0, Pointer&#40;Cloud.tBuffer^&#91;0&#93;&#41;&#41;;
    This just gets the pointer to the first item like before, rather than the array. C prefers it this way AFAIK.

  8. #18

    Volumetric Clouds

    I tryed that and got an invalid typcast error, would this work:

    [pascal]
    glVertexPointer(3, GL_FLOAT, 0, @Cloud.vBuffer^[0]);
    glColorPointer(4, GL_FLOAT, 0, @Cloud.cBuffer^[0]);
    glTexCoordPointer(2, GL_FLOAT, 0, @Cloud.tBuffer^[0]);
    [/pascal]

    Im multiplying them by 4 because each puff is actually Quad so i pass 4 vertices for each puff.
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  9. #19

    Volumetric Clouds

    Ah, okay. So what is the function expecting, typewise? Maybe try removing the array index portion and just throw it the buffer with a @ prefix to the whole thing. IE: @Cloud.vBuffer);

  10. #20

    Volumetric Clouds

    Quote Originally Posted by User137
    Quote Originally Posted by M109uk
    I have changed the code to use pointers instead, however i am getting an access violation error when i add data to the pointer (around the 20th item to be added)

    am i doing something wrong...

    heres the code im using:
    [pascal]//---- add data to pointers
    procedure AddToMem(Cloud: TVolumetricCloud; v2: TVector2f; v3: TVector3f; v4a,v4b: TVector4f);
    begin
    Cloud.vBuffer^ := v3;
    Inc(Cloud.vBuffer); <-------------- ERROR HERE
    Cloud.cBuffer^ := v4a;
    Inc(Cloud.cBuffer);
    Cloud.IcBuffer^ := v4b;
    Inc(Cloud.IcBuffer);
    Cloud.tBuffer^ := v2;
    Inc(Cloud.tBuffer);
    end;[/pascal]
    im sure i've missed something really dumb..
    Propably That code is trying to increase pointers by 1 like you showed in class definition. Try
    Inc(Cloud.vBuffer^);
    etc...
    *sigh* I wasn't really thinking clearly when i wrote that :lol: procedure AddToMem says something about what you want to do in it... Original procedure propably did something only C can do, now in pascal you likely need a new approach completely. So.. i think plan is to add 1 vertex to array and same time make preparations so next call will also add 1 after it. Need to make sure the array is resized and update some Count variable, then assign parameter info to vBuffer[Count-1] that is last index.

    And about sorting, this is 1 efficient structure:
    [pascal]for i:=0 to Count-2 do
    for j:=i+1 to Count-1 do
    // Compare here and swap if needed

    // Notice how it ignores all useless calls, like this way would make final compare to item itself, not to mention amount of extra calls it there wasn't i+1
    for i:=0 to Count-1 do
    for j:=i+1 to Count-1 do[/pascal]
    But still there exist faster ways, i'm not very much familiarized with them and they are propably made for certain kinds of arrays.

    Edit: Ok i take my words back a bit, it is all propably possible in pascal too, but this line
    Inc(Cloud.vBuffer);
    was actually made to increase the pointer (the place that array starts, note you would need to revert it backwards too if want to use it), and likely not by 1, but 12 that is sizeof(TVector3f). Maybe something like (i'm not sure):
    pointer(Cloud.vBuffer):=pointer(integer(Cloud.vBuf fer)+12);

Page 2 of 3 FirstFirst 123 LastLast

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
  •