Attention |
Topic was automatically imported from the old Question2Answer platform. | |

Asked By |
Xian |

I wanted to create a shadermaterial that bounces and rotate only the rendered image of the material. That way I can reduce the cpu usage of the game I am making. So far I manage to make it bounce and rotate but when rotating the image gets distorted or deformed. Here’s my code:

```
void vertex() {
UV=UV*uv1_scale.xy+uv1_offset.xy;
float rotate = mod(TIME,360.0);
VERTEX.y += sin(TIME)*0.1;
VERTEX.x = (VERTEX.x * cos(rotate)) - (VERTEX.z * sin(rotate));
VERTEX.z = (VERTEX.z * cos(rotate)) + (VERTEX.x * sin(rotate));
}
```

I was making use of the formula

```
x′=xcosθ−ysinθ
y′=ycosθ+xsinθ
```

Where my x is the x value of the vertex and the z is my y value. Making it look like this.

```
VERTEX.x = (VERTEX.x * cos(rotate)) - (VERTEX.z * sin(rotate));
VERTEX.z = (VERTEX.z * cos(rotate)) + (VERTEX.x * sin(rotate));
```

The degree it rotates around is made passively using the

```
float rotate = mod(TIME,360.0);
```

As for the y value of the vertex, I am using it to create the bouncing effect.

```
VERTEX.y += sin(TIME)*0.1
```

So far it works, but I can’t seem to figure out why the image distorts while rotating. Please help super senpais.

Hi,

first of all, i m pretty sure that glsl cos uses radiants and not euler degrees.

Can you post a screenshot of the distortion?

klaas | 2020-09-03 07:07