Page 1 of 4 123 ... LastLast
Results 1 to 10 of 38

Thread: Terrain-Texturing

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

    Terrain-Texturing

    I removed the other post from other thread (3d-Editor) about this, because it's something different.
    I was wondering how to create some texture for a terrain, and now - after thinking a few different ways - I came to the conclusion the best way to create some natural looking terrain would be some "spray-paint-method" where the final texture get's sprayed together from a few different texture-resources as gras, rocks, dirt etc.
    That will avoid lots of repetitions and make terrain look as natural as possible.
    And of course the texture can be "sprayed" in real-time to the model in a WYSIWYG-manner so using some additional paint-software is not first choice for this. I think I'll have to create some sBitmap-Data-String and replace parts through data from another bitmap - or would be better to mix colors? I fear they'll look odd and wrong-colored then.

    Probably I'm gonna make another editor for terrains - but I already think about the how-to get there. Maybe someone got a suggest to this?
    Last edited by ReneMiner; 23-04-2013 at 17:24.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    I think I need to do it from scratch- so all works hand-in-hand together on a very low level. And overnight I had already some "input" - I guess I get this included to the 3d-Editor somehow. That might limit the amount of available texture-slots from 1024 down to 1015 - but I think, I can live with that

    A question to this: How can I make a string from format TBGL_Data_BGR/BGRA to become TBGL_Data_RGBA ?
    Last edited by ReneMiner; 24-04-2013 at 09:36.
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    There are multiple options.

    To change from BGRA ro RGBA, you just need to swap two bytes (for Blue and Red channels), so the solution could be to allocate virtual array over the string buffer and swap the components or do it using new Memory_Swap statement.

    If you are harcore guy, this task is ideal task for OpenCL, which is available from ThinBASIC as well. It allows hardware accelerated data paralelism. You could launch micro thread on each RGBA segment and swap it on simple core of GPUs. It would be fast, but not everybody has OpenCL enabled GPU today.


    Petr

    Note: The TBGL_BGRA is preffered format for the GPUs.
    Last edited by Petr Schreiber; 24-04-2013 at 09:48.
    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
    Perlin noise is a way of creating texture. It works by generating chaotic values, interpolated at different frequencies, arranged in octaves. Good for cloudy skies, sand, and anything else in between.

    Perlin noise can be tiled, when the lowest frequency (longest wavelength) fits into each tile by an integer factor.

    Attached demo noise generator control. (Antivir/Avira may dislike it). You can adjust colors by RGB or HLS, and mix the different octaves. The color values are not clamped so you can get overflows, which are quite interesting in themselves.

    Charles
    Attached Files Attached Files
    Last edited by Charles Pegge; 24-04-2013 at 11:41.

  5. #5
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    Noise is nice idea - especially for clouds, water & fog - but currently is more about ground as sand, rock, gravel, cobbles, mud etc.

    Example runs fine without any complains from Windows-Defender.


    OT:
    Since I heard you're the hexagon-expert: Is it possible to cover a sphere (does not have to be a geometrical perfect one) with similar hexagonal tiles (which do not have to be perfect mathematical hexagons) - so I could create a planet-like ball - maybe north- and southpoles can be covered with ice, so don't need hexagonal tiles there. Can be a little elliptic as earth (wider than high) - no perfect sphere needed.
    I intend to create a base for strategy-game, where all tiles have to be the same shape - so there might be a solution if the hexagons are not real ones but bent upper and lower corner(yellow) 1.5° away from surface(white) and also upper (blue) belt is smaller than lower belt (purple). Can turn them upside down below equator - but all tiles have to be even. Any idea to this?

    Edit: Petr, I think I'll keep it OpenGL - so final runs on all users systems. Otherwise someone will probably complain a whole week about
    Attached Images Attached Images
    Last edited by ReneMiner; 24-04-2013 at 12:11.
    I think there are missing some Forum-sections as beta-testing and support

  6. #6
    Hexagons won't make a sphere, unfortunately. You will always need 12 pentagons, or 6 squares to go with them. But what you can do is create an inflated cube. One grid for each of the 6 faces. Each node is adjusted (normalised) so that it relocates onto the surface of the sphere. As you can see the squares become increasingly distorted as they approach the corners, but I think this will give you the best mapping for texturing and zoning.

    Each cube face has 16 panels in this dome

  7. #7
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    I need some PlugIn to see it - but PlugIn not available
    I think there are missing some Forum-sections as beta-testing and support

  8. #8
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    Too bad, there's no compatible JRE-PlugIn for Mozilla that will install automatic - if I install manually and enable, my browser crashes/ does not respond any more

    To keep near topic, some informational about current state/ideas:

    In the meantime I started a new project, which is all about terrain-editing + scene setup. To create terrains with TBGL3dEd would be to cumbersome and waste a lot of resources - since terrains with fixed sizes don't need X+Z nor flexible UV, but just heights, vertex-normals and colors and consist of one group only.
    So I'm up to create a world from fixed terrain-meshes which are 32*32 square tiles consisting of 2 triangles, each tile 32 screen-units in size, so one terrain-mesh is 1024 screen-units wide. Also I make some rule so even tiles [(1,1),(1,3)...] have diagonal line from lower left to upper right while odd tiles [(1,2),(1,4)... just add indexes to get even/odd...] have diagonals from upper left to lower right. So the hills won't bent to one side.

    For the time being TBGL3dEd will maintain in a Beta-stage because it's supposed to work together with the world-editor later so one can drag objects from somewhere else into the world and place them. Also the final mesh-format to write to is undecided yet and some little misbehavement of tB when loading associated files has to be corrected before a final .exe of TBGL3dEd will be published.


    I created a simple "texture-file-format" for some to this related purpose, - spraypaint the terrains texture together from different others - that's just how I save it:
    Function IMAGE_SaveBGRA(ByVal sFile As String, _
                            ByVal sImageData As String, _
                            ByVal lWidth As Long, _
                            ByVal lHeight As Long) As Boolean
                            
      Local fNum As DWord
      
      If Len(sFile) > 3 Then 
        If Mid$(sFile, 2, 2) <> ":\" Then sFile = TEXTURES_Path + sFile
        If Ucase$(FILE_PathSplit(sFile, %PATH_EXT)) <> "DATABGRA" Then sFile += ".DataBGRA"
      Else
        sFile = TEXTURES_Path + sFile + ".DataBGRA"
      EndIf
      
      If FILE_Exists(sFile) Then FILE_Kill(sFile)
      fNum = FILE_Open(sFile, "BINARY")
      If Not fNum Then Return FALSE
    
      FILE_Put(fNum, MKL$(lWidth))
      FILE_Put(fNum, MKL$(lHeight))
      FILE_Put(fNum, sImageData)
      FILE_Close(fNum)
      
      Function = TRUE
      
      
    End Function
    
    sImageData is some string that holds valid data to do the following:
    TBGL_MakeTexture sImageData, %TBGL_DATA_BGRA, lWidth, lHeight, lTexID, %TBGL_TEX_MIPMAP
    
    And these are the current functions to convert to BGRA - maybe someone has an idea to do this faster?
    Function IMAGE_RGBA_to_BGRA(ByVal sRGBAData As String) As String
    
      Local lPos       As Long 
      Local sImageData As String
      
      While lPos < Len(sRGBAData)
        sImageData += StrReverse$(Peek$(StrPtr(sRGBAData) + lPos, 3)) + Peek$(StrPtr(sRGBAData) + lPos + 3, 1)    
        lPos += 4
      Wend
      
      Function = sImageData
      
    End Function
    
    ' ------------------------------------------------------------------------- 
    Function IMAGE_BGR_to_BGRA(ByVal sBGRData As String) As String
    
      Local lPos       As Long 
      Local sImageData As String
      
      While lPos < Len(sBGRData)
        sImageData += Peek$(StrPtr(sRGBData) + lPos, 3) + Chr$(255)
        lPos += 3
      Wend
      
      Function = sImageData
      
    End Function
    
    Last edited by ReneMiner; 25-04-2013 at 11:42.
    I think there are missing some Forum-sections as beta-testing and support

  9. #9
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171

    Snoop-In Preview Terrain-Ed

    Here for the nosy users some preview-example of TerrainEd which is current work in progress. It has no texturing yet - so no FreeImage - FILE-Unit is not included- but runs without from thinAir. Needs #Minversion 1.9.5.0, big screen recommended.


    Currently its just some endless world (5*5 Meshes Terrain are shown) and can be edited just using mouse. No load/save yet- also a few menuitems which are currently just dummies are without functionality - or give only debug-console-output for something totally different...

    Left Button.........Action!
    Right Button........Move Camera
    Middle Button.......Move Map
    Turn Wheel..........Zoom In and Out
    CTRL + Left-Click...Go to clicked Position
    CTRL + Wheel........Change Pointer-size
    SHIFT + Wheel.......Change Landheight

    The SHIFT+Wheel-combination works always to alter height, so don't need to change tool for that.

    Shortcuts:
    F1 - Landheight (hold LeftMouseButton and pull land up or down)
    F2 - Flatten (click LMB to level surrounding to height of cursor-position)
    F3 - Soften (click LMB to soften)
    F4 - Texture (NOT AVAILABLE)
    F5 - Colorize (LMB to apply a color)

    The textboxes on menubar show the current cell coordinates as follows:
    Fist box shows North/South - (red corner in 3d-pointer points always north), larger numbers/positive direction is north
    Second box shows East/West - east is positive direction here

    feel free to use for personal and non-commercial projects

    I'm still undecided how to get texture onto it- the only thing I know for sure - there has to be just one texture per mesh, otherwise it would use up too much time if it has to be drawn in different groups.

    Edit: Attachement exchanged 05.05.2013

    To see water go menu View, check "Show Water". The number below allows to alter Water-Height. Is better editing landheights if water hidden, otherwise mousepointer points on water-surface
    Last edited by ReneMiner; 09-05-2013 at 14:08.
    I think there are missing some Forum-sections as beta-testing and support

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quote Originally Posted by ReneMiner View Post
    And these are the current functions to convert to BGRA - maybe someone has an idea to do this faster?
    Function IMAGE_RGBA_to_BGRA(ByVal sRGBAData As String) As String
    
      Local lPos       As Long 
      Local sImageData As String
      
      While lPos < Len(sRGBAData)
        sImageData += StrReverse$(Peek$(StrPtr(sRGBAData) + lPos, 3)) + Peek$(StrPtr(sRGBAData) + lPos + 3, 1)    
        lPos += 4
      Wend
      
      Function = sImageData
      
    End Function
    
    ' ------------------------------------------------------------------------- 
    Function IMAGE_BGR_to_BGRA(ByVal sBGRData As String) As String
    
      Local lPos       As Long 
      Local sImageData As String
      
      While lPos < Len(sBGRData)
        sImageData += Peek$(StrPtr(sRGBData) + lPos, 3) + Chr$(255)
        lPos += 3
      Wend
      
      Function = sImageData
      
    End Function
    
    Try this one, should be some many X times faster:
    Function IMAGE_RGBA_to_BGRA(ByVal sRGBAData As String) As String
      Local lPos        As Long
     Local pByte       As DWord
        
      pByte = StrPtr(sRGBAData) 
      For lPos = 0 To Len(sRGBAData) - 1 Step 4
        Memory_Swap(pByte + lPos, pByte + lPos + 2, 1)
      Next
      
      Function = sRGBAData
    
    
    End Function
    
    Maybe I can add some thinBasic native function (compiled) doing that job. They should be some thousands faster.
    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

Page 1 of 4 123 ... LastLast

Similar Threads

  1. Sphere Texturing
    By zak in forum TBGL General
    Replies: 1
    Last Post: 10-06-2011, 18:40
  2. texturing model by one picture stretched
    By zak in forum TBGL General
    Replies: 3
    Last Post: 11-09-2010, 20:29
  3. M15 texturing - UV Coordinates
    By dcromley in forum M15 file format
    Replies: 5
    Last Post: 06-04-2009, 08:41
  4. 9 terrain matrix
    By kryton9 in forum Resources
    Replies: 13
    Last Post: 05-07-2007, 00:32

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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