Wow, thanks for answering that fast !

I guess, modifying the cpp file would mean re-compiling Godot right ? If so, I'll just try to calculate them as you said.

I'm not sure how to access the VERTEX neighbors though. I see in this tutorial that it's done through a heightmap with the following :

```
pos=VERTEX.xz
NORMAL = normalize(vec3(k - height(pos + vec2(0.1, 0.0), TIME), 0.1,
k - height(pos + vec2(0.0, 0.1), TIME)));
```

I don't have a height map, so I replaced "height" by "apply_distorsion":

```
v_step = 1/mesh_size //It's a square
vec3 vx= applyDistortion(VERTEX-vec3(v_step,0,0),0.1); //-x neighbor
vec3 vz= applyDistortion(VERTEX-vec3(0,0,v_step),0.1); //-z neighbor
VERTEX= applyDistortion(VERTEX,0.1);
```

I'm not sure if that was what you meant when you said -x and -z neighbor

Then I tried different ways of calculating the NORMAL, but I must admit I'm shooting in the dark here :

A)

```
NORMAL=normalize(cross((VERTEX-vx),(VERTEX-vz)));
```

B)

```
NORMAL=normalize(cross((VERTEX-vec3(0,vx.y,0)),(VERTEX-vec3(0,vz.y,0))));
```

It runs, but it's giving me the wrong results. I'm sure there is something simple I'm not getting.

### EDIT :

I've been at it the whole night after work and I can't seem to come close to what the derivatives do. I would eally appreciate some help.

Here's the shader code, it's applied to a PlaneMesh subdivided 10x10y of size 10x10

I pretty muched tried to interchange everything with everything :

vX<-->vY<-->vZ<-->(VERTEX-vX)[...] with division by pt_size or not etc...

```
shader_type spatial;
uniform int GL_OES_standard_derivatives;
const float v_step = 10.0/1.0;
uniform vec4 out_color : hint_color =vec4(0.0,0.2,1.0,1.0);
uniform float distortion_amount : hint_range(0.2,1.5)=1.5;
uniform float distorsion_speed : hint_range(0.2,5)=1.0;
uniform float distorsion_seed : hint_range(0,1000)=1.0;
float generate_offset(float x, float z, float val1, float val2, float time){
float speed=distorsion_speed,amount=distortion_amount;
float radiansX=((mod(x + z*x*val1,amount)/amount)+(time*speed)*mod(x*0.8+z,1.5))*2.0*3.14;
float radiansZ=((mod(val2*(x*z+x*z),amount)/amount)+ (time*speed)*2.0*mod(x,2.0))*2.0*3.14;
return amount*0.5 *(sin(radiansZ)+cos(radiansX));
}
vec3 applyDistortion(vec3 vertex, float amount){
float xd = 0.0;//generate_offset(vertex.x,vertex.z,0.2,0.1,amount);
float yd = generate_offset(vertex.x,vertex.z,0.1,0.3,amount);
float zd = 0.0;//generate_offset(vertex.x,vertex.z,0.15,0.2,amount);
return vertex + vec3(xd,yd,zd);
}
varying vec3 preV;
varying vec3 vx;
varying vec3 vy;
varying vec3 vz;
varying float t;
varying vec3 normall;
varying float pt_size;
void vertex(){
//prevVertex = VERTEX;
t=TIME;
pt_size=POINT_SIZE;
preV=VERTEX;
VERTEX= applyDistortion(VERTEX,t*0.1);
vx= applyDistortion(VERTEX+vec3(POINT_SIZE,0,0),t*0.1);
vy= applyDistortion(VERTEX+vec3(0,POINT_SIZE,0),t*0.1);
vz= applyDistortion(VERTEX+vec3(0,0,POINT_SIZE),t*0.1);
}
void fragment(){
//NORMAL=normalize(cross(dFdx(VERTEX),dFdy(VERTEX)));
vec3 vX= applyDistortion(VERTEX-vec3(pt_size,0,0),t*0.1);
vec3 vY= applyDistortion(VERTEX-vec3(0,pt_size,0),t*0.1);
vec3 vZ= applyDistortion(VERTEX-vec3(0,0,pt_size),t*0.1);
NORMAL=normalize(cross((VERTEX-vX)/pt_size,(VERTEX-vY)/pt_size));
METALLIC =0.0;
SPECULAR=0.0;
ROUGHNESS=0.2;
ALBEDO= out_color.xyz;
}
```