0 Favourites

Let colors return a value?

This forum is currently in read-only mode.
  • Hello,

    First I just want to say a big thanks to the devs for making Construct (and for free, amazing). I�m currently learning it, and this program just makes programming make sense to me

    Anyhow, I�m thinking of some game designs and one of them is a kind of Close Combat clone, which I guess would be suitable with this engine. What I�m curious about is if it is possible to retrive values from texture maps, based on the pixel colors in the map.

    What I intend to do is have a grayscale map stretched over a layer to determain the height of hills and such, puting stuff like line of sight to interesting use. The map would not be visible in game of course, but would still have to be able to let objects fetch values from it. So, is this possible without using python scripting? And if not, is it at all possible even with python?

    Or can anyone think of an alternative way to create height for top down landscapes? As a less attractive solution I was thinking that I could generate a height map of maybe 8-16 colors, then create seperate objects of all the shades and then simply use the objects with ordinary collision checks to see what "height" an object is at. Do you think this would be a feasible solution?

    Btw, I was looking at the pixel shader entry in the wiki, thinking that they maybe could be put to use in a case like this, but it didn�t really tell me much.

    Thanks for answers

  • retrieving values like that from a texture would be way to slow, since allot of gpu-cpu transfers would have to be done. you need to find a better method, like making you collision maps out of top down "slices" (sorta like what voxels are if you know what that is) for each height level up to 16 levels or something and use those for line of sight ect., this is if its ABSOLUTELY necessary to have a heightmap like this.

    you could also make a loader create an array of values based on height maps and retrieve those at runtime, but even that would probably be slow, and its alot more complicated than my method.

    think of alternatives to heightmaps. do you absolutely need to know smooth variations for your game to work. is the load it puts on the system worth using it? i dont know exactly what youre trying to do, but im guessing heightmaps isnt the way to go in a construct based approach.

  • Actually....

    Yes you can do that, and yes it would be to slow to do it in real time.

    However there's nothing keeping you from making a pre generated mesh.

    Its a little old, but the height map generator I made should still work.

    http://guicon.110mb.com/structure/index.php?act=page&id=2

    As to the line of sight, it wouldn't be too hard to make up a separate map out of your height map.

    You would just need to pick a value that you want to detect and delete the rest.

  • Your slices idea was more or less what I meant with my less attractive solution. But I don�t understand why it would be that slow. It would only need to retrive the value when an object is moving, and let�s say there would be 20-30 objects moving at most which need to have their height checked, would that really make such a punch in performance? I could probably get away with checking a units height every 3rd or 4th frame or so, and, if using the slices-method, all it would do is a simple collision check "is unit touching height object x". If using the check-color-value I guess it would be similar, no?

    Or is collision checking in general slow? I haven�t really read that much about constructs performance, but to my understanding it is quite fast, no?

    And about smooth variations, no. I was thinking that if I have a layout of maybe at most 4096x4096, then I would stretch a 512x512 grayscale map over it. Making slices would complicate that idea, as I would have to stretch several objects, and make sure they all match up when stretched. Also, say I would make 16 slices, that would mean 512x512x16, not an attractive solution when I think about it.

    But let�s say that I go with the array idea. Basically I would, for say a 4096x4096 layot, load a greyscale map, read the values from like every 4th pixel or so and then put those value in a 512x512 array or something, right? Would this be a hugh performance sucker? I�m not familiar with how storing/reading large arrays affects performance.

    And also, just for confirmation, is it possible to retrive a value from a texture map? like "check RGB value at action point from -object-" or something.

  • newt

    I�m not sure I quite follow you

    And the line of sight, maybe I could just "shoot" an object towards the other units and check if its height-value when it travels over the heightmap gets higher than the shooting units stored value, then the sight is negative. Does that sounds slow? if the distance is long, I was thinking I could break it up over like 5 frames, reaction doesn�t have to be imminent, as the game will be slow paced.

    edit: Oh, and if I confuse you guys with anything, let me know, I�m typing fast and english isn�t my primary laungage :p

  • [quote:17s5gilo]Your slices idea was more or less what I meant with my less attractive solution. But I don?t understand why it would be that slow. It would only need to retrive the value when an object is moving, and let?s say there would be 20-30 objects moving at most which need to have their height checked, would that really make such a punch in performance? I could probably get away with checking a units height every 3rd or 4th frame or so, and, if using the slices-method, all it would do is a simple collision check "is unit touching height object x". If using the check-color-value I guess it would be similar, no?

    actually, checking color is a whole very different process, color values require gpu/cpu transfers for the texture data, which is the absolute WORST thing you can have for a real time application. collision checks are highly optimised and dont have this bottleneck.

    [quote:17s5gilo]Or is collision checking in general slow? I haven?t really read that much about constructs performance, but to my understanding it is quite fast, no?

    as i said collision checks arent slow, but GPU/cpu transfers with value checking is very much so.

    [quote:17s5gilo]And about smooth variations, no. I was thinking that if I have a layout of maybe at most 4096x4096, then I would stretch a 512x512 grayscale map over it. Making slices would complicate that idea, as I would have to stretch several objects, and make sure they all match up when stretched. Also, say I would make 16 slices, that would mean 512x512x16, not an attractive solution when I think about it.

    no youd only need to run a loop to spaw the 16 or wtv number of sprites, they could all be the same sprite type, all you need to do is spawn 16, and change the animation frame to wtv loopindex they were spawned on, and store that loopindex in a private variable. just make sure the animation speed is set to 0.

    i have no idea why you think 512 by 512 by 16 isnt an attractive solution. a huge sprite that has to be transfrered to vram, into the gpu, to the cpu, the cpu has to check a value out of a 512x512 array of pixels, 30 plus times, every 15th of a second if you do it every 4 frames is?

  • Mesh's are a file that Construct can generate, basically it's a saved form of a distort map.

    If you'll look in Construct's folder you'll find another folder called tools. Within that folder you'll find some examples of some mesh's, and a map editor.

    Btw Mesh's are fairly scale-able, and will scale themselves to the sprite they are applied to.

    On line of site, it is possible to get zdepth data for each row/column, but it would be much slower than my solution.

  • Mesh's are a file that Construct can generate, basically it's a saved form of a distort map.

    If you'll look in Construct's folder you'll find another folder called tools. Within that folder you'll find some examples of some mesh's, and a map editor.

    Btw Mesh's are fairly scale-able, and will scale themselves to the sprite they are applied to.

    while youre on the subject of meshes, you could probably use newts tool (if it saves mesh files, i never used it, where can i get it newt?), import a mesh, and make system which finds the height of the closest vertex on a mesh and use that as a simple and id think rather fast way to do things. it might even be faster than using an array

  • Terrastruct is here:

    http://files.getdropbox.com/u/666516/terrastruct.exe

    Overview is here:

    http://guicon.110mb.com/structure/index.php?act=page&id=7

    Im not terribly happy with the noise generator, so I would advise using Gimp or Photoshop to make up your maps.

  • I was going to generate the map based on a depth map made in a 3d-program I�m using, by first sculpting a landscape and then run a z-depth pass to extract the height into a map.

    So basically terrastruct generates a polygon mesh out of my height map, and then construct can extract information out of the topology of the vertecies? Or is it more like vertex mapping, where you have a flat multi-polygon plane with every vertice given a value, and then extract the mesh for use in construct?

    Not that it matter which way, as long as it works

    Thanks a lot for the help, and for the program, will check it out and post if I make something useful out of it

    edit: Ah, my main computer is broken and the one I�m using now is so slow that terrastruct was barely usable, but looking at the tutorial it seems very interesting. But basically, I could use which ever 3d-software that supports export of the .mesh format and then, depending on what method construct use for the mesh (if it�s height topology I just sculpt the terrain like I want, or if it�s vertex values, I�ll just paint a vertex map over a flat poly-plane), export it for use in construct, right?

    Although I must say terrastruct looks handy in this case, I don�t think I�ve ever encountered a feature that can generate a vertex map based on a height map in a 3d-software. But if all terrastruct does is generate a topology based on a height map I guess there are better software, like the free terragen, and also the 3d-program I use have this ability to some extent.

  • Initially it was just an engine I made up, but like most of my concepts I had no game to go with it.

    Mind you its not true 3d, It basically works like Terragen you create a height map, and from that you can make or apply a texture to the mesh that the height map generated.

    There are some limitations, you wont be able to go over 50x50 grid size, that's a hardware limitation according to Ashley, but like I said the mesh's are fairly scale-able, so your mesh, or texture, wont have to be 50x50, but the height map will. That means you have a couple options for making bigger maps, you can either string a bunch of smaller mesh's together, or just one big one, or even something in between.

    There's still a bunch of stuff thats' possible that I haven't tried, like deformable/animated terrain, and even random terrain maps.

  • You *cannot* use meshes exported from any program. the .mesh format used for construct is for construct only, its a special type of file that only the mesh editor or construct saves and exports. the name .mesh means nothing it could be .asfkjhdfkaf

  • Hehe, I thought terrastruct was totally bugged, whenever I loaded a map it looked all distorted. Then after some ages I figured out that you move the scene with the middle mouse button

    Well, I got my mesh loaded and I made a simple testscene:

    http://bayimg.com/jaeikaAcF

    But when running debug nothing happens to the height variable. As there is no info at all in the wiki on this stuff, I?m kind of confused with all the available expressions. I thought Z usually represent depth, right? So when moving about it should give some kind of value, no?

    edit: Hm, I realised nwo that maybe I need something like "get closest vertex"

    edit2: aha, I realised now that I misinterpreted some things, with colums and rows. I?ll do some more digging

    edit3: got it now! I just divided the players x/y with the number of rows/colums in the mesh.. Seems to be working, I?ll do some more messing around..

    edit4: hehe, it seems like it is only giving me the X/Y position of a specific place on the mesh, not actual depth values of the vertecie. I?m not sure, will to some more tinkering.

    edit5: okay, after puting some food in my stomach I finally figured out a formula (math ain?t exacly my greatest skill) to detarmain the height..

    When player-object is overlapping heightmap, give private variable 'height' the following value:

    Heightmap.VertexZ(Player.Y/(Heightmap.Height/Heightmap.MeshCols), Player.X/(Heightmap.Width/Heightmap.MeshRows))

    Now, there is one problem: it only works when the heightmap is put in the top-left corner of the layout. I need to make it relative somehow.. I?ll see if I can figure it out on my own..

    Hm, I can tell that this is going to be a real drain on the system. CPU waiting for GPU went from 90% to 30% when using six objects at once. Imagine having like 20-30 + a lot of other complex calculations.. Guess I have to find a way to optimize this..

    edit6: Ah, it was no problem optimizing it, I just set it to happen every 500ms and the cpu usage was barely noticable. I guess if I have a lot of units I could optimize it even further by making some kind of que system so objects never check their height on the same tick..

    Many edits

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • The thing to remember about z is 0 is like the middle ground, with positive numbers giving foreground, and negative the background. To make things easier I just didn't use negative numbers.

  • Well, lucky me I guess, as that I think this is hard enought as it is

    Anyhow, I got everything working now, thanks a lot for the help guys/gals..

    Here is the finished equation as reference for eventual math-hating lurkers. You can move your mesh where ever you like and get correct results:

    When player-object is overlapping heightmap, give player-owned private variable 'height' the following value:

    Heightmap.VertexZ((Player.Y-Heightmap.Top)/(Heightmap.Height/Heightmap.MeshCols), (Player.X-Heightmap.Left)/(Heightmap.Width/Heightmap.MeshRows))

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)