I am using Blender Game Engine. I want to create a large flat plane, and deform it locally near a moving object.

So far (despite being a beginner at shaders) I've written a vertex shader for the plane which moves the vertices to their correct positions (constant positions, for now).

I cannot find a way to swap that constant location with an object's location updated every frame, while the shader is running. I am not even sure if it's possible. I only want to access a specific object's center from the shader.

  • 3
    \$\begingroup\$ I don't know Blender, but what you want to do is create a uniform variable in the vertex shader, and set the uniform to the object's location every frame. Maybe with a bit of searching you can find how to handle uniforms in Blender. \$\endgroup\$ Commented Feb 22, 2014 at 3:21
  • \$\begingroup\$ @Nathan Reed thats exactly what i did. I defined a uniform3f value in the shader, and i am just setting its new values on every frame. Now i need to find out if its possible to pass a list of locations for every object on the scene. But anyway my initial problem is solved :D Thanks \$\endgroup\$
    – Greg
    Commented Feb 23, 2014 at 11:03

1 Answer 1


You need to create a variable in your shader that holds this object location. In GLSL, you'd create a uniform variable; this is a variable which has the same value throughout the invocation of the shader (thus, "uniform;" you may see developers more familiar with D3D refer to these kind of variable as a "shader constant" variable as well).

Every time you want to render something with this shader, you'd set the uniform variable to the value you want.

That said, however, it looks like you are just using this uniform to displace some object in the world. The more common approach to this is to use a world transformation matrix for the object which is applied in the shader. This is implemented (in modern OpenGL) as a matrix uniform variable, much like your simple vector uniform, but also allows for rotation and scaling and is the more common approach. It will also scale equally well to an instancing scenario where you have several objects sharing the same geometry but in different world positions (as it sounds like, from your comments, you are wanting to have eventually).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .