JavaScript WebGL drawing 2D image with depth map to achieve pseudo-3D effect

I'm learning WebGL, done that with the help of WebGLFundamentals page, which helped me pretty much to understand how buffers, shaders and all that stuff works. But now I want to achieve a certain effect which I saw here: https://tympanus.net/Tutorials/HeatDistortionEffect/index3.html I know how to make the heat distortion effect, the effect I want to achieve is the DEPTH on the image. This demo has a tutorial but it doesnt really explain how to do it, it says I must have a grayscale map, in which the white parts are the closest ones and the black parts the farest. But I really cant understand how it works, here is my shader's code:

var vertexShaderText = [
     "attribute vec2 a_position;",
     "attribute vec2 a_texCoord;",
     "uniform vec2 u_resolution;",
     "varying vec2 v_texCoord;",
     "void main() {",
     "  vec2 zeroToOne = a_position / u_resolution;",
     "  vec2 zeroToTwo = zeroToOne * 2.0;",
     "  vec2 clipSpace = zeroToTwo - 1.0;",
     "  gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);",
     "  v_texCoord = a_texCoord;",
     "}"
  ].join("\n")

  var fragShaderText = [
     "precision mediump float;",
     "uniform sampler2D u_image;",
     "uniform sampler2D u_depthMap;",
     "uniform vec2 mouse;",
     "varying vec2 v_texCoord;",
     "void main() {",
     "  float frequency=100.0;",
     "  float amplitude=0.010;",
     "  float distortion=sin(v_texCoord.y*frequency)*amplitude;",
     "  float map=texture2D(u_depthMap,v_texCoord).r;",
     "  vec4 color=texture2D(u_image,vec2(v_texCoord.x+distortion*map, v_texCoord.y));",
     "  gl_FragColor = color;",
     "}"
  ].join("\n")

What I want is when I move the mouse, the image would respond to the shader to distort like in the link I showed above. But I really have no idea on how to do it on the javascript part. Thanks

Answer:1

I have a commonly reused set of form inputs that are reused throughout my application, so I am trying to encapsulate them in a custom directive. I want to set an ngModel on my directive and have that ...

I have a commonly reused set of form inputs that are reused throughout my application, so I am trying to encapsulate them in a custom directive. I want to set an ngModel on my directive and have that ...

  1. ngmodel custom directive
  2. angularjs ng model custom directive
  3. ng-model inside custom directive
  4. angular ng-model custom directive
  5. require ngmodel in custom directive

_renderItem is not executing at all, tried with console.log too no messages printed. Tried with 'autocomplete', 'ui-autocomplete', 'Autocomplete' attributes no hope. In addition I could not ...

_renderItem is not executing at all, tried with console.log too no messages printed. Tried with 'autocomplete', 'ui-autocomplete', 'Autocomplete' attributes no hope. In addition I could not ...

  1. jquery autocomplete _renderitem not working
  2. jquery autocomplete _renderitem undefined
  3. jquery autocomplete _renderitem example
  4. jquery autocomplete _renderitem
  5. jquery autocomplete _renderitem multiple
  6. jquery autocomplete _renderitem select
  7. jquery autocomplete _renderitem table
  8. jquery ui autocomplete _renderitem
  9. jquery ui autocomplete _renderitem example
  10. jquery ui autocomplete _renderitem not working
  11. jquery autocomplete override renderitem
  12. jquery autocomplete ajax _renderitem
  13. jquery autocomplete custom renderitem
  14. jquery ui autocomplete _renderitem highlight
  15. jquery autocomplete data _renderitem
  16. jquery ui autocomplete custom renderitem
  17. jquery ui autocomplete override renderitem
  18. jquery autocomplete custom rendered item
  19. jquery autocomplete renderitem
  20. jquery ui autocomplete renderitem

What does this expression mean in Vuejs? :class="{ expr1: expr2}" It appears be a truth expression, but is there a binary truth operator in Javascript?

What does this expression mean in Vuejs? :class="{ expr1: expr2}" It appears be a truth expression, but is there a binary truth operator in Javascript?

I have in the below parameters for all ajax calls in the <head> of my document. (I need this for an iOS ajax bug at https://stackoverflow.com/a/12856562/627473 $.ajaxSetup ({ cache: ...

I have in the below parameters for all ajax calls in the <head> of my document. (I need this for an iOS ajax bug at https://stackoverflow.com/a/12856562/627473 $.ajaxSetup ({ cache: ...

  1. jquery ajaxsetup headers
  2. jquery ajaxsetup headers authorization
  3. jquery ajax headers
  4. jquery ajax headers authorization
  5. jquery ajax headers access-control-allow-origin
  6. jquery ajax headers authorization bearer
  7. jquery ajax headers cors
  8. jquery ajax headers content type
  9. jquery ajax headers not working
  10. jquery ajax headers basic authentication
  11. jquery ajax headers post
  12. jquery ajax headers cookie
  13. jquery ajax headers json
  14. jquery ajax headers accept
  15. jquery ajax headers cross domain
  16. jquery ajax headers not added
  17. jquery ajax headers get
  18. jquery ajax headers origin
  19. jquery ajax headers not being set
  20. jquery ajax headers response