Forums > Jitter

try to implement shader for z-depth map according the luminance of the texture

Apr 04 2012 | 3:45 pm

hi all,
I try to learn about glsl shaders, in implementing this shader for jitter:
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.

-- Pasted Max Patch, click to expand. --

  1. ghost2.jxs
Apr 04 2012 | 5:27 pm

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 :)

-- Pasted Max Patch, click to expand. --

Apr 04 2012 | 5:34 pm

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.

Apr 04 2012 | 5:54 pm

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.

Apr 04 2012 | 9:05 pm

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 ;)

Apr 04 2012 | 9:08 pm

no. information can only go from the vertex shader to the fragment shader.

Apr 04 2012 | 9:32 pm

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 !

Apr 04 2012 | 10:56 pm

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

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.

Apr 05 2012 | 9:28 am

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,

-- Pasted Max Patch, click to expand. --

  1. ghost4luma.jxs
Viewing 9 posts - 1 through 9 (of 9 total)

Forums > Jitter