About Monkey 2 › Forums › Monkey 2 Programming Help › Terrain tiling shows borders
This topic contains 2 replies, has 2 voices, and was last updated by
Pakz 1 year ago.
-
AuthorPosts
-
April 13, 2018 at 7:11 am #14339
I had the idea to use terrains to tile with but somehow I got the effect that around each terrain there is a lighter border. Can anyone shed some light on this?
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"Using std..Using mojo..Using mojo3d..Global mapsize:Int=32Class MyWindow Extends WindowField _scene:SceneField _camera:CameraField _light:LightField _material:MaterialField _terrain:Model[,]Field map:Int[,] = New Int[10,10]Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )Super.New( title,width,height,flags )map[5,5] = 1startgame()End MethodMethod OnRender( canvas:Canvas ) OverrideRequestRender()Fly( _camera,Self )_scene.Render( canvas)If Keyboard.KeyReleased(Key.Space) Then startgame()canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )canvas.DrawText("Cursor up/down/left/right a/z and Left mouse button - space = new map.",0,20)End MethodMethod startgame()If _scene Then _scene.DestroyAllEntities()_scene = Scene.GetCurrent()'create camera'_camera=New Camera_camera.Near=1_camera.Far=512_camera.Move( 0,66,0 )'create light'_light=New Light_light.RotateX( Pi/2 ) 'aim directional light 'down' - Pi/2=90 degrees._material = New PbrMaterial( Color.Brown,1,0.5 )_material.ScaleTextureMatrix( 32,32 )_terrain = New Model[10,10]For Local y:Int=0 Until 10For Local x:Int=0 Until 10Local heightMap:= New Pixmap(mapsize,mapsize)heightMap = makeheightmap(1)'_terrain=New Terrain( heightMap,New Boxf( -mapsize,0,-mapsize,mapsize,64,mapsize ),_material )_terrain[x,y]=Model.CreateTerrain( heightMap,New Boxf( -32,0,-32,32,32,32 ),_material )_terrain[x,y].CastsShadow=False_terrain[x,y].Move(x*64,0,y*64)heightMap.Discard()NextNextEnd MethodEnd''Function makeheightmap:Pixmap(tile:Int)Local pm:Pixmappm = New Pixmap(mapsize,mapsize)pm.Clear(Color.Black)For Local y:Int=0 Until mapsizeFor Local x:Int=0 Until mapsizepm.SetPixel(x,y,New Color(.5,.5,.5))NextNextReturn pmEnd Function' Taken from the mojo3d testFunction Fly( entity:Entity,view:View )If Keyboard.KeyDown( Key.Up )entity.RotateX( 1 )Else If Keyboard.KeyDown( Key.Down )entity.RotateX( -1 )EndifIf Keyboard.KeyDown( Key.Q )entity.RotateZ( 1 )Else If Keyboard.KeyDown( Key.W )entity.RotateZ( -1 )EndifIf Keyboard.KeyDown( Key.Left )entity.RotateY( 1,True )Else If Keyboard.KeyDown( Key.Right )entity.RotateY( -1,True )EndifIf Mouse.ButtonDown( MouseButton.Left )If Mouse.X<view.Width/3entity.RotateY( 1,True )Else If Mouse.X>view.Width/3*2entity.RotateY( -1,True )Elseentity.Move( New Vec3f( 0,0,.1 ) )EndifEndifIf Keyboard.KeyDown( Key.A )entity.MoveZ( 1 ) '( New Vec3f( 0,0,.1 ) )Else If Keyboard.KeyDown( Key.Z )entity.MoveZ( -1 ) '( New Vec3f( 0,0,-.1 ) )EndifEnd FunctionFunction Main()New AppInstanceNew MyWindowApp.Run()EndI was thinking if I would have prefab terrains it would make scrolling and larger worlds easier.
Attachments:
April 13, 2018 at 9:55 am #14343It looks like discontinuities at the edges of each terrain, perhaps the normals are being incorrectly generated here – will take a look at it.
But even if there is something up here, there will always be discontinuities at the edges I think (except in cases like this where terrains are totally flat) as the vertex normals wont be correctly generated at the edges as they aren’t actually connected to neighboring edge.
This is actually pretty close to how the original terrain that was in there last year worked though (except each tile was just an index buffer and they all shared the same mega vertex buffer) and I think I may resurrect it so hold tight and this may be built in soon!
April 13, 2018 at 6:44 pm #14352Ok. I was just experimenting. I might just as wel just create tile meshes if terrains have those discontinues.
-
AuthorPosts
You must be logged in to reply to this topic.
