Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Vertex manipulation test

Author
Message
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 7th Nov 2022 02:08
I want to move verts up or down on a terrain and the only way I have found uses a memblock.
In this demo keys Z and X move the selected vert down or up but it lags due to having to apply the
whole memblock to the whole terrain after each movement.

There must be a faster way. Any ideas anyone?
Cheers.

Here's the code and the demo.

BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Nov 2022 18:11
That is a job tailor made for a shader.
However I don't think you could use it as a physics object.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 7th Nov 2022 18:56
Parallel instead of serial coding?
I might try again to wrap my head around GLSL. Would be very handy to know.
Thanks Blink.
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Nov 2022 19:30 Edited at: 8th Nov 2022 19:58
I think with the vertex shader you are passed each vertex of the model.
I'm not sure you can access the texture stages in the vertex shader but that would be the go.
Use the pixel colour in the texture stage to set the height of the vertex.

This is a very crude shader to flatten all the verts in an object to create a shadow.

Attachments

Login to view attachments
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 7th Nov 2022 20:04
Cheers mate. I'll have a study. This might take a while but should be a fun challenge. LOL
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 18th Nov 2022 19:57
I got the frame rate ok on my old laptop by reducing the terrain to about 32 x 32 verts.

I also use vertex manipulation to try to get a water waves example working. It's also 32 x 32 verts.
You have to get your feet wet to see the waves.
It's a copy of a program I was playing with about ten years ago.
Trying to work out SetMeshMemblockVertexNormal. The last three parameters x,y,z. Not sure how to use them.

BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.

Attachments

Login to view attachments
OriginalKronos
6
Years of Service
User Offline
Joined: 10th Nov 2017
Location:
Posted: 18th Nov 2022 20:17 Edited at: 23rd Nov 2022 00:26
What I did in my editor was to copy the vertex positions within a certain radius of the mouse pointer into an array as line objects and draw/update the lines every frame while the mouse button is pressed and only when the mouse button is released does the memblock actually gets updated. Speeds things up alot.

Edit: looks like I totally misread the question..never mind
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Nov 2022 17:55
If you do a search the minecraft thread has lots of input from allot of people and may help

also my thread https://forum.thegamecreators.com/thread/222027?page=1 about the 4th item from the top has 3 example methods of modifying a terrain

blinks vertex shader im yet to try but could also be handy for that purpose

dont underestimate memblock tho as with my Krazygrandprix proggy and help from many, including *blink i have a real time editor for both track, object placements and terrain with includes water and it has
a nintendo look and appeal.
PK
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 30th Nov 2022 02:07
Create a terrain with many more sections rather than a split value of 1...you then target the terrain objects meshes individually as objects using the mesh index as reference for the memblock. These will be much quicker to manipulate but you cannot swap the mesh out as best as I can tell. You can however hide that particular mesh of the terrain and simply create a fresh object from the manipulated memblock mesh and put it in position. Now some of the meshes will have less vertices than others to account for the last row of pixels/vertex heights both in the height-map and on the mesh, and the meshes are physically laid out in a "snake" like fashion, ie their positions are not rows then columns(or vice versa) going left to right then up or down, instead they are "do a row", left to right, then do the next row right to left. This obviously only relates to their positions in the order they are numbered in the mesh index. Then of course as already suggested simply focus on the nearest vertices around the point of the brush's center, tapering the height value down the further they are away - purely so you know you have functionality. Once you have done all your editing, you could if you wished; recreate the entire terrain via memblock's as objects placed in the same manner - combine the lot as a single object AND/OR create a memblock from the height map, every change you make to heights update the memblock, create image and recreate terrain with terrain command. Now all that said you will also have to recalculate the smooth normal's for any heights you change, otherwise it won't look good/right. You do that by calculating face normal's for any triangle that shares the target vertex, you then average the results. There will be plenty of examples of this sort of stuff - you will definitely need to use the search tool at the top of any forum page. If you cannot find it in any agk related board then search the dark basic pro board, code snippets etc as code in that language is easily ported to agk, if you can't yourself then just ask as there's plenty of folk about to help you out

Now I only got as far as working out how to do it with the terrains created from height-map and changing a single point for viability as I was really checking out the mesh format for these terrains as I was trying to work out shared vertex index order and this should have been a good example but wasn't in the end. I also happened to recently have worked on a scrolling tile terrain project which permitted a static memblock mesh terrain with a few minor code changes. So there was really no need for me to go any further with the internal terrain command produced object. Creating your own terrain from memblock meshes is another option open to you. It is a fair bit of work though.

As for using a shader - that's a bit of a quandary for me, as best I can tell you will need vertex texture fetch(is there any other way to store the heights? anything else would have to be code generated?):
From the helpfiles:
"AGK uses shaders written in the OpenGL 2.0 Shading Language (GLSL version 110) on desktop platforms, and OpenGL ES 2.0 shaders on mobile platforms"

Then there is this page:
https://www.khronos.org/opengl/wiki/Vertex_Texture_Fetch
At the bottom that looks similar to an agk VS...and I can say that Evolved who is a well known member among DBP users for his splendid deferred shading project, well Evolved uses a virtual texture for the terrain which is dx of course and sm3.0, it also has a vertex shader with VTF which uses some similar aspects of code specifically the "texture2DLod" part which is the significant part I think. I say I think because at this point it should be obvious I only ever got so far with direct x shader understanding in DBP and certainly am out of my depth beyond what I have stated...for me I have a few more things to do project wise then I will look at VTF although the whole hardware support stuff in that link is a little concerning. In fact the majority I find a little confusing in that link but again I think I have the gist of it, need to put it to the test when the time comes. Also normal's would need calculating as well which isn't mentioned in that link.

Hope you figure something out, just stick at it
Win 10 Home 64, Intel(R) Core(TM) i5-10300H, 8GB DDR4, NVidia GeForce GTX 1650 4GB GDDR6
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 7th Feb 2023 19:41
Thats really good "ando" particularly the speed of the vertex changes in the first one, that i need to study more closely, the water worked okay I had to turn off mipmapping to get things to work and the water seemed a little jittery to me. One of the best examples Ive seen on the forums with vertex manipulation for speed and simplicity.

I changed this

to this to get it to work
fubarpk
https://fubarpk.itch.io/

Login to post a reply

Server time is: 2024-04-25 09:48:54
Your offset time is: 2024-04-25 09:48:54