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

Thread: PerlinNoise

Share/Bookmark
  1. #11
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    61
    Posts
    3,869
    Rep Power
    397

    Noise Finished

    I finished the noise function. Files are here on GitHub

    I finally settled on making the noise function based on the information located here at Paul Bourke's website:
    http://paulbourke.net/texture_colour/perlin/

    Noise.tbasici is the include file needed to use the dll and functions.

    NoiseDemoCanvasUsingFillNoiseArray.tbasic demo code using the FillNoiseArray function. This is probably what you will want to use most often. Very fast.

    NoiseDemoCanvasManualNoise.tbasic demo where you manually fill the necessary arrays with noise. More control, but slower.
    Click image for larger version. 

Name:	noise.jpg 
Views:	7 
Size:	20.6 KB 
ID:	9712
    Last edited by kryton9; 29-05-2017 at 01:08. Reason: update
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  2. #12
    Hi kryton9
    using a C dll makes the calculations speedier
    but there is a slow rendering with:
    For y = 1 To height
                            For x = 1 To width 
                                glColor4d 255, 255, 255, noise ( x, y ) * alphaScale
                                TBGL_Vertex x, y
                            Next
                        Next
    
    the fps for me is 5
    i have tried the Gbuffer using a template from some examples ,the graphics will be speedy , it is for me about 60. but i have a problem, there is something not correct
    i replace your
     For y = 1 To height
          For x = 1 To width 
             glColor4d 255, 255, 255, noise ( x, y ) * alphaScale
             TBGL_Vertex x, y
              Next
          Next
    
    with positional array vertex(x,y) which are filled from 1-500, 1-500
    the color and alpha for every vertex in another array : noise(x,y)
    noiseNum = PerlinNoise xOff, yOff, 0
    noise(x,y).r = 255
    noise(x,y).g = 255
    noise(x,y).b = 255
    noise(x,y).A = noiseNum * alphaScale
    
    but i don't see the alpha working here
    Uses "TBGL"  
    #INCLUDE "%APP_INCLUDEPATH%thinbasic_gl.inc"  ' to use glColor4d function
    #INCLUDE "PerlinNoise.tbasici"
    
    Double yOff = 0.0
    Double xOff = 0.0
    Long interval = 0   
    Long width = 500 'larger the longer it takes to calculate
    Long height = 500 'larger the longer it takes to calculate 
    Long x = 0 
    Long y = 0
     
    Function TBMain()
      Local hWnd      As DWord
      Local FrameRate As Double
      Long numPoints = width * height  
    String winTitle = "Calculating " + numPoints + " Noise Values, This can take Some time."
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx ( "PerlinNoise 2D GL Demo", width, height, 32, %TBGL_WS_WINDOWED )
      TBGL_ShowWindow  
      TBGL_SetWindowTitle ( hWnd, winTitle)
        
      TBGL_ShowWindow  
    
      Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_2D)
     
      ' -- Define data for it
      Global vertex(width,height) As TBGL_TVECTOR2F
      Global noise(width,height)  As TBGL_TRGBA 'TBGL_TRGB
    
      Dim x,y As Integer
      Double noiseStep = 0.001 'good ranges : 0.1 to 0.00000000000000001
      Double alphaScale = 5  ' ranges: 1 to 1000000000000 
      Double noiseNum
      
      For y=1 To width
        yOff += noiseStep 
        For x=1 To height
          xOff += noiseStep
           
          vertex(x,y).x = x
          vertex(x,y).y = y
          
            noiseNum = PerlinNoise xOff, yOff, 0
            
            noise(x,y).r = 255
            noise(x,y).g = 255
            noise(x,y).b = 255
            noise(x,y).A = noiseNum * alphaScale
            
        Next
      
      Next 
      
    
     Dim NumOfarrayElements As Long = CountOf(vertex(1))* CountOf(vertex(2))
      ' -- Create buffer dynamically linked to the arrays above
      TBGL_GBufferDefineFromArray(gbPoints, %TBGL_STATIC, NumOfarrayElements, vertex(1,1), noise(1,1))
       
      ' -- Resets status of all keys 
      TBGL_ResetKeyState() 
    
      TBGL_BlendFunc %GL_SRC_ALPHA , %GL_ONE
        TBGL_UseBlend %TRUE
        TBGL_RenderMatrix2D ( 1, height, width, 1 ) 
      ' -- Main loop
      While TBGL_IsWindow(hWnd)
      
        FrameRate = TBGL_GetFrameRate
            Incr interval
            If interval > 5 Then
                TBGL_SetWindowTitle ( hWnd, "PerlinNoise 2D GL Demo FPS: " + Str$ ( FrameRate, 4 ) )
                interval = 0
            EndIf
            TBGL_ClearFrame
        
          ' -- Render it 
          TBGL_RenderMatrix2D ( 1, height, width, 1 )                              
          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
    
    Last edited by primo; 14-05-2017 at 12:35.

  3. #13
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    61
    Posts
    3,869
    Rep Power
    397
    Thanks for testing it Primo and for the suggestions. In my demo, I just wanted to show the speed increase from using the dll version. Actually if I were using this in a real program, I would just do a single render to a texture and then just show that in the main loop. Drawing every frame pixel by pixel is not efficient.

    Your program though opens up animating in real time, so I will study your code. I am not an opengl guru like Petr. But I will happily look at it now and see if I can figure it out. Hopefully in the meantime, Petr sees your post and probably knows the answer right away, and will reply quicker.
    Last edited by kryton9; 14-05-2017 at 20:01.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #14
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    61
    Posts
    3,869
    Rep Power
    397
    Primo, TBGL_tRGBA uses byte and not double
    ' -- This type is used by TBGL_GBufferCreate, TBGL_GBufferDefineFromArray
    TYPE TBGL_tRGBA
    R AS BYTE
    G AS BYTE
    B AS BYTE
    A AS BYTE
    END TYPE

    Also TBGL_tVector3F uses singles (floats in C) and not doubles
    ' -- This type is used by TBGL_GBufferCreate, TBGL_GBufferDefineFromArray
    TYPE TBGL_tVector3F
    x AS SINGLE
    y AS SINGLE
    z AS SINGLE
    END TYPE

    I will need to talk about these with Petr to make sure everything is uniform and compatible.

    Thanks again for testing and bringing out these inconsistencies.
    Last edited by kryton9; 14-05-2017 at 20:31.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #15
    thanks kryton9 for testing the code and ideas.
    if the gbuffer code logic in general is right then it should produce the same output as your first code. yes the reason may be the byte choice for alpha channel. tomorrow i will put your perlNoise formula in one of the general opengl codes to see if it will produce the same shape as your first code. but opengl is too complex and i even don't remember my opengl codes, while Gbuffer is easy to use and it is speedy

  6. #16
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    61
    Posts
    3,869
    Rep Power
    397
    Primo, don't waste your time at this stage. I am working on major changes and I will post it when finished for testing.

    I hope to iron out differences with tbgl to make it as compatible as possible.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  7. #17
    kryton9, like Petr said the double in color and alpha have no meaning with real screens.
    but to continue the testing your dll with alpha as single here is the opengl code adapted from old post http://www.thinbasic.com/community/s...uffers-example
    as you can see it provide the same shape (circle of light) as in your first example
    look the :
    Type Point3D
      x As Single
      y As Single
      z As Single 
      red As Single
      green As Single
      blue As Single 
      alpha As Single 'Double
    End Type
    
    using Double make the shape a complete random
    you may use this demo as a template for other testing
    (not optimised so there is too much flicker)
    note: there must me a special care to gluPerspective and the gluLookAt, also the glTranslatef better to be before glDrawArrays which draw the graphics.
    EDIT: note the glColorPointer(4 , the 4 refer to the presence of alpha. if 3 there is no alpha in Type end type
    EDIT2: the TBGL_RenderMatrix2D is great, it replaces many functions. i have added TBGL_RenderMatrix2D( 1, 500, 500, 1 ) before glDrawArrays(%GL_POINTS, 1, 500*500 ) removing the z , and it fixes the flicker, and the shape is 2D . attached the new version, save it to the kryton9 DLL in the first post.
    Uses "tbgl", "MATH"
        
      #INCLUDE "%app_includepath%\thinbasic_gl.inc"
      #INCLUDE "%app_includepath%\thinbasic_glu.inc" 
      #INCLUDE "PerlinNoise.tbasici"
      
      Type Point3D
      x As Single
      y As Single
      z As Single 
      red As Single
      green As Single
      blue As Single 
      alpha As Single 'Double
      End Type 
       
      Dim hwnd As DWord  
      Global Nb As DWord = 500*500
      
      Global Vertex(Nb) As Point3D
      Double yOff = 0.0
      Double xOff = 0.0  
      'msgbox 0, SizeOf(Point3D))
          
      hwnd = TBGL_CreateWindowEx("glDrawArrays example - esc to exit", 500, 500, 32, 0)
      TBGL_ShowWindow
      TBGL_ResetKeyState()
      'TBGL_SetDrawDistance 550
      'TBGL_BackColor 0,0,0
      'glPointSize( 2.0 ) ' just to show the curve in bold
      
      FillArray ' fill Vertex(...) with position data and color data
      
      While TBGL_IsWindow(hwnd)
         TBGL_ClearFrame
        
        display
        TBGL_DrawFrame
        If TBGL_GetWindowKeyState( hwnd, %VK_ESCAPE) Then Exit While
      Wend
        
      TBGL_DestroyWindow
    
    '=================================================================================
    
    '--------------------------------------------------------
    '--------------------------------------------------------   
    Sub display()
    TBGL_BlendFunc %GL_SRC_ALPHA , %GL_ONE
    TBGL_UseBlend %TRUE
    glMatrixMode(%GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(120.0, 500/500, 1.0, 500.0)
    glMatrixMode(%GL_MODELVIEW)
    
    glShadeModel(%GL_SMOOTH) 
    glEnable(%GL_DEPTH_TEST)
    gluLookAt( 0, 0, 100,
               0,  1, 0,
                0, 1,  0 ) 
        glclear(%gl_color_buffer_bit)
          
        TBGL_Rotate GetTickCount/30,0,0,1
          
     glClear(%GL_COLOR_BUFFER_BIT Or %GL_DEPTH_BUFFER_BIT)
     'glClearColor(1, 1, 1, 1)
     
     glEnableClientState(%GL_VERTEX_ARRAY )
     glEnableClientState(%GL_COLOR_ARRAY)
     glVertexPointer(3, %GL_FLOAT,SizeOf(Point3D),VarPtr(Vertex(1).x))
     glColorPointer(4, %GL_FLOAT, SizeOf(Point3D), VarPtr(Vertex(1).red))
          
     glTranslatef(-240, -250, -60)
     glDrawArrays(%GL_POINTS, 1, 500*500 )
          
     glDisableClientState(%GL_COLOR_ARRAY)
     glDisableClientState(%GL_VERTEX_ARRAY)  
      '**************************************************
          
      
      End Sub
      
      Sub FillArray()
      DWord indx = 0 
      Dim  x, y, z As Long
    
      Double noiseStep = 0.001 'good ranges : 0.1 to 0.00000000000000001
      Double alphaScale = 5 ' ranges: 1 to 1000000000000 
      Double noiseNum
      For y=1 To 500
        yOff += noiseStep 
        For x=1 To 500
          xOff += noiseStep
          indx+1             
          Vertex(indx).x = x
          Vertex(indx).y = y
          Vertex(indx).z = 0
           Vertex(indx).red = 1.0 :Vertex(indx).green = 1.0 :Vertex(indx).blue = 1 
            noiseNum = PerlinNoise xOff, yOff, 0
            Vertex(indx).alpha = noiseNum * alphaScale 
    
            
        Next x
    
      Next y
            
                           
      End Sub
    
    Attached Files Attached Files
    Last edited by primo; 15-05-2017 at 16:50.

  8. #18
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    61
    Posts
    3,869
    Rep Power
    397
    Thanks a lot for your help Primo. This will be very helpful to test the new library when finished. Once I get the code to a testable stage I will put it on GitHub, so we can all work on polishing it up together then. That was interesting to see the difference from using single and double in Point3D.alpha
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  9. #19
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    61
    Posts
    3,869
    Rep Power
    397

    finished

    I finished the noise code. It is linked to in the first post here:
    http://www.thinbasic.com/community/s...ll=1#post93572
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  10. #20
    Thanks Kryton9, it is speedy and looks good, and can be used to provide images to build a terrain for the 3d grpahics. i like your idea SeedNoise(2017).
    while searching i find http://www.bugman123.com/Fractals/index.html the site have all colors on the world and he refers also to perl noise and to the paul bourke site

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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