I am following the algorithm shown in this code 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

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

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?

  • 2
    $\begingroup$ You could make a 3d normal from a 2d normal with something like > float height = 1.0; N = normalize(vec3(Normal2D, height)); $\endgroup$
    – PaulHK
    Apr 5, 2020 at 15:57
  • $\begingroup$ @PaulHK brilliant! That works quite well. Still working on getting it tuned to where I need. It. $\endgroup$
    – CalebK
    Apr 5, 2020 at 20:31
  • $\begingroup$ Would be interesting to see your results, happy to help $\endgroup$
    – PaulHK
    Apr 7, 2020 at 8:33


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.