# Displacement along normal not working

**URL:** https://discourse.libcinder.org/t/displacement-along-normal-not-working/470
**Category:** Using Cinder
**Created:** [December 30, 2016, 5:54pm UTC](https://discourse.libcinder.org/t/displacement-along-normal-not-working/470 "2016-12-30T17:54:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Craigson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/craigson/32/43_2.png) [@Craigson](https://discourse.libcinder.org/u/Craigson)
#### Post date: [December 30, 2016, 5:54pm UTC](https://discourse.libcinder.org/t/displacement-along-normal-not-working/470/1 "2016-12-30T17:54:27Z")

</div>

Hi all,

I haven’t had the chance to use Cinder in a while, so figured the holidays were a good time to dive back in. In my first attempt at shaking off the rust, I’ve clearly forgotten a few things.

I’ve created and animated a texture using some simplex noise. I had no trouble doing a texture lookup in the vertex shader to adjust the y value of the vertices of a geom::Plane(), however trying to apply the logic to an Isosphere by displacing the vertices along their respective normals seems to be causing me some issues. There seems to be some distortion along the z-axis that is causing the sphere to flatten. I know it’s something trivial I’m overlooking - here’s the vertex shader:

```
#version 150

uniform mat4 ciModelViewProjection;
uniform mat3 ciNormalMatrix;

in vec4 ciPosition;
in vec3 ciNormal;
in vec2	ciTexCoord0;

out vec2 texCoordVarying;
out vec3 vNormal;

// texture containing incoming noise data
uniform sampler2D tex0;

void main()
{
    
    vNormal = normalize(ciNormalMatrix * ciNormal);

    // we need to scale up the values we get from the texture
    float scale = 0.05f;
    
    // here we get the red channel value from the texture
    // to use it as displacement along the normal
    float displacementY = texture(tex0, ciTexCoord0).r;
    
    vec3 newPosition = ciPosition.xyz + (vNormal * displacementY * scale);

    gl_Position = ciModelViewProjection * vec4(newPosition, 1.);
    
    // pass the texture coordinates to the fragment shader
    texCoordVarying = ciTexCoord0;
}

```

Thanks, and happy holidays!

---

<div class="post-metadata">

### Author: ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)
#### Post date: [December 30, 2016, 11:02pm UTC](https://discourse.libcinder.org/t/displacement-along-normal-not-working/470/2 "2016-12-30T23:02:01Z")

</div>

Hi,

you’re transforming the normal to view space before displacing the vertex in object space, hence you’re working in two different coordinate spaces. For the displacement, simply use `ciNormal` instead of `vNormal`.

-Paul

---

<div class="post-metadata">

### Author: ![Craigson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/craigson/32/43_2.png) [@Craigson](https://discourse.libcinder.org/u/Craigson)
#### Post date: [December 31, 2016, 12:22am UTC](https://discourse.libcinder.org/t/displacement-along-normal-not-working/470/3 "2016-12-31T00:22:41Z")

</div>

Classic. Thanks Paul, that was it.
