Results 1 to 8 of 8

Thread: GBuffer tests

  1. #1

    GBuffer tests

    i have made some tests on GBuffers as posted by Petr http://www.thinbasic.com/community/s...2240#post92240
    and it is really facilitating the plotting and reducing the code amount and provide a speedy rendering of the arrays it works on
    here is the math curve plotted in the previous link but here with GBuffers
    tested with TB beta 1.9.16.3
    curve.PNG
    Uses "TBGL"
     
    Function TBMain()
      Local hWnd      As DWord
      Local FrameRate As Double
       
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers - press ESC to quit", 600, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow  
       
      TBGL_BackColor 255,255,255
     
      ' -- Create 3D triangle buffer
      Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
      'Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_LINES, %TBGL_3D)
      
      Global Nb As Integer = 120
      
      ' -- Define data for it
      Global VertexA(Nb,Nb) As TBGL_TVECTOR3F
      Global ColorA(Nb,Nb)  As TBGL_TRGB
      
      FillArrays ' call the sub to fill VertexA , ColorA  arrays
      
    
     Dim NumOfarrayElements As Long = CountOf(VertexA(1))* CountOf(VertexA(2))
      ' -- Create buffer dynamically linked to the arrays above
      TBGL_GBufferDefineFromArray(gbPoints, %TBGL_DYNAMIC, NumOfarrayElements, VertexA(1,1), ColorA(1,1))
       
      ' -- Resets status of all keys 
      TBGL_ResetKeyState() 
    '  TBGL_PointSize 2
    
      ' -- Main loop
      While TBGL_IsWindow(hWnd)
      'init 
        FrameRate = TBGL_GetFrameRate
        
        TBGL_ClearFrame
          TBGL_Camera(0, 3, 4, 0, 0, 0)
           
          ' -- Turn triangle
          TBGL_Rotate GetTickCount/50, 0, 1, 0
                                   
          ' -- Render it                              
          TBGL_GBufferRender(gbPoints)   
            
        TBGL_DrawFrame
     
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
     
      Wend        
      ' -- Destroying the buffer is not necessary,
      ' -- the garbage collector will take care of it
     
      ' -- Destroy window
      TBGL_DestroyWindow
    End Function  
    
    Sub FillArrays()
    Dim xMin, yMin, zMin, xMax, yMax, zMax, range, step1, x, y, z As Single
    xMin = -1 : yMin = -1: zMin = -1: xMax = 1: yMax = 1: zMax = 1
    'xMin = -0.5 : zMin = -0.5 : xMax = 0.5: zMax = 0.5 
    Dim a,b As Integer
      range = xMax - xMin
      step1 = range / Nb
      x = xMin: z = zMin : y = yMin
      For b=1 To Nb
         
        For a=1 To Nb
          
          y = Sin(10*(x^2+z^2))/5
                  
          VertexA(a,b).x = x
          VertexA(a,b).y = y
          VertexA(a,b).z = z
          If y >= 0 Then 'color red if y>=0 esle color blue 
            ColorA(a,b).r = 255
            ColorA(a,b).g = 0
            ColorA(a,b).b = 0
          Else
            ColorA(a,b).r = 0
            ColorA(a,b).g = 0
            ColorA(a,b).b = 255
          End If
          x = x + step1
            
        Next a
          
        x = xMin
        z = z + step1
      Next b
        
    '=================================================================================
    End Sub
    
    as a funny variation, using the same GBuffer method but plotting the shapes data produced somehow by WolphramAlpha site , as an example: Bart Simpson_like curve:
    http://www.wolframalpha.com/input/?i...tSimpsonCurve-
    its x,y data is 13KB, very big, and to obtain it hover the mouse at the bottom of its equations in the page look the picture
    wolframAlpha.PNG
    and click on 'A' for a copyable text version, save it to a file and apply the attached "VBRegExp_Test_Replace.tbasic" which is essentialy the thinbasic official example applying it to the file such as simpsons.txt to convert its equations to the thinbasic version
    note that the x = ... is going to about 6000 characters so we need to partition it in every about 2000 characters or so using the underscore _ , and thinbasic do a good job in this
    VBRegExp_Test_Replace.tbasic: opening "simpsons.txt" file and applying several simple regexes to it ans saving it to simpsons2.txt. apply the same method with other curves equations downloaded from wolframAlpha, the "simpsons.txt" available in the attached rar file
      Uses "VBREGEXP", "file"
      
      dim lpRegExp  as dword
      dim strText   as string value "The quick brown fox jumped over the lazy dog."
      Dim strRetVal As String
      Dim FileHandle As DWord
      Dim FileName   As String 
     
      '---Allocate a new regular expression instance
      lpRegExp = VBREGEXP_New
      
      '---Check if it was possible to allocate and if not stop the script
      if isfalse lpRegExp then
        MSGBOX 0, "Unable to create an instance of the RegExp object." & $crlf & "Script terminated"
        stop
      end if
        
      '---Set case insensitivity
      VBREGEXP_SetIgnoreCase lpRegExp, -1
      '---Set global applicability
      VBREGEXP_SetGlobal lpRegExp, -1
     
      Dim i As Integer
      FileName   = APP_SourcePath + "simpsons.txt"  ' Build filename
         
         strText = FILE_Load(FileName)
         VBRegExp_SetPattern lpRegExp, "(\d\s)sin" 
         strRetVal = VBRegExp_Replace(lpRegExp, strText, "$1*sin") 
         VBRegExp_SetPattern lpRegExp, "(\d\s)t" 
         strRetVal = VBRegExp_Replace(lpRegExp, strRetVal, "$1*t") 
         VBRegExp_SetPattern lpRegExp, "(\)\s)theta" 
         strRetVal = VBRegExp_Replace(lpRegExp, strRetVal, "$1*theta")
         VBRegExp_SetPattern lpRegExp, "(\d\s)pi" 
         strRetVal = VBRegExp_Replace(lpRegExp, strRetVal, "$1*pi")
         VBRegExp_SetPattern lpRegExp, "sqrt" 
         strRetVal = VBRegExp_Replace(lpRegExp, strRetVal, "sqr")
          
      FILE_Save(APP_SourcePath + "simpsons2.txt", strRetVal) 
    
      '---Deallocate regular expression resource
      IF istrue lpRegExp   THEN VBREGEXP_Release(lpRegExp)
      MsgBox 0, "ok"
    
    since the files x,y data are too big i attach the tbasic files as rar files , simpsons.curve, ketty_curve, cannabis_curve, rose_curve, there is also curves3.txt which contains more curves data you can test, some files such as rose_curve needs 10 seconds to display depends on your system speed
    Attached Files Attached Files

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Wow, thanks!
    This is an EXTREME test for thinBasic parser and interpreter!

    I've never interpreted a math expression so big.
    For example simpsons_curve.tbasic example contains two math expressions calculating x and y:

    • X calculation is a math function 6575 bytes long
    • y calculation is a math function 6593 bytes long


    They are calculated for 22624 times.

    3 things regarding thinBasic tricks:
    1. no need to use A or B at NEXT A and NEXT B, just NEXT. ThinBasic will know what variable to increment
    2. no need to add _ for line continuation when last char of the previous line is a delimiter like a math symbol
    3. because in this examples you got formulas from external source, you can set the X and Y calculation in an external file and include it in the script just like it would be inline with your code.
      In this way you can keep your script into one source and BIG formulas into another script. Example:
      While t <= 72*Pi
      
        #INCLUDE "simpsons.txt.tbasic"        
      
      
      'x = ((-5/37 *Sin(61/42-8 *t)-112/41 ...
      'Y = ((-9/23 *Sin(38/25-6 *t)-67/38 ...
      
      
        VertexA(N).x = x*0.04
        VertexA(N).y = y*0.04
        ColorA(N).r = 255 :ColorA(N).g = 0 :ColorA(N).b = 0 
      
      
        t + 0.01 : N + 1
      
      
      Wend
      


    Thanks a lot for this present.
    I want to see Petr Schreiber face when he will see this

    Ciao
    Eros
    Attached Images Attached Images
    Last edited by ErosOlmi; 13-11-2015 at 19:50.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    Hehe,

    this is just perfect


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thanks Eros, Petr for the valuable info, especialy the #INCLUDE "simpsons.txt.tbasic" this will makes the life easier with the very huge files available in wolfram alpha site and other sources.
    there is a blog about these topics:
    http://blog.wolframalpha.com/2013/01...ing-equations/
    http://blog.wolfram.com/2013/05/17/m...-isaac-newton/

    regards

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    Just a hint - because the loading takes a while, what about adding some animation to track the progress?

    Something to get you started:

    #1 Add this function to your code
    Function ReportProgress(ratio As Number)
      Single i
      Single radians       
      
      ' -- Whatever color is set inside block, we want it to be reset to white
      ' -- once block is finished
      TBGL_PushColor 255, 255, 255      
      
        TBGL_ClearFrame           
          TBGL_Rotate 360*ratio/2+180 ' -- Rotating the following shape to appear symetrical
        
          TBGL_Color 255,255-255*ratio,255-255*ratio ' -- Nice color fade out
          
          TBGL_BeginPoly %GL_POLYGON
          
            TBGL_Vertex 0, 0, -1 
            
            For i = 0 To 360*ratio Step 0.1
              radians = DegToRad(-i+90)          
              TBGL_Vertex Cos(radians)*0.1, Sin(radians)*0.1, -1          
            Next
            
          TBGL_EndPoly  
          
        TBGL_DrawFrame  
      
      TBGL_PopColor  
      
    End Function
    
    #2 Add this function call right before Wend in your While loop in FillArrays
    If Mod(N, 500) = 0 Then
      ReportProgress(t/(72*Pi))
    End If
    
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Very nice Petr!

    A growing pie let the time (in some way) pass quickly !
    It's a new relativistic postulate unable to be explained
    Attached Images Attached Images
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    Petr, this is what i thought of before but don't know how to do that, thanks for this addition.
    i have found also that we don't need to dimension the structured arrays in exact number previously, so this is good, this is my new approach:
    Global VertexA(1) As TBGL_TVECTOR3F
    Global ColorA(1) As TBGL_TRGB
    and in the FillArrays sub we do depends on
    ReDim Preserve VertexA(n)
    ReDim Preserve ColorA(n)
    to resize the arrays, it consumes a little additional time
    here is the simpsons curve again but adding the Eros and Petr suggestions about loading data from external files, and the adding of the waiting animation
    but i am confused by the addition of #INCLUDE "BartSimpsons.tbasic" inside the loop: While t <= 72*Pi , is it executed every time the loop run ?, my hard disk led does not work in my computer so i can't see the hard disk activity while waiting the calculation. but i think it runs once somehow by monitoring the execution time.
    Uses "TBGL"
    Uses "math" 
     
    Function TBMain()
      Local hWnd      As DWord
      Local FrameRate As Double
       
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers - press ESC to quit", 600, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow  
       
      TBGL_BackColor 255,255,255
     
      ' -- Create points buffer
      Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
      'Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_LineStrip, %TBGL_3D)
        
      ' -- Define data for it
      Global VertexA(1) As TBGL_TVECTOR3F
      Global ColorA(1)  As TBGL_TRGB
      
      FillArrays ' call the sub to fill VertexA , ColorA  arrays
     
      ' -- Create buffer dynamically linked to the arrays above
      TBGL_GBufferDefineFromArray(gbPoints, %TBGL_DYNAMIC, CountOf(VertexA), VertexA(1), ColorA(1))
      
      ' -- Resets status of all keys 
      TBGL_ResetKeyState()
        
      ' -- Main loop
      While TBGL_IsWindow(hWnd)
      
        FrameRate = TBGL_GetFrameRate
        
        TBGL_ClearFrame
          TBGL_Camera(0, 0, 100, 0, 0, 0)
           
          ' -- Turn triangle
          TBGL_Rotate GetTickCount/50, 0, 1, 0
                                   
          ' -- Render it                              
          TBGL_GBufferRender(gbPoints)   
            
        TBGL_DrawFrame
     
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
     
      Wend        
      ' -- Destroying the buffer is not necessary,
      ' -- the garbage collector will take care of it
     
      ' -- Destroy window
      TBGL_DestroyWindow
    End Function  
    
    Sub FillArrays()
    
    Dim x, y, z, t As Single 
    
    DWord n = 1
    ReDim VertexA(n)
    ReDim colorA(n)
           
    While t <= 72*Pi
              #INCLUDE "BartSimpsonsData.tbasic"
              
              VertexA(n).x = x*0.04
              VertexA(n).y = y*0.04
              ColorA(n).r = 255 :ColorA(N).g = 0 :ColorA(N).b = 0 
                    
            
        t + 0.01 : n + 1
        ReDim Preserve VertexA(n)
        ReDim Preserve ColorA(n)
    If Mod(n, 500) = 0 Then
      ReportProgress(t/(72*Pi))
    End If    
    Wend
     
    End Sub  
    
    Function theta(a As Single) As Single
       If a<=0 Then
        Function = 0
        Else
        Function = 1
       End If
    
    End Function
    
    Function ReportProgress(ratio As Number)
      Single i
      Single radians       
       
      ' -- Whatever color is set inside block, we want it to be reset to white
      ' -- once block is finished
      TBGL_PushColor 255, 255, 255      
       
        TBGL_ClearFrame          
          TBGL_Rotate 360*ratio/2+180 ' -- Rotating the following shape to appear symetrical
         
          TBGL_Color 255,255-255*ratio,255-255*ratio ' -- Nice color fade out
           
          TBGL_BeginPoly %GL_POLYGON
           
            TBGL_Vertex 0, 0, -1 
             
            For i = 0 To 360*ratio Step 0.1
              radians = DegToRad(-i+90)          
              TBGL_Vertex Cos(radians)*0.1, Sin(radians)*0.1, -1          
            Next
             
          TBGL_EndPoly 
           
        TBGL_DrawFrame 
       
      TBGL_PopColor 
       
    End Function
    
    Attached Files Attached Files

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Quote Originally Posted by primo View Post
    but i am confused by the addition of #INCLUDE "BartSimpsons.tbasic" inside the loop: While t <= 72*Pi , is it executed every time the loop run ?
    #Include is resolved just once during pre-parsing of thinBasic scripts.
    Code founds into included files is just included once regardless where #Include is placed.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Performance Tests
    By Charles Pegge in forum O2h Compiler
    Replies: 18
    Last Post: 18-07-2009, 12:21
  2. I need some speed tests
    By ErosOlmi in forum Suggestions/Ideas discussions
    Replies: 11
    Last Post: 11-01-2008, 23:27
  3. Sample script to prepare you on tests
    By Petr Schreiber in forum thinBasic General
    Replies: 0
    Last Post: 16-08-2006, 20:46

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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