try to implement shader for z-depth map according the luminance of the texture
hi all,
I try to learn about glsl shaders, in implementing this shader for jitter:
http://vimeo.com/38019842
basically, he maps the z of the mesh according to the red values of texture (if I understand correctly his code).
I would like to do that but according to the luminance of each pixel.
see the attached result, it's more like a polygone global treatment than a really fine pixel one.
I would like to have some clues, what I do wrong ? I couldn't transmit the luminance value from fragment to vertex so I trie to the calculation in the vertex, maybe stupid-I'm not even sure that the luma is correctly detected :)
the amplitude param is not bind, because as you can see, it would crash max (see .jxs file)
here's the patch and the shader;
thx you in adavance.
when i try to run your patch, max stops working, but i did it using jit.gen.
i am starting, to play around with gen, so maybe it wont be ideal :)
thx, this is weird my patch doesn't crash here…anyway the result is kind of what I want beside the fact that I want to do this with shaders, I need to learn about them !:)
Thx in advance.
The capability of using textures in the vertex program is highly driver dependent. Depending on your hardware+OS+graphics card driver it may or may not work.
and would it be possible to send luma calculated in the fragment program into the vertex program ? Haven't find anything like that…
varying sends values from vertex to fragment…but the opposite…?
still workout on my mess ghost shader ;)
no. information can only go from the vertex shader to the fragment shader.
ok so I'm on the good way ? I suppose my mistake comes from gl_ModelViewProjectionMatrix or gl_TextureMatrix… even with docs it's pretty new to me !
thx.
The biggest error in that shader was the binding of the same to both VP and FP. You have to choose one. You can however create 2 params that point to the same texture. So you could do the following:
and then bind "tex1" to "vp"
Another thing I noticed is that you set up a varying "texcoord" that is never written to in the vertex program. By default this will just be zero. Try adding this line before the sampling line
texcoord=gl_TexCoord[0].xy;
Finally, you aren't using the "amplitude" variable, so that will throw a warning. Try multiplying luminance*amplitude in your code now. One thing I noticed on that video is that it appears that it's actually doing a Y offset based on luminance instead of Z, but it will just look different.
thanks wesley and andrew for your time. final version works, actually no need to varying texcoord, if I'm not wrong:
gl_TexCoord[0] = gl_TextureMatrix[0]*gl_MultiTexCoord0 does transform texture coordinate into vertex position.
here's the jxs working,