Results 1 to 10 of 10

Thread: How to combine GBuffers & Entities?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,525
    Rep Power
    170

    How to combine GBuffers & Entities?

    Is there a possibility to use the functionality of GBuffers ( TBGL_GBufferDefineFromArray ) to blast the data directly into an entity (static) or is there a way if one could send or copy that GBuffer to a displaylist as first?

    Or can't i just create some virtual Entity upon the GBuffer?

    It's mostly about the speed and i want to use the entity-system.

    Passing all data at once is much faster then each vertex line by line.
    Also saving to binary would make sense then.

    Any ideas? Functionslot is no option here...

    Were it possible to add a native (fast) function to load *.obj-files into displayllist/entity? I have to admit, *.obj is not my first choice since they lack vertex-colors but they are widely common and since we don't have no own Entity-Format yet - probably because of slow loading-speed...
    Last edited by ReneMiner; 24-10-2014 at 12:17.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Rene,

    this is custom GBufferEntity, which you can modify. Let me know...


    Petr
    Attached Files Attached Files
    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

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,525
    Rep Power
    170
    that seems to work.

    Now have something to play with
    Only bug - you forgot to change %eBox to %eGBuffer in the example when rotating - on first turn it crashed. But thats minor - i found it.
    I think there are missing some Forum-sections as beta-testing and support

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,525
    Rep Power
    170
    i played a little around- somehow i fear if i set up different fov/aspect the GBuffer-Entity is not affected by the setting as i know it from 3d-fonts - not tried out yet...

    But anyway I wrapped a little -all hidden at heap-memory, be surprised what's possible in thinBasic - and the code reads now like that:
    Uses "TBGL" 
    
    #INCLUDE "t_Entity.tBasicU"
    
    Begin Const
      ' -- Scene IDs
      %sScene  = 1
    End Const 
    
    Function TBMain()
      Local hWnd As DWord
      Local FrameRate As Double
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit",    _
                                 640, 480, 32,                         _
                                 %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX ) 
      
      TBGL_ShowWindow 
    
      ' -- Create scene
      TBGL_SceneCreate(%sScene)
    
      ' create entities from 0 - don't have even a real local variable
    
      Local Entity As t_Entity At 0
      
      SetAt( Entity, Entity.Create(%sScene, %TBGL_CAMERA) )
    
             Entity.SetPos(0, 10, 20)
             Entity.SetTargetPos( 0, 0, 0)  
      %hCamera = GetAt( Entity ) As DWord ' if want to store it...
      
      ' -- Create directional light, don't need its ptr...  
      SetAt( Entity, Entity.Create(%sScene, %TBGL_LIGHT, %TBGL_LIGHTTYPE_DIRECTIONAL) )
    
             Entity.SetPos(0, 25, 20) ' above camera
             Entity.SetTargetPos( 0, 0, 0)  
             Entity.SetParent( %hCamera )
      
      ' -- Define data for mesh   
      
      ' -- Vertices
      
      Dim VertexA(3) As TBGL_TVECTOR3F At HEAP_Alloc( 3 * SizeOf(TBGL_TVECTOR3F) )    
      
      VertexA(1).x = -2
      VertexA(1).y = -2
      VertexA(1).z = 0
      
      VertexA(2).x = 2
      VertexA(2).y = -2     
      VertexA(2).z = 0  
      
      VertexA(3).x = 0
      VertexA(3).y = 2
      VertexA(3).z = 0  
      
      ' -- Colors
      
      Dim ColorA(3) As TBGL_TRGB At HEAP_Alloc( 3 * SizeOf(TBGL_TRGB) )
      
      ColorA(1).r = 255
      ColorA(1).g = 128
      ColorA(1).b = 64
      
      ColorA(2).r = 0
      ColorA(2).g = 255
      ColorA(2).b = 0  
      
      ColorA(3).r = 0
      ColorA(3).g = 0
      ColorA(3).b = 255 
      
      ' -- Entity                     
    
      %hTriangle = Entity.Create(%sScene,             _
                                 %TBGL_GBufferStatic, _
                                 %TBGL_TRIANGLES,     _
                                 GetAt(VertexA),      _
                                 GetAt(ColorA)        )
    
      
      
      TBGL_ResetKeyState() 
      
      ' -- Main loop
      While TBGL_IsWindow(hWnd) 
        FrameRate = TBGL_GetFrameRate
    
        TBGL_ClearFrame 
    
          TBGL_SceneRender(%sScene)
          
        TBGL_DrawFrame 
    
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While 
    
        If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
    
          SetAt( Entity, %hTriangle )
                 Entity.Turn( 0,-90/FrameRate, 0)
    
        ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
    
          SetAt( Entity, %hTriangle )
                 Entity.Turn( 0, 90/FrameRate, 0)
    
        ElseIf TBGL_GetWindowKeyState(hWnd, %VK_UP) Then
    
          SetAt( Entity, %hCamera )
                 Entity.Move( 0, 16/FrameRate, 0 )
                 Entity.SetTarget( %hTriangle )  
    
        ElseIf TBGL_GetWindowKeyState(hWnd, %VK_DOWN) Then
    
          SetAt( Entity, %hCamera )
                 Entity.Move( 0, -16/FrameRate, 0 )
                 Entity.SetTarget( %hTriangle )  
    
        EndIf
    
      Wend 
    
      TBGL_DestroyWindow
    End Function
    
    just a raw sketch, the entity does not have a texture yet, neither is the DisplayList-creation done...

    As you probably see- it's all arranged to have a future Mesh-udt that's single entities (groups) can have different types of data.
    Attached Files Attached Files
    Last edited by ReneMiner; 28-10-2014 at 14:39.
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,525
    Rep Power
    170
    one more question:

    is it possible to retrieve the pointers of vertex-, color-, normal- and texel-array from a once setup-GBuffer again?
    Or do i have to save them to some variable?
    I think there are missing some Forum-sections as beta-testing and support

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Rene,

    I would recommend to store them to data of the GBufferEntity - it should be fast enough.


    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

  7. #7
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,525
    Rep Power
    170
    one more about this topic, help says for TBGL_GBufferCreate

    Syntax
    TBGL_GBufferCreate( gType, gDims )

    parameter-description for gType

    Use one of the following equates:
    %TBGL_POINTS
    %TBGL_LINES
    %TBGL_LINESTRIP
    %TBGL_LINELOOP
    %TBGL_TRIANGLES
    %TBGL_TRIANGLEFAN
    %TBGL_TRIANGLELOOP
    %TBGL_QUADS
    %TBGL_QUADSTRIP
    %TBGL_POLYGON
    this can not be correct.
    There is missing %TBGL_TRIANGLESTRIP while %TBGL_TRIANGLELOOP is not recognized as keyword by thinAir...

    however- it took me a while to find out what went wrong and how to solve it...
    Last edited by ReneMiner; 10-11-2014 at 09:38.
    I think there are missing some Forum-sections as beta-testing and support

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Rene,

    my apologies - nothing worse than bad docs, and now I fell into this category!
    I will fix it for next release!


    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

  9. #9
    the Entity from Gbuffers deserve to be added to the official thinbasic distribution Like Entity from display List or from a Function
    it is much speedier than display list for some tasks
    here is a proof using the Petr example above
    galaxy shape from display list: 600000 points : FPS= 20
    galaxy shape from Gbuffer: 600000 points : FPS= 60

    from display list:
    'adapted from:
    ' The entity skeleton for TBGL
    ' Petr Schreiber, started on 10-25-2014
    '
    #Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc" 
    
    Uses "TBGL" 
    
    Begin Const
      ' -- Scene IDs
      %sScene  = 1
     
      ' -- Entity IDs 
      %eCamera = 1
      %lMyPoints 'display List number
      %ePoints   'the number to represent the Entity made from the Display List      
    End Const 
    
    Function TBMain()
      Local hWnd As DWord
      Local FrameRate As Long 'Double
      Global tot As Long
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow 
    
      ' -- Create scene
      TBGL_SceneCreate(%sScene)
    
      ' -- Create basic entities
      ' -- Create camera to look from 15, 15, 15 to 0, 0, 0 
      TBGL_EntityCreateCamera(%sScene, %eCamera)
        TBGL_EntitySetPos(%sScene, %eCamera, 0, 3, 8)
        TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)  
      
      TBGL_EntityCreateDLSlot(%sScene, %ePoints, 0, %lMyPoints)
      TBGL_EntityCreateDLSlot(%sScene, %ePoints, 0, %lMyPoints) 
       
        TBGL_EntitySetColor(%sScene, %ePoints, 255, 255, 255)
        TBGL_EntitySetPos(%sScene, %ePoints, 0, 0, 0)
      
        ' -- Define data for it
      DrawPoints()
      
      ' -- Resets status of all keys 
      TBGL_ResetKeyState() 
      
      'TBGL_PointSize 2
      'glEnable(%GL_POINT_SMOOTH)
      TBGL_UseLighting %FALSE
      ' -- Main loop
      While TBGL_IsWindow(hWnd) 
        FrameRate = TBGL_GetFrameRate                                                    
        TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+"  points = "+Str$(tot))
        
        TBGL_EntityTurn(%sScene, %ePoints, 0,30/FrameRate, 0)
        TBGL_ClearFrame 
    
          TBGL_SceneRender(%sScene)
          
        TBGL_DrawFrame 
    
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While 
    
        If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
          TBGL_EntityTurn(%sScene, %ePoints, 0,-90/FrameRate, 0)
        ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
          TBGL_EntityTurn(%sScene, %ePoints, 0, 90/FrameRate, 0)
        End If
    
      Wend 
    
      TBGL_DestroyWindow
    End Function
    
    Sub DrawPoints()
    Dim e As Single
    Dim x, y, z, y1 As Single
    Dim rand, indx As Long
    e = 2.718281828459
    x=-4: z=-4
    TBGL_NewList %lMyPoints
    TBGL_BeginPoly %GL_POINTS
         While z<= 4
         'Randomize
            While x<=4
            'Randomize
            tot = tot + 1
            If x*x+z*z<=13 Then
              y = Pow(e,(0.1-x*x-z*z)) ' the formula  
            'Repeat
             rand = Rnd(-1,1)'Rnd(-2,2)
            'Until rand <> 0 ' To Get rid of Value zero
            y1 = y * rand + Rndf(0.1, 0.4)' y * rand: let the point go up And down the galaxy disk, Rndf(0.1, 0.4): And let the disk have Some thickness like a sponge
            
            Select Case y
              Case <=0.00005
                TBGL_Point(x,y1, z)
                TBGL_Color(50,255,0)
              Case <=0.001
                TBGL_Point(x,y1, z)
                TBGL_Color(255,200,0) 'orange 
              Case <=0.01
                TBGL_Point(x,y1, z)
                TBGL_Color(255,20,0) 'red
              Case <=0.8
                TBGL_Point(x,y1, z)
                TBGL_Color(0,160,255) 'bluesh
              Case >0.8
                TBGL_Point(x,y1, z)
                TBGL_Color(255,255,255) 'white
             End Select 
              
         End If
         
       x+0.01
       Wend
       x = -4
      
     z+0.01
     Wend
     '================================================
      
     TBGL_EndPoly
     TBGL_EndList  
      
    End Sub
    
    from Gbuffer: needs the file "GBufferEntity.tBasicU" inside GBufferAsEntity.zip by Petr posted above
    'adapted from:
    ' The entity skeleton for TBGL
    ' Petr Schreiber, started on 10-25-2014
    '
    #Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc" 
    
    Uses "TBGL" , "Console"
    #Include "GBufferEntity.tBasicU"
    
    Begin Const
      ' -- Scene IDs
      %sScene  = 1
     
      ' -- Entity IDs 
      %eCamera = 1
      '%eLight
      %eGBuffer            
    End Const 
    
    Function TBMain()
      Local hWnd As DWord
      Local FrameRate As Long 'Double
      Global i  As Long ' number of points
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow 
    
      ' -- Create scene
      TBGL_SceneCreate(%sScene)
    
      ' -- Create basic entities
      ' -- Create camera to look from 15, 15, 15 to 0, 0, 0 
      TBGL_EntityCreateCamera(%sScene, %eCamera)
        TBGL_EntitySetPos(%sScene, %eCamera, 0, 3, 8)
        TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)  
     
      TBGL_EntitySetPos(%sScene, %eGbuffer, 0, 0, 0)
      
      %eGbuffer = GbufferEntity_Create(%sScene, %TBGL_POINTS, %TBGL_3D)
      
      Global NumOfPoints = 641601
      ' -- Define data for it
      Global VertexA(NumOfPoints) As TBGL_TVECTOR3F
      Global ColorA(NumOfPoints)  As TBGL_TRGB   
                                
      GBufferEntity_DefineFromArray(%sScene, %eGbuffer, %TBGL_DYNAMIC, NumOfPoints, VertexA(1), ColorA(1))  
                       
        ' -- Define data for it
      DrawPoints()
      
      ' -- Resets status of all keys 
      TBGL_ResetKeyState() 
      
      'TBGL_PointSize 2
      'glEnable(%GL_POINT_SMOOTH)
      TBGL_UseLighting %FALSE
      ' -- Main loop
      While TBGL_IsWindow(hWnd) 
        FrameRate = TBGL_GetFrameRate                                                    
        TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+"  points = "+Str$(i))
        
        TBGL_EntityTurn(%sScene, %eGbuffer, 0,30/FrameRate, 0)
        TBGL_ClearFrame 
    
          TBGL_SceneRender(%sScene)
          
        TBGL_DrawFrame 
    
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While 
    
        If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
          TBGL_EntityTurn(%sScene, %eGbuffer, 0,-90/FrameRate, 0)
        ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
          TBGL_EntityTurn(%sScene, %eGbuffer, 0, 90/FrameRate, 0)
        End If
    
      Wend 
    
      TBGL_DestroyWindow
    End Function
    
    Sub DrawPoints()
    Dim e As Single
    Dim x, y, z, y1 As Single
    Dim rand, indx As Long
    e = 2.718281828459
    x=-4: z=-4
    
         While z<= 4
         'Randomize
            While x<=4
            'Randomize
             i = i + 1
            If x*x+z*z<=13 Then
              y = Pow(e,(0.1-x*x-z*z)) ' the formula  
            'Repeat
             rand = Rnd(-1,1)'Rnd(-2,2)
            'Until rand <> 0 ' To Get rid of Value zero
            y1 = y * rand + Rndf(0.1, 0.4)' y * rand: let the point go up And down the galaxy disk, Rndf(0.1, 0.4): And let the disk have Some thickness like a sponge
            
            Select Case y
              Case <=0.00005
                VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
                ColorA(i).r=50: ColorA(i).g=255: ColorA(i).b=0
              Case <=0.001
                VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z 
                ColorA(i).r=255: ColorA(i).g=200: ColorA(i).b=0 'orange 
              Case <=0.01
                VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
                ColorA(i).r=255: ColorA(i).g=20: ColorA(i).b=0 'red
              Case <=0.8
                VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
                ColorA(i).r=0: ColorA(i).g=160: ColorA(i).b=255 'bluesh
              Case >0.8
                VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
                ColorA(i).r=255: ColorA(i).g=255: ColorA(i).b=255 'white
             End Select 
              
         End If
         
       x+0.01
       Wend
       x = -4
      
     z+0.01
     Wend
     '================================================
      
    End Sub
    
    suggestion 2: powerBasic lacks a good 3D graphics engine, we can't consider OpenGL an engine for the home users. also the available xors3d and N3xtD depends on DirectX9, the xors3d is abandoned and the N3xtD depends on the DX9. most users of windows 10 usualy don't like to install DX9 on their machines even for psychological reasons only. while Opengl is backward compatible . so the door is open to provide especialy the Petr entity system friendly and easy to use to the powerbasic users. you can sell the engine in windows store for 29$.
    https://www.microsoft.com/store/apps
    when you do this i will buy powerbasic v10 immediately.

  10. #10
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Primo,

    thank you very much for your kind words, it really made my day

    As for GBuffer entity - I will have a look at it, it would nicely complete the set.

    To get further performance improvements... I will check some OpenGL extensions. I am playing with Vulkan as well. It has huge performance boost, but it is very fragile.


    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

Similar Threads

  1. The silence inside the fractal - GBuffers (how many may be used ?)
    By RobbeK in forum TBGL Scripts and Projects
    Replies: 35
    Last Post: 24-01-2014, 12:18
  2. Entities again...
    By ReneMiner in forum TBGL General
    Replies: 6
    Last Post: 17-05-2013, 10:59
  3. Preview: GBuffers for TBGL
    By Petr Schreiber in forum TBGL module by Petr Schreiber
    Replies: 11
    Last Post: 04-03-2010, 11:33
  4. Scenes and Entities
    By Intio in forum thinBasic General
    Replies: 2
    Last Post: 09-12-2008, 20:44
  5. Bone deformation and entities
    By Michael Hartlef in forum TBGL General
    Replies: 7
    Last Post: 16-02-2008, 02:16

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
  •