Displacing a video's depth in GLSL / Displacement Issues

What I’m doing just seems to be creating a displacement map, but I’m running into some issues in the process. I have two videos, one for the source, one for displacement. The displacement map is the same size as the source video. My shaders are simple:

#version 120

uniform sampler2D displacementMap;

varying vec4 position;
varying vec2 texCoordVarying;

void main(){
    texCoordVarying = gl_MultiTexCoord0.xy;
    vec4 position = gl_Vertex;
    position.z += texture2D(displacementMap,texCoordVarying).r * 100.0;
    gl_Position = gl_ModelViewProjectionMatrix * position;
#version 120

uniform sampler2D tex0;

varying vec2 texCoordVarying;

void main()
    vec2 uv = texCoordVarying;
    gl_FragColor = texture2D(tex0,uv);

Now, running this gives me what appears to be a very low resolution displacement. The peaks and troughs are sharp, nowhere near corresponding to my displacement input. This makes me think I am in some way mishandling coordinates in my vertex shader, or formatting the texture input incorrectly. That brings up another question for me, can I just manipulate the video without copying it to a plane or something like that? Is the issue with the FBO I’m using for the displacement? The FBO is currently just perlin noise with the same dimensions as the video.

Here is a sample from draw():

    shader_heat.setUniformTexture("displacementMap", fbo.getTexture(), 1);    

Any advice would be appreciated. The .cpp is below, it’s a little unwieldy with the other shaders, but should at least fill in what I didn’t explain above.


Hi there!

I’m on my phone, so I can’t properly check all of your code, but you are trying to displace an ofVideoPlayer, then you are displacing a low poly plane. You need to get both your textures to a plane with an higher grid. Use one texture for displacing, and another to texture it.

1 Like

Great, thanks hubris, it’s working now. Having trouble getting lighting to work on it, but that will be something new to learn.

EDIT: @hubris, actually now that I’m looking around for some lighting solutions for this, I’m finding posts of yours from a few years back for getting ofLight to work with shaders, but a bit at a loss still. Know what direction to point me?

Since you are using your custom shader, you need to create your own lightning.

A good place to start, is to check OF’s custom shader in ofMaterial.cpp. Just use that code on your shader and create/enable the other objects like you would.

1 Like