# How do I apply domain warping to my marching cubes voxel terrain in Unity?

## How do I apply domain warping to my marching cubes voxel terrain in Unity?

```So, in GPU Gems 3 there is a cool warped terrain that I seek to replicate.
Currently, I'm generating the terrain fine, but I want to add that warp effect.
// Do this before using 'ws' to sample the nine octaves!
float3 warp = noiseVol2.Sample( TrilinearRepeat, ws*0.004 ).xyz;
ws += warp * 8;

Im wondering how to replicate the above code in C#. What does the above code do? What type of variable is noiseVol2.Sample(x,y).xyz?
I want to warp my own terrain, currently I have a system that creates octaves of perlin noise with certain frequencies and amplitudes.
It looks something like this:
var perlin0 = new Perlin3(0,baseFreq  * 4.03f, 0.25f);
var perlin1 = new Perlin3(1, baseFreq * 1.96f, 0.50f);
var perlin2 = new Perlin3(2, baseFreq * 1.01f, 1.00f);
var perlin3 = new Perlin3(3, baseFreq * 0.49f, 2.00f);
var perlin4 = new Perlin3(4, baseFreq * 0.24f, 4.00f);

return new Density(ws => {

float density = plane.Evaluate(ws);

// add perlin noise to get density values at each ws co-ord.
//3 octaves currently (3 perlin noise +=)
density += perlin0.Evaluate(ws);
density += perlin1.Evaluate(ws);
density += perlin2.Evaluate(ws);
density += perlin3.Evaluate(ws);
density += perlin4.Evaluate(ws);
return density;
});

I've tried replicating it like so:
var q = new Vector3(perlin0.Evaluate(new Vector3(0,0,0)), perlin0.Evaluate(new Vector3(5.2f, 1.3f, 1.3f)));
var q1 = new Vector3(perlin1.Evaluate(new Vector3(0, 0, 0)), perlin1.Evaluate(new Vector3(5.2f, 1.3f, 1.3f)));
var q2 = new Vector3(perlin2.Evaluate(new Vector3(0, 0, 0)), perlin2.Evaluate(new Vector3(5.2f, 1.3f, 1.3f)));
density += perlin0.Evaluate(p + 4.0f*q);
density += perlin1.Evaluate(p + 4.0f * q1);
density += perlin2.Evaluate(p + 4.0f * q2);

I've read the article that Íñigo Quílez created, and implemented it like above. Am I doing something wrong? It looks the same without that, just using
density += perlin0.Evaluate(p);
density += perlin1.Evaluate(p);
density += perlin2.Evaluate(p);

I want to know what I'm doing wrong, what I misunderstood and how to implement it correctly.
This is all based off this lumpn's proceedural-generation on github
(I would link it, but I can't)
Thanks.
I would also want to know if there are any examples (I learn best from codebases) with this implementation using shaders. (Maybe it will run faster because it uses the GPU instead of the CPU?)
This is still unanswered on how to do it on the CPU
(and I'm still confused on how to do it on the GPU, do you have to do some vertex stuff? how do you pass in a noise texture through the shader?)
```