how to dynamic texturize a terrain contour

Previous topic - Next topic

kaotiklabs

Hi,

for my LD entry I posted a 2D horizontal scroller with a guy walking through a terrain.

I would like to know if its possible to apply a terrain texture the ground sprite in order to paint it on-the-fly following the contour.

Maybe by using polyvectors and some kind of dynamic adapted texture??

In my sample, the terrain is a sprite but if I what I want can be achieved with another kind of object like a poligon mesh is not a problem, Im just looking for the result, texturizing dynamic terrain :)

I attach you here the samples for better understanding of what I want to achieve.


[attachment deleted by admin]
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

MrTAToad

I can't think of a way of doing it dynamically, and certainly not fast enough for a game unfortunately...  It would generally be individual blocks of graphics, created in some art package.

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

erico

Lets suppose your terrain is mostly horizontal.

You could create it first as a black and white thing, then go scanning pixels vertically while plotting your pixels, grab the final result and use it. Altough it seems it is what you are currently doing right?

kaotiklabs

#4
Erico, my sample result is now beeing drawn by hand.  :(

As erico suggested maybe I could upload the sprite to mem and paint the pixels before but I was looking for a better looking method, not raw pixeling.
I want to have several types of texture terrains, like forest, snow, desert, etc that I could apply to the same shape template (black&white).

Maybe is possible to generate a kind of uv map and use polys for the shape?
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

erico

Polyvectors may help as they are able to ´liquify´ around the shape, but you may get distortions.

If you want to use a texture, let´s say a 8x8 blocks, you could use similar method.
Read the pixels to know when to change textures based on distance of the ground´s ´end´.
You could then use a B&W mask or blocks to trim the top part of it if needed or construct a set of pre made top bloks to use.

That is, if you want an horizontal terrain.

This way, your textures are unaltered, but you could also have a routine to ´share vertically´ the pixels of the up most blocks.

I´m not sure if this all make sense, just theories... :)

erico

What I meant, as an example, is similar to this screenie, but you crop tops so it dosen´t look blocky.
You could also draw your full things as blocks or a map and them just crop the borders(ops redundancy), or add blocks that have different curve levels to suite your needs. If this is overdone with options, then no one will notice it is a tile map, I guess some 6 different levels could pull the trick!

hope it inspires! :good:

http://playstarbound.com/wp-content/uploads/2012/05/31.png

erico

Also, if you need to have the outline, be it done by you or the user (like I once half did for a "draw your course" race game), you could run a pass over the outline to make it blocky in the first place, and work from there on...

mentalthink

I don´t understand very well the question?¿, but putting 2 textures and making something like a And or Xor...

Slydog

#9
If you are wanting to wrap a texture on top of a dynamically generated 'rolling' hill, I don't think this is too difficult, if you use POLYVECTORs.

Take the below screen shot as an example.

The bottom set of red circles would represent your rolling terrain points.
The bottom set of blue circles would be calculated based on the red points.
It should be an easy algorithm to determine these blue dots, somebody on here may provide the technical term for that trig function, I have no idea.
Then repeat this (and reuse the same texture) for all of the terrain points.

Then design your texture like the top texture in the screenshot (but with a even horizontal base, unlike the cut/paste I did from yours).
Using polyvectors, map the red dots from the bottom to the red dots on the texture.
Then do the same for the blue dots.
This will result in the texture 'wrapping' around the terrain.
It will distort a slight bit of course, but experiment and you may be happy.

You could have a longer texture to provide less repeating, each time just pick a point to start mapping from.
Of course you may have to predetermine certain valid starting points so the results flow together with the neighboring terrain nicely.  (same concept as a tileable texture)

[Edit]  The more reds dots you use along the terrain, the better it may look.

[attachment deleted by admin]
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Kitty Hello

Slydog's method is the best, IMO.
One thing: When you go "downhill", the math for the tiles might get complicated once they are to small that they could possibly overlap:


See the image: The grey polyvectors are just perpendicular to the terrain edge you want to render. The green ones are to fill the holes (if you want that). But if you go uphill, the green ones will be the red ones, that overlap with other graphics - which is bad. So in this case you need very sophisticated math, or just make the terrain texture like grass, that looks good even when it overlaps.

Slydog

Later today I'm going to post the code I was working on yesterday that results in the screenshot below.
It endlessly scrolls and creates randomly generated rolling hills, and textures the hill portion using the method I suggested above.

As you can see there are artifacts when the hills peak and valley.
That is because I think the uv coordinates are too squished to look good.
I have an idea to fix that, fingers crossed.



[attachment deleted by admin]
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

kaotiklabs

Yes!

thats really cool!!  :nw:

Im still trying but havent go so far.
well done!!
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Wampus