hello,
here is a square mesh generator object i made mixing code from a square and newWave, disigned to be used with vertex shader. i don't know if it should go from -1 to 1 (gem standart), or from 0 to 1 (best for vertex shader) i also don't know if texture coordinate should be precomputed (like in newWave) or not.
so, tell me what you think.
maybe i should accept cvs write access and commit this myself...
cyrille
hi cyrille, this is cool! I am no friend of the gem standard anyway, so, if the range is between 0 and 1 that would be perfect. but if you want to go with the gem standard, then maybe you can add a message flag to switch between gem standard (-1 to 1) and shader standard. what do mean by precomputed? would that mean everytime you change the dimension the values get recalculated? I guess that would make the object faster, no? marius.
cyrille henry wrote:
hello,
here is a square mesh generator object i made mixing code from a square and newWave, disigned to be used with vertex shader. i don't know if it should go from -1 to 1 (gem standart), or from 0 to 1 (best for vertex shader) i also don't know if texture coordinate should be precomputed (like in newWave) or not.
so, tell me what you think.
maybe i should accept cvs write access and commit this myself...
cyrille
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
hello,
marius schebella a écrit :
hi cyrille, this is cool! I am no friend of the gem standard anyway, so, if the range is between 0 and 1 that would be perfect. but if you want to go with the gem standard, then maybe you can add a message flag to switch between gem standard (-1 to 1) and shader standard.
yes, this is also a good option.
what do mean by precomputed? would that mean everytime you change the dimension the values get recalculated?
yes, curently, the texture coordinate a computed every time the texture change.
I guess that would make the object faster, no?
i don't know if 2 multiplication is slower than reading in a 2d array.
cyrille
marius.
cyrille henry wrote:
hello,
here is a square mesh generator object i made mixing code from a square and newWave, disigned to be used with vertex shader. i don't know if it should go from -1 to 1 (gem standart), or from 0 to 1 (best for vertex shader) i also don't know if texture coordinate should be precomputed (like in newWave) or not.
so, tell me what you think.
maybe i should accept cvs write access and commit this myself...
cyrille
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
On Dec 16, 2007 6:39 AM, cyrille henry cyrille.henry@la-kitchen.fr wrote:
maybe i should accept cvs write access and commit this myself...
Yes, you should.
cgc
Hallo,
great see this new object. For vertex displacement i worked with curve3d before but the mesh_square interpolate smoother.
But when you change the grid the texture stays to the initial arguments given to the object. see the patch with displacement based on the luminance of texture.
lg mn
Am 16.12.2007 um 13:39 schrieb cyrille henry:
hello,
here is a square mesh generator object i made mixing code from a square and newWave, disigned to be used with vertex shader. i don't know if it should go from -1 to 1 (gem standart), or from 0 to 1 (best for vertex shader) i also don't know if texture coordinate should be precomputed (like in newWave) or not.
so, tell me what you think.
maybe i should accept cvs write access and commit this myself...
cyrille
/*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia
A mesh_square
Copyright (c) 1997-2000 Mark Danks. mark@danks.org Copyright (c) Günther Geiger. geiger@epy.co.at Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM. zmoelnig@iem.kug.ac.at For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-----------------------------------------------------------------*/
#ifndef INCLUDE_mesh_square_H_ #define INCLUDE_mesh_square_H_
#include "Base/GemShape.h"
#define MAXGRID 1000
/*-----------------------------------------------------------------
CLASS mesh_square
Creates a mesh_square
KEYWORDS geo
DESCRIPTION
-----------------------------------------------------------------*/ class GEM_EXTERN mesh_square : public GemShape { CPPEXTERN_HEADER(mesh_square, GemShape)
public:
////////// // Constructor mesh_square(t_floatarg sizeX,t_floatarg sizeY);
protected: ////////// // Destructor virtual ~mesh_square();
int m_blend; ////////// // Do the rendering virtual void render(GemState *state); static void blendMessCallback(void *data, t_floatarg size); static void gridMessCallback(void *data, t_floatarg size); static void gridXMessCallback(void *data, t_floatarg size); static void gridYMessCallback(void *data, t_floatarg size); ////////// // getStuff int gridX, gridY; float xsize, xsize0, ysize, ysize0; int alreadyInit; void setSize( int valueX, int valueY ); void getTexCoords(void); float texCoords[MAXGRID][MAXGRID][2];
};
#endif // for header file //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmoelnig@iem.kug.ac.at // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) Günther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // /////////////////////////////////////////////////////////
#include "mesh_square.h"
#include "Base/GemState.h"
CPPEXTERN_NEW_WITH_TWO_ARGS(mesh_square, t_floatarg, A_DEFFLOAT, t_floatarg, A_DEFFLOAT)
///////////////////////////////////////////////////////// // // mesh_square // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// mesh_square :: mesh_square(t_floatarg sizeX, t_floatarg sizeY) : GemShape(1) { m_linewidth=1.0; // m_drawType = GL_QUADS; m_blend=0; setSize((int)sizeX,(int)sizeY); }
///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// mesh_square :: ~mesh_square() { }
///////////////////////////////////////////////////////// // getTexCoords // ///////////////////////////////////////////////////////// void mesh_square :: getTexCoords(void) { for ( int i = 0; i < gridX; ++i) { for ( int j = 0; j < gridY; ++j) { texCoords[i][j][0] = ((xsize*(float)i/(float)(gridX-1)) + xsize0 ); texCoords[i][j][1] = ((ysize*(float)j/(float)(gridY-1)) + ysize0 ); //post("texCoords[%d][%d] = %f\t%f",i,j,texCoords[i][j] [0],texCoords[i][j][1]); } } }
///////////////////////////////////////////////////////// // setSize // ///////////////////////////////////////////////////////// void mesh_square :: setSize( int valueX, int valueY ) { if(valueX>1) gridX = valueX; else gridX = 5;
if(valueY>1) gridY = valueY; else gridY = gridX;
getTexCoords(); }
///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void mesh_square :: render(GemState *state) { int i,j; GLfloat sizeX = 2. / (GLfloat)(gridX-1); GLfloat sizeY = 2. / (GLfloat)(gridY-1);
if(m_drawType==GL_DEFAULT_GEM)m_drawType=GL_TRIANGLE_STRIP; //m_drawType=GL_LINES;
glNormal3f(0.0f, 0.0f, 1.0f); if (m_drawType == GL_LINE_LOOP) m_drawType = GL_LINES;
if (m_drawType == GL_LINES) glLineWidth(m_linewidth);
if (m_blend) { glEnable(GL_POLYGON_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glHint(GL_POLYGON_SMOOTH_HINT,GL_DONT_CARE); }
glNormal3f( 0.0f, 0.0f, 1.0f);
if (state->texture && state->numTexCoords>=3) { if ((xsize0!= state->texCoords[0].s) || (xsize != state->texCoords[1].s-xsize0) || (ysize0!= state->texCoords[1].t) || (ysize != state->texCoords[2].t-ysize0)) alreadyInit = 0;
if (!alreadyInit) { xsize0 = state->texCoords[0].s; xsize = state->texCoords[1].s-xsize0; ysize0 = state->texCoords[1].t; ysize = state->texCoords[2].t-ysize0; setSize( gridX, gridY ); alreadyInit = 1; } for (int i=0; i<(gridX-1) ; i++) { glBegin(m_drawType); for (int j = 0; j < gridY ; j++) { glTexCoord2fv( texCoords[i][j] ); glVertex3f( m_size * (i*sizeX - 1), m_size * (j*sizeY
-1) , 0);
glTexCoord2fv( texCoords[i+1][j] ); glVertex3f( m_size * ((i+1)*sizeX - 1), m_size *
(j*sizeY -1), 0); } glEnd(); } }else { if (!alreadyInit) { xsize = 1; ysize = 1; ysize0= 0; xsize0= 0;
setSize( gridX, gridY); alreadyInit = 1; } for ( i = 0; i<(gridX -1); i++) { glBegin(m_drawType); for ( j = 0; j < gridY ; j++) { glTexCoord2fv( texCoords[i][j] ); glVertex3f( m_size * (i*sizeX -1), m_size * (j*sizeY
-1), 0 );
glTexCoord2fv( texCoords[i+1][j] ); glVertex3f( m_size * ((i+1)*sizeX -1), m_size *
(j*sizeY -1), 0 ); } glEnd(); } }
if (m_blend) { glDisable(GL_POLYGON_SMOOTH); glDisable(GL_BLEND); } }
///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void mesh_square :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&mesh_square::blendMessCallback, gensym("blend"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&mesh_square::gridMessCallback, gensym("grid"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&mesh_square::gridXMessCallback, gensym("gridX"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&mesh_square::gridYMessCallback, gensym("gridY"), A_FLOAT, A_NULL); }
void mesh_square :: blendMessCallback(void *data, t_floatarg blend) { GetMyClass(data)->m_blend=((int)blend); }
void mesh_square :: gridMessCallback(void *data, t_floatarg grid) { GetMyClass(data)->gridX=(int)grid; GetMyClass(data)->gridY=(int)grid; }
void mesh_square :: gridXMessCallback(void *data, t_floatarg grid) { GetMyClass(data)->gridX=(int)grid; }
void mesh_square :: gridYMessCallback(void *data, t_floatarg grid) { GetMyClass(data)->gridY=(int)grid; }
<mesh_square-help.pd>_______________________________________________ GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
Matthias Neuenhofer a écrit :
Hallo,
great see this new object. For vertex displacement i worked with curve3d before but the mesh_square interpolate smoother.
it should also be lot's faster than curve3d.
But when you change the grid the texture stays to the initial arguments given to the object. see the patch with displacement based on the luminance of texture.
hello, i was not able to use your shader, but i did not investigate. i saw the bug when changing the grid size with a texture. here is a new version that should correct it.
thanks for testing it.
cyrille
lg mn
Am 16.12.2007 um 13:39 schrieb cyrille henry:
hello,
here is a square mesh generator object i made mixing code from a square and newWave, disigned to be used with vertex shader. i don't know if it should go from -1 to 1 (gem standart), or from 0 to 1 (best for vertex shader) i also don't know if texture coordinate should be precomputed (like in newWave) or not.
so, tell me what you think.
maybe i should accept cvs write access and commit this myself...
cyrille
/*----------------------------------------------------------------- LOG GEM - Graphics Environment for Multimedia
A mesh_square
Copyright (c) 1997-2000 Mark Danks. mark@danks.org Copyright (c) Günther Geiger. geiger@epy.co.at Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM. zmoelnig@iem.kug.ac.at For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-----------------------------------------------------------------*/
#ifndef INCLUDE_mesh_square_H_ #define INCLUDE_mesh_square_H_
#include "Base/GemShape.h"
#define MAXGRID 1000
/*-----------------------------------------------------------------
CLASS mesh_square
Creates a mesh_square
KEYWORDS geo
DESCRIPTION
-----------------------------------------------------------------*/ class GEM_EXTERN mesh_square : public GemShape { CPPEXTERN_HEADER(mesh_square, GemShape)
public:
////////// // Constructor mesh_square(t_floatarg sizeX,t_floatarg sizeY);
protected:
////////// // Destructor virtual ~mesh_square(); int m_blend; ////////// // Do the rendering virtual void render(GemState *state); static void blendMessCallback(void *data, t_floatarg size); static void gridMessCallback(void *data, t_floatarg size); static void gridXMessCallback(void *data, t_floatarg size); static void gridYMessCallback(void *data, t_floatarg size); ////////// // getStuff int gridX, gridY; float xsize, xsize0, ysize, ysize0; int alreadyInit; void setSize( int valueX, int valueY ); void getTexCoords(void); float texCoords[MAXGRID][MAXGRID][2];
};
#endif // for header file //////////////////////////////////////////////////////// // // GEM - Graphics Environment for Multimedia // // zmoelnig@iem.kug.ac.at // // Implementation file // // Copyright (c) 1997-2000 Mark Danks. // Copyright (c) Günther Geiger. // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // /////////////////////////////////////////////////////////
#include "mesh_square.h"
#include "Base/GemState.h"
CPPEXTERN_NEW_WITH_TWO_ARGS(mesh_square, t_floatarg, A_DEFFLOAT, t_floatarg, A_DEFFLOAT)
///////////////////////////////////////////////////////// // // mesh_square // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// mesh_square :: mesh_square(t_floatarg sizeX, t_floatarg sizeY) : GemShape(1) { m_linewidth=1.0; // m_drawType = GL_QUADS; m_blend=0; setSize((int)sizeX,(int)sizeY); }
///////////////////////////////////////////////////////// // Destructor // ///////////////////////////////////////////////////////// mesh_square :: ~mesh_square() { }
///////////////////////////////////////////////////////// // getTexCoords // ///////////////////////////////////////////////////////// void mesh_square :: getTexCoords(void) { for ( int i = 0; i < gridX; ++i) { for ( int j = 0; j < gridY; ++j) { texCoords[i][j][0] = ((xsize*(float)i/(float)(gridX-1)) + xsize0 ); texCoords[i][j][1] = ((ysize*(float)j/(float)(gridY-1)) + ysize0 ); //post("texCoords[%d][%d] = %f\t%f",i,j,texCoords[i][j][0],texCoords[i][j][1]); } } }
///////////////////////////////////////////////////////// // setSize // ///////////////////////////////////////////////////////// void mesh_square :: setSize( int valueX, int valueY ) { if(valueX>1) gridX = valueX; else gridX = 5;
if(valueY>1) gridY = valueY; else gridY = gridX;
getTexCoords(); }
///////////////////////////////////////////////////////// // render // ///////////////////////////////////////////////////////// void mesh_square :: render(GemState *state) { int i,j; GLfloat sizeX = 2. / (GLfloat)(gridX-1); GLfloat sizeY = 2. / (GLfloat)(gridY-1);
if(m_drawType==GL_DEFAULT_GEM)m_drawType=GL_TRIANGLE_STRIP; //m_drawType=GL_LINES;
glNormal3f(0.0f, 0.0f, 1.0f); if (m_drawType == GL_LINE_LOOP) m_drawType = GL_LINES;
if (m_drawType == GL_LINES) glLineWidth(m_linewidth);
if (m_blend) { glEnable(GL_POLYGON_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glHint(GL_POLYGON_SMOOTH_HINT,GL_DONT_CARE); }
glNormal3f( 0.0f, 0.0f, 1.0f);
if (state->texture && state->numTexCoords>=3)
{ if ((xsize0!= state->texCoords[0].s) || (xsize != state->texCoords[1].s-xsize0) || (ysize0!= state->texCoords[1].t) || (ysize != state->texCoords[2].t-ysize0)) alreadyInit = 0;
if (!alreadyInit) { xsize0 = state->texCoords[0].s; xsize = state->texCoords[1].s-xsize0; ysize0 = state->texCoords[1].t; ysize = state->texCoords[2].t-ysize0; setSize( gridX, gridY ); alreadyInit = 1; } for (int i=0; i<(gridX-1) ; i++) { glBegin(m_drawType); for (int j = 0; j < gridY ; j++) { glTexCoord2fv( texCoords[i][j] ); glVertex3f( m_size * (i*sizeX - 1), m_size * (j*sizeY
-1) , 0);
glTexCoord2fv( texCoords[i+1][j] ); glVertex3f( m_size * ((i+1)*sizeX - 1), m_size *
(j*sizeY -1), 0); } glEnd(); } }else { if (!alreadyInit) { xsize = 1; ysize = 1; ysize0= 0; xsize0= 0;
setSize( gridX, gridY); alreadyInit = 1; } for ( i = 0; i<(gridX -1); i++) { glBegin(m_drawType); for ( j = 0; j < gridY ; j++) { glTexCoord2fv( texCoords[i][j] ); glVertex3f( m_size * (i*sizeX -1), m_size * (j*sizeY
-1), 0 );
glTexCoord2fv( texCoords[i+1][j] ); glVertex3f( m_size * ((i+1)*sizeX -1), m_size *
(j*sizeY -1), 0 ); } glEnd(); } }
if (m_blend) { glDisable(GL_POLYGON_SMOOTH); glDisable(GL_BLEND); } }
///////////////////////////////////////////////////////// // static member function // ///////////////////////////////////////////////////////// void mesh_square :: obj_setupCallback(t_class *classPtr) { class_addmethod(classPtr, (t_method)&mesh_square::blendMessCallback, gensym("blend"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&mesh_square::gridMessCallback, gensym("grid"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&mesh_square::gridXMessCallback, gensym("gridX"), A_FLOAT, A_NULL); class_addmethod(classPtr, (t_method)&mesh_square::gridYMessCallback, gensym("gridY"), A_FLOAT, A_NULL); }
void mesh_square :: blendMessCallback(void *data, t_floatarg blend) { GetMyClass(data)->m_blend=((int)blend); }
void mesh_square :: gridMessCallback(void *data, t_floatarg grid) { GetMyClass(data)->gridX=(int)grid; GetMyClass(data)->gridY=(int)grid; }
void mesh_square :: gridXMessCallback(void *data, t_floatarg grid) { GetMyClass(data)->gridX=(int)grid; }
void mesh_square :: gridYMessCallback(void *data, t_floatarg grid) { GetMyClass(data)->gridY=(int)grid; }
<mesh_square-help.pd>_______________________________________________ GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev