a simple question about programmable shaders


    Aug 25 2006 | 2:39 pm
    i would like to make a vertex program that applies a certain deformation to a plane based on the contents of a jitter matrix. i.e., i have a plane and i'd like to displace certain points on this plane based on a jit-matrix that i'm writing into with jit.lcd or some such.
    i'm not sure how to access the contents of a jit.matrix from within my glsl shader program.
    any hints?
    thanks, a

    • Aug 25 2006 | 2:59 pm
      You could tranfer the lcd contents to a texture and access the texture from within the shader. Ofcouse you'll have to bind both the texture and shader program to the plane using the normal @texture and @shader attributes. Instead of using the rgba values to influence the color of the plane, you can then use them to do something else. I'm not really sure you can access the texture "sampler2D" in the vertex program, but I suspect you can.
      hth, -thijs
      On 8/25/06, Ali Momeni wrote: > > > i would like to make a vertex program that applies a certain deformation > to a plane based on the contents of a jitter matrix. i.e., i have a plane > and i'd like to displace certain points on this plane based on a jit-matrix > that i'm writing into with jit.lcd or some such. > > i'm not sure how to access the contents of a jit.matrix from within my > glsl shader program. > > any hints? > > thanks, > a > >
    • Aug 25 2006 | 3:18 pm
      i'm with you so far; however, what i need is to access particular positions in my texture within my vertext program. is tex0 indexted like a matrix, as in tex0[x][y] would be the x,y point in my texture?
    • Aug 25 2006 | 3:52 pm
      You access a texture by instantiating a the sampler2D for every texture. Then to access its content you call the texture2D method with 2 arguments. The first being the texture id, tex0, and the second one being the array of texture coordinates (st / xy in case of a 2D texture). You can use the coordinates generated automatically by opengl (according to the texturing mode), but in your case you would calculate the coordinates yourself. So the answer is yes, you can access your texture like an array, only not like tex0[x,y] but through use of the texture2D method.
      I don't have experience with this either, but I have the orange book sitting next to me:-) I suggest you check it out online.
      -thijs
      On 8/25/06, Ali Momeni wrote: > > > i'm with you so far; > however, what i need is to access particular positions in my texture > within my vertext program. is tex0 indexted like a matrix, as in tex0[x][y] > would be the x,y point in my texture? >
    • Aug 25 2006 | 4:01 pm
      still with you, i've discovered texture2DRect but am not sure how to provide the vec2 coor for the point i wanna access.
      first, is the 2nd argument of texture2DRect in integers as in the pixel position in the texture, or is it a float between 0. and 1. for x and y?
      and second, how could i access the automattically generated coordinates by OpenGL?
      say, you happen to have a linke for the orange book online? or you bought the hard copy....
    • Aug 25 2006 | 4:16 pm
      ah, now i have a new problem. it seems that i'm not allowed to use textures from the outside like tex0 and tex1 and ... in a vertex program.
      i get this error: -- ERROR: Implementation limit of 0 active vertex shader samplers (e.g., maximum number of supported image units) exceeded, vertex shader uses 1 samplers • error: -- END GLSL INFO LOG: jDang:/Users/ali/Documents/_for-MaxMSP/_current/shaders/gravity-lighting1.jxs --
      this so called implementation limit of 0 seems to be rather low, no? :)
      a
    • Aug 25 2006 | 4:42 pm
      Hi Ali, Texture access is not allowed in the current version of vertex programs that both OSX and Windows support. For this, you're going to have to wait for the next version of GLSL to make its way from standard to actually being implemented in the OS. This kind of thing and a new type of shader called Geometry shaders are what's coming in the future.
      For now, you're going to have to use a per-vertex value such as color, tangent, bitangent, or specular array (basically one of jit.gl.mesh's inputs). You'll access these using the built in GLSL variables for accessing fixed function values like gl_Color or gl_Normal and just ignore the name and use it how you want. So, this is entirely possible to do now, just not with textures. If you need more direction on how to do this, let me know and I'll see if I can whip out an example.
      wes
    • Aug 25 2006 | 4:50 pm
      first, is the 2nd argument of texture2DRect in integers as in the pixel > position in the texture, or is it a float between 0. and 1. for x and y?
      I think its 0-1
      > and second, how could i access the automattically generated coordinates by > OpenGL?
      gl_MultiTexCoord0.st
      > say, you happen to have a linke for the orange book online? or you bought > the hard copy....
      my bad, I made a wrong assumption that the orange book was available online too, just like the other opengl books. I have a hardcopy. About the errors you're getting.. I can't help with that. Like I said I don't have experience with this stuff. It's time for someone with more knowledge to take over.
      good luck, -thijs
    • Aug 25 2006 | 4:59 pm
      hi wes, ah, i see; so the implimentation limit of 0 is not a jitter thing but rather a GLSL standard thing.
      as for the present solution, i think i understand; i need to get the data from outside (i.e. from jitter) into my glsl thru other means... so if i want to displace points on my plane forinstance, i should write color/normal/... values into the vector for the shape to which i'm applying my shader, and then recover them in my glsl code with gl_Color, gl_Normal and such....? if you happen to have a little example easily whipped out, i'd be most grateful.
      a
    • Aug 25 2006 | 5:06 pm
      These are the state variables that you can bind vertex shader attributes to. The correspond precisely to their jit.gl.mesh's namesake.:
      "POSITION" "NORMAL" "TANGENT" "BITANGENT" "TEXCOORD"
      I had a patch lying around that already did this, so here you go. There's a patch and a shader:
      ----------------------------Vertex Displace Patch---------------------------------
      -----------------------------------------------vertex distaplce shader-----------------------------------
      Textured glass-like material lit with a point light w/ two specular components calculated per pixel. Position of Light Source Position Tangent Primary Specular Color Secondary Specular Color Base Color Primary Specular Multiplier Secondary Specular Multiplier Specularity Adjustment
    • Aug 25 2006 | 5:12 pm
      i get the patch but i'm not sure if you included all of the shader called vd.attr2.jxs....
      would you please post that again?
      a
    • Aug 25 2006 | 5:15 pm
      On Aug 25, 2006, at 9:59 AM, Ali Momeni wrote:
      > as for the present solution, i think i understand; > i need to get the data from outside (i.e. from jitter) into my glsl > thru other means... > so if i want to displace points on my plane forinstance, i should > write color/normal/... values into the vector for the shape to > which i'm applying my shader, and then recover them in my glsl code > with gl_Color, gl_Normal and such....?
      This is probably easiest to accomplish using jit.gl.mesh.
      FWIW, ALI, since you need to submit the data as another matrix of information, you might find this easier to do with standard CPU based jitter matrix operator objects if it's not an incredibly complex calculation.
      -Joshua
    • Aug 25 2006 | 5:19 pm
      Here you go again. It was at the bottom of my previous email:
      Textured glass-like material lit with a point light w/ two specular components calculated per pixel. Position of Light Source Position Tangent Primary Specular Color Secondary Specular Color Base Color Primary Specular Multiplier Secondary Specular Multiplier Specularity Adjustment
    • Aug 25 2006 | 5:25 pm
      thanks joshua. if what you mean is that i might as well do everything on the CPU with jitter, then yes, i can and have tried that; it works fine and i get about 16fps on my macbook pro; i'd like to get about 60fps so i thought i'd try another route.... :)
    • Aug 25 2006 | 5:44 pm
      incidentally, i just tried my jitter/CPU patch which i'd developed with 4.6 beta 1 and jitter 1.6 UB beta 1 and it now crashes max.
      it gives this error before crashing:
      •error: jit.gl.pbuffer: unable to get a valid pixel format! •error: jit.gl.texture: error attaching texture to readback mecahnism for capture!
      oddly enough, the patch works in 4.5.7/1.6 running in rosette on my machine!
      must be a readback from GPU problem cuz i use the gaussian blur shader and try get back the data into a jitter matrix...
      any thoughts?
    • Aug 25 2006 | 6:09 pm
      > any thoughts?
      Yes, please please please post a proper bug report with instructions about making it crash and a patch that demonstrates. Otherwise, this is hairy stuff and it's never going to get fixed.
      thanks, wes
    • Aug 25 2006 | 6:38 pm
      alright, i'm trying to do unlike my usual self and actually reduce the complicated patch to the sipmlest version that crashes, but i'm getting very confused with something.
      i get hundreds of these:
      • error: jit.gl.texture: error attaching texture to readback mechanism for capture! jit.gl.texture: error submitting texture data: GL Error: Invalid operation • error: jit.gl.texture: unable to create texture! jit.gl.texture: error submitting texture data: GL Error: Invalid operation
      but i don't have any jit.gl.texture objects in my patch...?! i have a "jit.gl.slab.gauss6x foo" abstraction, a "jit.gl.videoplane", and a "jit.gl.render" and that's it for gl objects... who's causing the errors?
      a
    • Aug 25 2006 | 6:48 pm
      On Aug 25, 2006, at 11:38 AM, Ali Momeni wrote:
      > i get hundreds of these: > • error: jit.gl.texture: unable to create texture! > jit.gl.texture: error submitting texture data: GL Error: Invalid > operation > > but i don't have any jit.gl.texture objects in my patch...?! > i have a "jit.gl.slab.gauss6x foo" abstraction, a > "jit.gl.videoplane", and a "jit.gl.render" and that's it for gl > objects... who's causing the errors?
      jit.gl.slab internally uses a texture for each input as well as the output.
      -Joshua
    • Aug 25 2006 | 6:51 pm
      On Aug 25, 2006, at 11:38 AM, Ali Momeni wrote:
      > i get hundreds of these: > • error: jit.gl.texture: error attaching texture to readback > mechanism for capture! > jit.gl.texture: error submitting texture data: GL Error: Invalid > operation > > i have a "jit.gl.slab.gauss6x foo" abstraction, a > "jit.gl.videoplane", and a "jit.gl.render" and that's it for gl > objects... who's causing the errors?
      Btw, make sure that jit.gl.slab's args (in this case "foo"), are using the same name as the rendering context! This is something which may have worked by chance in 1.5.X but not 1.6
      -Joshua
    • Aug 26 2006 | 10:25 am
      indeed my gaussian blur has the same context name as my rendered.
      i wonder if what i'm trying to do (deform the vertext positions 3d form based on a matrix that i create in jitter) isn't more easily done with one of the other languages supported by jitters programmable shaders implementation like Cg or arb.... i know very little about them and how they differ from glsl...
      a
    • Aug 26 2006 | 8:36 pm
      On Aug 26, 2006, at 3:25 AM, Ali Momeni wrote:
      > i wonder if what i'm trying to do (deform the vertext positions 3d > form based on a matrix that i create in jitter) isn't more easily > done with one of the other languages supported by jitters > programmable shaders implementation like Cg or arb.... > i know very little about them and how they differ from glsl...
      Not likely. They all expose roughly the same HW functionality.
      -Joshua