# Vertex offset for several renderers parallely

Hi there,

I have an issue with my vertex shader which might be a beginner’s problem. I wrote a simple vertex shader that offsets vertices along a sinus-function to create the Illusion that my character (from Autodesk Character Generator) is being inflated or deflated. However, since eyes, teeth and other body parts have their own meshes and own shaders, changing the Body results in a distorted body configuration as displayed in the Image.
It seems to me that I need to write shaders that geometrically adapt the distortion function for each single of these objects. Or is there a Workaround that let’s me apply the same distortion to the body and all related body parts at the same time?

Thanks!
Marius

I think I found the solution to applying the same sinus distortion to several objects. The Problem was actually already discussed here: Modifying vertex position in a surface shader - Questions & Answers - Unity Discussions, but I did not realize at first that this solution applied to my Problem.

In my shader, I now convert the Vertices to world space, apply my geometry function, and convert the Vertices back to object space. This Looks like this:

``````      void vert (inout appdata_full v) {
// sinus-shaped distortion: convert vertices to world spaces, apply distortion in x- and z-direction along vertical axis (running through middle of character),
// convert back to object space and apply to shader.
float3 world_space_vertex = mul(unity_ObjectToWorld, v.vertex );
float3 sinoffset;
sinoffset.x = (world_space_vertex.x - sin_x_off) * sin_size*sin(world_space_vertex.y*sin_freq+sin_phase);
sinoffset.y = 0;
sinoffset.z = (world_space_vertex.z - sin_z_off) * sin_size*sin(world_space_vertex.y*sin_freq+sin_phase);
sinoffset = mul( unity_WorldToObject, sinoffset);
v.vertex.xyz += sinoffset;

}
``````

I simply controll the variables defining my distortion from an external script:

``````    void Update () {
sin_x_off = MainTransform.position.x;
sin_z_off = MainTransform.position.z;

for (int i = 0; i < renderers.Length; i++)
{
rens[i].material.SetFloat("sin_x_off", sin_x_off);
rens[i].material.SetFloat("sin_z_off", sin_z_off);
rens[i].material.SetFloat("sin_size", sin_size);
rens[i].material.SetFloat("sin_freq", sin_freq);
rens[i].material.SetFloat("sin_phase", sin_phase);
}

}
``````