Sanctus Posted May 4, 2010 Share Posted May 4, 2010 Since I decided to use the terrain leadwerks provides to save myself from some headaches i started to play around with it and got into a weird problem. There is absolutely no info on BlendTerrainTexture on wiki. I basically want to be able to paint my terrain programatically. I see it takes x and y as parameters and I guess those work just the same as the ones from the height commands. The next value is alpha. From what I sniffed around to see I guess it's in range from 0 to 1. Finally there's the layer. I made a terrain with one base layer (0) and 3 other layers. I want to programatically be able to set which one is visible the most. First problem I had is that there is no command to get the blend alpha. I managed to store it separately as a temporary fix. Now I just call this For Local x:Int = px - radius / 2 To px + radius / 2 For Local y:Int = pz - radius / 2 To pz + radius / 2 Local d:Float = (radius / 2 - Dist2(px, pz, x, y)) If d < 0 d = 0 End If Local h:Float = d / radius * strength Local oa:Float = layerAlpha[layer, y + Width / 2, x + Height / 2] / 255.0 Local na:Float = h + oa If na > 1 Then na = 1 If na < 0 Then na = 0 BlendTerrainTexture(terrain, y + Width / 2, x + Height / 2, na, layer) layerAlpha[layer, y + Width / 2, x + Height / 2] = (na) * 255 Next Next Please ignore the fact that x and y are in the reverse order. the same algorithm works very nice for the elevation so the problem is clearly not there. As I press and hold the mouse click on one spot the terrain gets more like a layer's texture. Problem is that it doesn't "go towards" the right layer. It always seems to get like the last texture from the layers. I verified a couple of things in debug: the variable layer has the right value. In the terrain on the layerarray the textures used there are the right ones. Problem must be either in this function or me not calling it right (which I guess it's excusable since there is no documentation). Can anyone help me with this? (I know the code is in BlitzMax but I figure out anyone can understand what's happening there) Quote I create the game you play. I create the rulles you will obey. Link to comment Share on other sites More sharing options...
Sanctus Posted May 5, 2010 Author Share Posted May 5, 2010 Did some more sniffing around and I don't think it's my fault Here is a small example: Framework leadwerks.engine SuperStrict RegisterAbstractPath(AppDir) Graphics(1024, 768) Global world:TWorld = CreateWorld() Global buffer:TBuffer = CreateBuffer(1024, 768, BUFFER_DEPTH | BUFFER_COLOR | BUFFER_NORMAL) Global camera:TCamera = CreateCamera() Global terrain:TTerrain = CreateTerrain(512) Global dirLight:TLight = CreateDirectionalLight() RotateEntity(dirLight, Vec3(45, 45, 0)) PositionEntity(camera, Vec3(20, 20, 20)) PointEntity(camera, terrain) SetTerrainTexture(terrain, LoadTexture("abstract::grass.dds"), 0, 0) SetTerrainTexture(terrain, LoadTexture("abstract::mud.dds"), 0, 1) SetTerrainTexture(terrain, LoadTexture("abstract::dirt.dds"), 0, 2)'-Commenting this will make the first texture work with set blend BlendTerrainTexture(terrain, 256, 256, 1, 1)' -\___Both do the exact same thing(actually show only the last texture loaded) BlendTerrainTexture(terrain, 256, 256, 1, 2)' -/ SetTerrainTextureConstraints(terrain, 0, 90, 0, 100, 1)'--Has no effect SetTerrainTextureConstraints(terrain, 0, 90, 0, 100, 2)'--Has no effect While Not KeyHit(KEY_ESCAPE) SetBuffer(buffer) RenderWorld() SetBuffer(BackBuffer()) RenderLights(buffer) Flip() WEnd I wrote on the comments what happens and when. I really don't think it should work that way. Quote I create the game you play. I create the rulles you will obey. Link to comment Share on other sites More sharing options...
Josh Posted May 13, 2010 Share Posted May 13, 2010 Please post the texture files you used here. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Sanctus Posted May 13, 2010 Author Share Posted May 13, 2010 I sent the textures to you by mail. Quote I create the game you play. I create the rulles you will obey. Link to comment Share on other sites More sharing options...
Josh Posted May 18, 2010 Share Posted May 18, 2010 This function will handle the blending for you: Function BlendTerrainTexture2(terrain:TTerrain, x:Int, y:Int, h:Float[]) glBindTexture GL_TEXTURE_2D,terrain.alphatexture.reference._index glTexSubImage2D GL_TEXTURE_2D,0,y,x,1,1,GL_RGBA,GL_UNSIGNED_BYTE,[byte(h[0]*255),Byte(h[1]*255),Byte(h[2]*255),Byte(h[3]*255)] EndFunction The h parameter should be four floats like this: [0.0,1.0,0.0,1.0] ...or whatever values you want. The problem is this is a feature no one ever uses, so an error was overlooked and never addressed. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Sanctus Posted May 18, 2010 Author Share Posted May 18, 2010 Yes it may be a feature that nobody uses but if you claim on so many ads to have such a great terrain system then it has to be working. Am I not supposed to use a feature that's avaialbe just because other people don't use it? No actual game will be made with the sandbox so developers will have to use the actual engine for this. You haven't answered anything about the camerapick not working on terrains and neither on the loading/saving from file. These are vital parts of a game and they are not working. I'll try your new function and tell you how it's working. Quote I create the game you play. I create the rulles you will obey. Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 18, 2010 Share Posted May 18, 2010 I used the same functionality way back in the version 2.0+ days of Leadwerks and there were problems with it then too. I had to alter code following instructions from Josh to get it working. With regard to CameraPick and picking terrain, I use this all the time in my editor and have no issues with it, it's all working fine! I'm using version 2.31 at the moment but its worked with at least the previous 4 versions that I know of. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Sanctus Posted May 18, 2010 Author Share Posted May 18, 2010 Hm.. and do you create the terrain youserlf or load it from a file? I create them myself but I have to reverse x and y for it to give the good results on screen. If it's not too much to ask could you offer some snippets of code?(for the camerapick thing) Thanks in advance. Quote I create the game you play. I create the rulles you will obey. Link to comment Share on other sites More sharing options...
Josh Posted May 18, 2010 Share Posted May 18, 2010 Yes it may be a feature that nobody uses but if you claim on so many ads to have such a great terrain system then it has to be working. I agree. I was unaware there was any problem until you pointed it out, so thank you. You haven't answered anything about the camerapick not working on terrains and neither on the loading/saving from file. When I search this thread for the words "pick" or "load", this sentence is the first result that is found. What is your question? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 18, 2010 Share Posted May 18, 2010 Hm.. and do you create the terrain youserlf or load it from a file? I create them myself but I have to reverse x and y for it to give the good results on screen. If it's not too much to ask could you offer some snippets of code?(for the camerapick thing) Thanks in advance. I'm using terrain created in the Leadwerks Editor, so essentially loaded from the saved heightmap during the LoadScene command. My editor needs to place items on the terrain as well as on other objects and an example of some code I use for the camera pick is as follows: // Place model in picked position if(bPlaceModelMode && bLeftMouseButtonClicked) { // Perform a camera pick (raycast) iGotSurface = CameraPick(&pickStruct, camera,Vec3(MouseX(),MouseY(), 1000),0,0,NULL); if(iGotSurface) { vec3PickPos = Vec3(pickStruct.X,pickStruct.Y,pickStruct.Z); // Position the model at the picked location PositionEntity(entModel,vec3PickPos,0); ShowEntity(entModel); bPlacedModel = true; } } It's in C I know, but hopefully this might help. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Sanctus Posted May 19, 2010 Author Share Posted May 19, 2010 I agree. I was unaware there was any problem until you pointed it out, so thank you. You are welcome mate. Hopefully it will be fixed in the final LE2.32 About the camera pick and load/save heightmap I think it was on your email. Anyway I'll prepare a short demo to show you exactly what I'm talking about. I'm using terrain created in the Leadwerks Editor, so essentially loaded from the saved heightmap during the LoadScene command. Yeah I noticed people who load from the SandBox don't seem to have this problem. That code doesn't work at all on my terrain. It's in C I know, but hopefully this might help. I programm in C as well so that's not a problem Thank you. Quote I create the game you play. I create the rulles you will obey. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.