This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

GDscript param to shader

MagicLordMagicLord Posts: 578Unconfirmed
edited February 2018 in 3D

Hi there

Can we pass GDscript parameters to a shader ?
I got some needs for clothes vertex animation based on character direction and velocity.

Best Answer


  • MegalomaniakMegalomaniak Posts: 2,580Admin
    Accepted Answer
  • MagicLordMagicLord Posts: 578Unconfirmed
    edited February 2018

    Thank you.
    This other use is to shift texture using a GDscript offset parameter to control a cartoon expression using a texture atlas.

  • MagicLordMagicLord Posts: 578Unconfirmed

    Does this function process cost power if i pass a variable each process(delta) to the shader ?
    I would need to move a vertex to the direction the character is moving, can i do it in the shader with shader camera and the variables i pass ? I don't know if it is some camera_projection or world_projection i must use ?

  • MegalomaniakMegalomaniak Posts: 2,580Admin
    edited February 2018

    Well, the input you are sending to the shader parameter comes from the CPU so yes there is going to be a latency cost however the smaller the datablock you send the less of an effect its going to have. At least that's the way I think of it to keep it simple.

    In respect to the rest of your post I'm not entirely sure I understand what you are trying to-do so not sure if xy problem.

  • MagicLordMagicLord Posts: 578Unconfirmed
    edited February 2018

    I am trying to move a vertex to the opposite direction of the character velocity using a parameter.
    That could be three float for the vector direction.
    I think it's simple, adding some X,Y,Z offset to the shader for moving the vertex should work.

    Are vertex working in world space in the shader if we add some offset ?

  • MegalomaniakMegalomaniak Posts: 2,580Admin

    But what for? Like a cloth dynamics thing or..?
    I'm thinking it might be better to do this with the animation system perhaps.

  • MagicLordMagicLord Posts: 578Unconfirmed

    This is to deform whole clothes in real time to simulate wind forces.
    With bones you need a lot around the whole clothes, there is better ways.
    Vertex GPU animation advantage is vertex color can determine whole vertex will move and how much.

  • MegalomaniakMegalomaniak Posts: 2,580Admin
    edited March 2018

    well, you are going to have issues with the cloth going through itself and the character mesh doing it this way.
    Anyways, the GDC video is behind a pay wall but the slides for a talk by Natalie Burke that might be of interest to you can be found here:

    edit: oh and yeah, to answer earlier q. you would want to make use of vertex positions as your basis and work in world-space.

    Mind you I have no clue if its implemented in godot(probably not) however Bullet physics library should have support for cloth physics.

  • MagicLordMagicLord Posts: 578Unconfirmed

    Character model will not be a whole model ,only some parts , the clothes will be separate parts , there is no overlap.
    This effect was used in some skiing games, where clothes begun to have faster wind like effect as the player moves faster.

    For example on pants only the back facing parts will have some movement, while surface normal to direction movement will not move as much, and the movement will be bigger on lower parts. It's not for regular clothes, more like skiing clothes.

    Because the shader works in world space, it won't be complex to move vertex using character direction.
    it's an experiment, i don't want to use multiple bones i would have to animate manually, instead a cheap effect could look good.

    For physic clothes, they are very linear, you won't have wind effect with clothes doing small movements variations because of high speed movement.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.