I didn’t post in this sub-forum before, but I had some fun playing around with the game engine and I stumbled about a question I didn’t find an answer for. I searched for a way to update a mesh changing modifier while running the game engine. I’d like to shift a displacement along a subdivided surface during gameplay. Now what would be the best and fastest approach to do this in your opinion? Python is probably not a good way.
Apply the displacement as a shape key and use a shape action actuator.
BTW I find it best to apply all modifiers before starting the game, it make the game run much faster.
Shapekeys aren’t flexible enough for what I have in mind. I need full in-game control about displacement coordinates/update. Can’t that be achieved by GLSL geometry shaders? Does Blender support this already? If not, what alternatives are there?
I remember someone doing a script that actually deformed the mesh with realtime physics, but can’t remember the thread. If I recall correctly, this person managed to deform the mesh graphics, but didn’t manage to deform the physical mesh, in other words he got stuck but the thread must be still around.
There is a python command to apply the deformations physically so that they affect the physics.
You can even run it every frame to get real time colisions based on animations, but it is very slow.
Looks like I have found what I was searching for. Blender supports Vertex Shaders which can be used to manipulate and deform meshes in quick way. I didn’t test it, but you can see how it works in the xmb.blend by mpan3 from here:
Kai, yes, you can deform mesh in game with vertex shader, but unfortunately the physics can`t be updated.
If you use python, you can also update the physics mesh with “Edit Object” Actuator under “Replace Mesh” dropdown menu and make sure “Phys” button is pressed.
Thanks martinsh! Currently I’m trying out vertex shaders but immediately I stumbled over another problem. I only want to set a vertex shader, but not the fragment shader. But shader.setSource() seems to require always both shader programs. I tried to replace FragmentShader with mat.getShader().getFragmentProg() to get the original shader but this seems to be empty and I get:
---- Fragment Shader Error ----
(0) : error C0000: syntax error, unexpected $end at token “<EOF>”
(0) : error C0501: type name expected at token “<null atom>”
Any suggestions how to keep blenders original shader intact and only use a custom vertex shader?
Yeah, “print shader.getFragmentProg()” returns empty.
Moguri is making a shader system that allows to use either Vertex of Fragment shaders separately.
Thanks, I have asked Moguri about the shader problem and he could explain it in more detail:
The fragment shader is still there, but it’s not getting all the uniforms it needs from the vertex shader since you overwrote it. Supplying the necessary uniforms yourself is difficult since the names are generated as they are needed (var0, var1, etc).
I’m not sure how to best work around this without reworking how part of the code generation is done (ie, use predictable names).
I’ve found that physics constraints can be able to be removed and placed in the Game Engine via python… You could use a script that creates a constraint, then adds a new one, then deletes the old one, then repeats. If you did this when an object experienced a collision/force that indented it for more than 2 frames, it would resolidify its location relative to the object it’s attached to. If you combined THIS with armature ragdolls and were willing to use quite a few ridgedbody collision meshes around the main object, you could create a fully physical deformable object. This is all theoretical, of course; I’m trying to create the script for 2:49, but haven’t gotten around to it… Just throwing it out there.