<p>I am following the algorithm shown in <a href="https://github.com/robovm/apple-ios-samples/tree/master/GLCameraRipple" rel="nofollow noreferrer">this code</a> here. Essentially there is a simple simulation of heights and then the difference in heights on the x and y axis respectively (sampling adjacent points) ends up defining how much you add/subtract to your texture coordinate.</p>

<p>The result is displayed in this video <a href="https://www.youtube.com/watch?v=0KoqUdynPpY" rel="nofollow noreferrer">here</a> </p>

<p>My question is essentially do you think you could write a fragment shader that adds some sort of good looking specular highlight to this. Almost as though there were some sort of light off the edge. Just to add more feeling of depth/shape.</p>

<p>So far the only thing I have thought of is to look at the difference between the distorted and the normal texture coordinate which ends up looking something like this:
<a href="https://i.sstatic.net/0xWJJ.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0xWJJ.jpg" alt="enter image description here"></a></p>

<p>However since that vector is inherently 2D I am not sure how to figure out a 3D normal that would be useful for calculating the specular.</p>

<p>Any ideas?</p>

CC BY-SA 4.0
2020-04-05T15:57:16.283Z
You could make a 3d normal from a 2d normal with something like > float height = 1.0; N = normalize(vec3(Normal2D, height));
PaulHK
CC BY-SA 4.0
2020-04-05T20:31:02.370Z
@PaulHK brilliant! That works quite well. Still working on getting it tuned to where I need. It.
CalebK
CC BY-SA 4.0
2020-04-07T08:33:03.587Z
Would be interesting to see your results, happy to help
PaulHK
<lighting><specular>
Adding specular reflections to a ripple simulation
CalebK
# Adding specular reflections to a ripple simulation

(Asked by: username_0 on 2020-04-05)

I am following the algorithm shown in [this code](https://github.com/robovm/apple-ios-samples/tree/master/GLCameraRipple) here. Essentially there is a simple simulation of heights and then the difference in heights on the x and y axis respectively (sampling adjacent points) ends up defining how much you add/subtract to your texture coordinate.

The result is displayed in this video [here](https://www.youtube.com/watch?v=0KoqUdynPpY)

My question is essentially do you think you could write a fragment shader that adds some sort of good looking specular highlight to this. Almost as though there were some sort of light off the edge. Just to add more feeling of depth/shape.

So far the only thing I have thought of is to look at the difference between the distorted and the normal texture coordinate which ends up looking something like this:
[![enter image description here](https://i.sstatic.net/0xWJJ.jpg)](https://i.sstatic.net/0xWJJ.jpg)

However since that vector is inherently 2D I am not sure how to figure out a 3D normal that would be useful for calculating the specular.

Any ideas?

**Tags:** lighting, specular

> **Comments:**
> **username_1**: You could make a 3d normal from a 2d normal with something like > float height = 1.0; N = normalize(vec3(Normal2D, height));  
> **username_0**: @username_1 brilliant! That works quite well. Still working on getting it tuned to where I need. It.  
> **username_1**: Would be interesting to see your results, happy to help  

---

## 0 answers

