Let colors return a value?

For questions about using Classic.

Post » Tue Oct 06, 2009 11:27 pm

Hello,

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

Anyhow, Im 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 Im 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 didnt really tell me much.

Thanks for answers
B
2
G
3
Posts: 15
Reputation: 880

Post » Tue Oct 06, 2009 11:56 pm

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.
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Wed Oct 07, 2009 12:26 am

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.
[url:25lyy99u]http://guicon.110mb.com/structure/index.php?act=page&id=2[/url:25lyy99u]

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.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Wed Oct 07, 2009 12:29 am

Your slices idea was more or less what I meant with my less attractive solution. But I dont understand why it would be that slow. It would only need to retrive the value when an object is moving, and lets 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 havent 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 lets 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? Im 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.
B
2
G
3
Posts: 15
Reputation: 880

Post » Wed Oct 07, 2009 12:36 am

@newt

Im not sure I quite follow you :) I was intending to have a pre-generated grayscale map. Or what do you mean by mesh, that construct supports 3d-models somehow :?

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 doesnt have to be imminent, as the game will be slow paced.

edit: Oh, and if I confuse you guys with anything, let me know, Im typing fast and english isnt my primary laungage :p
B
2
G
3
Posts: 15
Reputation: 880

Post » Wed Oct 07, 2009 1:19 am

[quote:17s5gilo]Your slices idea was more or less what I meant with my less attractive solution. But I dont understand why it would be that slow. It would only need to retrive the value when an object is moving, and lets 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?[/quote:17s5gilo]

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 havent really read that much about constructs performance, but to my understanding it is quite fast, no?[/quote:17s5gilo]

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.[/quote:17s5gilo]

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?
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Wed Oct 07, 2009 1:25 am

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.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Wed Oct 07, 2009 1:28 am

[quote="newt":ws87v1xz]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.[/quote:ws87v1xz]

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
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Wed Oct 07, 2009 1:34 am

Terrastruct is here:
[url:1r42x6dz]http://files.getdropbox.com/u/666516/terrastruct.exe[/url:1r42x6dz]
Overview is here:
[url:1r42x6dz]http://guicon.110mb.com/structure/index.php?act=page&id=7[/url:1r42x6dz]

Im not terribly happy with the noise generator, so I would advise using Gimp or Photoshop to make up your maps.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » Wed Oct 07, 2009 2:07 pm

I was going to generate the map based on a depth map made in a 3d-program Im 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 :) it sounds amazing and if I hade known construct had this ability I wouldnt have even concidered using texture maps, as I come from a background of 3d-modelling where vertex maps are preferable to texture maps :)

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 Im 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 its height topology I just sculpt the terrain like I want, or if its vertex values, Ill 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 dont think Ive 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.
B
2
G
3
Posts: 15
Reputation: 880

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests