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 Classic Chat / Animation and shaders

Author
Message
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Jan 2019 23:26
Hey.

Does anyone know how to get animation working with shaders? If you make any kind is vertex shader, even one that's just a dummy of the AppGameKit one, then animation doesn't seem to work anymore. It plays, and AppGameKit reports times etc, but the model won;t update.

Anyone found this, or a solution to it?
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 14th Jan 2019 07:56
I haven't found that exact problem but I have found the problem trying to import old dbpro animated 3DS file

using loadobject
and setobjectimage
works but doesn't allow the animations to work

using LoadObjectWithChildren
and setobjectimage
or SetObjectMeshImage(1, 0, 1,0 )
the animation works but with no texture

i did notice the animations had no names but
PlayObjectAnimation( 1, GetObjectAnimationName( 1, 1 ) , 1, -1, 1,1)
works to get the animation working
fubar
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Jan 2019 09:00
Yeah, I did it before using the getobjectanimationname trick, and it's working this time......I have the animation time for each object on screen and they are set updating, just the model isn't. Which is odd, as I'm 99% sure this isn't done in the shader. If I turn off my shader then the object doesn't display at all, it stays invisible.

I'm thinking that it may be a bad model, as it's a .X model from milkshape, but it's the exact same process I did before and it was working perfectly in a previous project with the default any shader.

Will need to play about tonight to see if the old model I made works.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 14th Jan 2019 09:56
Bone animation is done in the vertex shader.

Bone rotations/positions are worked out in the shader and then the vertices moved appropriately. The stock animation vertex shader for bone based models is this:



If you get you model animating correctly with the shaders built into AppGameKit then simply get that shader and save it to a file then you have a good starting point.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Jan 2019 11:05
Thanks Bengismo.

So it is done in the vertex shader......bugger. I assume that also means the shadows don't work by default through AppGameKit then with animated objects, similar to altering any vertice data in the vertex shader?

I'll try grabbing the shader, but that's how I based the shader I am using, though not with animation at the time. Will try again.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Jan 2019 21:37
Bengismo,

That doesn't work I'm afraid, in fact it made even the non animated models vanish compeltely.....they still cast shadows, but now aren't rendering, either with or without textures.

Going to try grabbing the shader code.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 14th Jan 2019 21:57 Edited at: 14th Jan 2019 22:14
Quote: "That doesn't work I'm afraid, in fact it made even the non animated models vanish compeltely.....they still cast shadows, but now aren't rendering, either with or without textures."


Animated models and non animated use different shaders. A non animated model cant use the animated shader as no bone weights will be passed to the shader.

The shader code I posted above is the shader that works with a .x file (its the one used by agk to render the soldier.x in the examples with a texture).

The exact shader AppGameKit uses will depend on your model and if you have texture applied. More importantly on what vertex attributes there are. Some models have normals, some dont, some have 2 sets of uvs, some dont.....some have per vertex colours, some dont...etc.... The shader is even changed if you dont apply a texture to your model as theres no point trying to look up a texture value when none is applied. This is the same for AppGameKit sprites.

So as said above, its best to render your model using a stock shader then grab it so you can see whats in it and have a good place to start from. The important bit is the quaternion based bone weightings and position calculations for an animated model.

If you try to render any model that has a shader that looks up texture values without a texture set then it wont render as the texture value looked up has an alpha value of zero so doesnt get added to the scene at all.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Jan 2019 22:22
Yeah, I know a little bit so I understand the different values.....so I started a brand new project and loaded an object that I built before and animated.......it works with the stock AppGameKit animator, so I assume that the model I have been testing is, in fact, broken.

Oddly, I now loaded it into the other program and it doesn't work, even when setting it's shader to 0 (which according to the documentation should reset it to the internal shader) - it *kind of* works, but faces randomly flay all over the place so I assume something is happeing in the matrix that transforms the positions???

Also to note, the working animated objects have only 1 mesh, where as the other object has two meshes, and the first is animated - does AppGameKit struggle with this? (I tried setting mesh shaders, made no difference)

Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 14th Jan 2019 22:30
Well, I cant comment on whether your model is broken or not as I havent seen it. Obviously a working model is the most important thing to start with.

If a stock shader works on it.... then you should be able to just grab that shader and assign it yourself to the model. Ive tried that with a few models and it works fine. Thats the best place to start from when writing a custom shader.

If your interested in how AppGameKit come up with the shader for your model its the code from line 1718 onwards here:
https://github.com/TheGameCreators/AGKTier2/blob/master/common/Source/AGKShader.cpp


Also...in good news....the shadow shader does apply the animation to the vertex positions so shadows should be animated too. ... its also in the same file I linked to above
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Jan 2019 22:44
That's awesome about the shadows.....but also means I'm doing something wrong in the tree/grass shader as the transofrmations applied in the vertex shader don't affect shadows. I think it's because I'm assigning a manual .x movement, not assigning the gl_Position witht he movement.

Trying to change the two mesh model to a one mesh model to see how it goes.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Jan 2019 23:13 Edited at: 14th Jan 2019 23:21
Ok, I think I'm done for tonight.

I've fixed the object, so in the new stand alone program it's working fine, animating correctly now. I;ve grabbed it's VS and PS source, saved them to a file, moved that into the original program folder and loaded them in.....not working, the object is invisible (or rather, it;s vertices are scattering everywhere).

The only thing I am doing differently in the main program is that the object is cloned several times before being finally placed, but the snimation data is all still there and I set the shader for it AFTER it's placed.

Very confused.

EDIT: just had a thought - the object is scaled too.......

Yup....it's the scale that's the issue, or at least when I tried it in the seperate program the same issue appears.

Thanks for all your help Bengismo.....wouldn;t have gotten to the issue without your help.
puzzler2018
User Banned
Posted: 14th Jan 2019 23:31
AGK has scaling issues with all objects. im happy you getting it sorted
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Jan 2019 23:38
Yeah, I can now see the issue - if I set teh scale to permanent then it seems to work, at least in the seperate program. Will have a better look at it later now.....loosing the ability to scale the object is a bit of a bind though. I wonder if you can scale the animation in the shader?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 15th Jan 2019 17:29
So I got the animation working with Bengismo help, and after sorting the scaling.

However, curious question. Animation updates the vertex positions in the vs, which allows AppGameKit to render shadows based on the movement. However, if I change a vertex position, shadows render based on the original mesh positions.

I compared the two shaders, stock and animated, and other than the transform matrix I can't see exactly what part allows the shadow to render. In the animation shader, it transforms the position using the bones and animation data, then converts this back to gl_Positon. However if in a stock shader I move or manually adjust the gl_Positon the shadow doesn't render to account for the change.

Has anyone any idea exactly what part of the vs allows the shadow shader to account for the change? The two ps files are pretty much identical, so I assume it's the vs that does it, and would have assumed updating the gl_Position would cover it, but it doesn't seem to.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 15th Jan 2019 19:33 Edited at: 15th Jan 2019 20:46
I believe lightVarying is where the shadow is calculated in the vs, and then passed to the pixel shader.

Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 15th Jan 2019 21:08 Edited at: 15th Jan 2019 21:09
I wanted to add this.

Wouldn't the object that is receiving the shadow need to account for the change in position of the object casting the shadow? Is the shadowmap not picking up this change?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 15th Jan 2019 21:20
Hmmmm.....I tried adding the movement I am applying to the lightvarying, it didn't work......doesn't that just control the shading, not geometry?

I don't think you need to account for the object receiving the shadow, I'm mixing objects with an animation shader and a customer shader and the shadows are received correctly with animated objects. Are the shadows a seperate post process or done realtime? My understanding is all geometry calculations are done, then the shadow map is generated, but I don't know.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 15th Jan 2019 21:37
You are right.

I've had this problem, too, but I was putting it off thinking it would be a simple fix. My grass and trees don't have their shadows move, but my animated objects do.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 15th Jan 2019 22:26
That's the exact problem I'm trying to fix......tree branches moving with a sin calculation but with totally static shadows. Lol.

Will have another play around tomorrow. I'm thinking one of two things - either agk does something after the animation that allows the shadows (post processing, and why it doesn't come up when grabbing a shader) to pick up geometry changes, or I'm just getting the shader wrong.

I added the sin movement to every stage of the shader one at a time, gl_Poisiton, pos, normal, and lightvarying......found some brilliant effects but no matter how wildly the shape changed the shadow stayed perfectly still and as though the shape hadn't altered at all.

Maybe Bengismo or Janbo know?
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 16th Jan 2019 22:05
Hi
Quote: "tree branches moving with a sin calculation but with totally static shadows"

Sounds like the shadow's scene is rendered without the GetPSLighting function.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 16th Jan 2019 22:11 Edited at: 17th Jan 2019 01:36
No, they use the pslighting function.

I'll post the shader tomorrow, but have you managed to alter geometry in a shader and have agks shadows account for it, without animation, Janbo?
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 17th Jan 2019 03:11 Edited at: 17th Jan 2019 03:26
If you look at the AGKShader.cpp, Bengismo provided the link, the shadow shader takes into account the animated movement, but the calculation for non-animated objects is just gl_Position = pos;.



I think we need to update this, but I have no idea how. My thought is this happens during the RenderShadowMap(). Could be totally wrong, though. Just a guess.

edit: I have tried to change the order of the rendering process, to no avail. I also tried to draw the object before RenderShadowMap() is called(also tried before and after Update()), and that wasn't the answer either.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 17th Jan 2019 15:41
The shadow render and the normal render use different shaders, so whilst you may be modifying the normal render shader to adjust the vertex positions the shadow shader isn't doing the same thing. Unfortunately the shadow shader is currently hard coded and assumes the object is either bone animated or static, with no other modification to the vertices. It's possible this could be made to use a custom shadow shader, but it might take some work to get it set up. Since you are looking at the AppGameKit source the change that needs to be made is to insert a custom shader in cObject3D.cpp lines 2540 and 2554
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 17th Jan 2019 16:35 Edited at: 17th Jan 2019 16:36
Thats what i said basically, well I left much room for interpretation that for sure

Quote: "to insert a custom shader"

Do you mean like a separate shader comands set just for the shadow render ? or more like the ability to quickly change the shader to another one to render the shadow scene

In source code maybe use the vertex code of the shader provided by the user and use a pass through fragment shader ...just an idea.
Probably would be bad if someone uses a performance intensive vertex shader, as it would be processed a second time.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 17th Jan 2019 17:55
Janbo,

Would the shadow shader you were working on get round this problem? As you day, changing shaders.......so for example use the agk shader for static and animated objects, but perhaps use yours for items that need vertex positions updated? I can't think of much outside trees and fabric that would need it.

The other option of course is just to animate the tree models.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 17th Jan 2019 19:18 Edited at: 17th Jan 2019 19:32
If you match the smoothing(i.e Fixed/Random Multisample) with that of AppGameKit then you wont notice it.
I already have every shader separate, for animated and static models in the Real scene and for the shadow scene...
But what are you doing with the shadow receivers ?
You don't want to mix both shadow maps and you can't pass the shadow map to AGK.
I guess your options are
1. just use my shadow shader for everything
2. Animate the tress and stuff
3. Change AGK's source code
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 19th Jan 2019 19:22
Hmmmm.

Thanks Janbo, I think for the sake of simplicity I'll just animate the trees.

New issue though - though not sure if it's an issue. Paul, setting the scale perm for animated objects works fine, however they all have to be even. So, scaling on just the X works fine, however scaling on just the Y or the Z causes the animation to break and go wild all over the place. Is this the behaviour you intended?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 22nd Jan 2019 11:10
Has anyone managed to get multiple meshes working with a format other than a .X model? I've tried exporting trough .obj, .dae etc but they either don't exports bones and meshes, or I'm not doing it right in a way AppGameKit likes.

I do notice in the help text it does say that AppGameKit will try and consolidate multiple consolidate multiple vertices into a single object with as few meshes as possible......so how is that meant to work when meshes require seperate textures?
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd Jan 2019 13:28
I have multiple meshes w/bones working through FBX.

Each mesh needs its own image and material inside the 3d software. The same image with a different material will not work. Then export out of the software with FBX unit scale. This is how I do it in Blender.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 22nd Jan 2019 13:58
Ah, I use milkshape as I find blender ridiculously complicated yo be honest, plus on my 4k screen everything is minute as it doesn't take desktop scaling into account.

Not sure I follow what you mean with
Quote: "the same image with a different material will not work"
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd Jan 2019 16:25 Edited at: 22nd Jan 2019 16:29
Meaning I can't just make 10 different materials, and assign the same image. I actually have to assign unique images to each material in order for AppGameKit to recognize a mesh. Huge pain in the butt.

Bengismo gives a great demo (sadly, its Blender) of this here: https://forum.thegamecreators.com/thread/221784
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 25th Jan 2019 11:51
Solve found a kind of way around it, be it a fuss. I build my model in milkshape, then export as an obj file. Photoshop can import this and texturing is a doddle in that, then I export the 3d scene as an obj. Back in milkshape I then import just the uv data, then export as a .X model.....multi mesh support with full animation.

Bit of a fuss, but it let's it work at least......coding is so much easier than art!

Login to post a reply

Server time is: 2024-04-19 20:24:11
Your offset time is: 2024-04-19 20:24:11