Basic shader manager and vertex batch
There are many things to learn and do. In order to render the curvature tensor, which is property of mesh, i need to add shader step-up and organize the vertices from curvatures into vbo (OpenGL 3.x is used).
However, there is already shader step-up and vbo using in the scene::render(), i don’t want to duplicate the code in the class Model. So, shader manager and vertex batch classes are need.
After googling, i come across to http://www.informit.com/articles/article.aspx?p=1616796&seqNum=4, the free chapters of OpenGL SuperBible 5th, and the greatest thing is its code is stored in google code project, from where i can download it. Must read!
Another resource is http://prideout.net/blog/?p=22 (anti-aliased cel shading, and shader wrapper).
Expected result:
1. Refactor the shader loading, create the batch class, render the scene(world frame, grid, mesh) using this new one.
2. render the curvature tonsor.
3. integrate the anti-aliased cel shading.
Notes:
1. there are two ways to get the vertex attribute location(index). The explicit way, use the
glBindAttribLocation(uint program, int index, char *name);
The inexplicit way, use the
int index = glGetAttribLocation( uint program, const char *name );
the index will be used later by puting vertex data into it.
2. To render the model, there is only mesh data at the current time, which is a polygon/n-sided mesh, using GL_TRIANGLES, a triangle mesh is created. The triangle mesh is used exclusively on rendering, but the mesh adjacency information is not used so data is wasted to record that. After integrate the GLBatch from GLTools of OpenGL SuperBible 5th, I wonder how about remove the triangle mesh, put the triangle data of the polygon mesh into the a instance of class GLBatch.
After further investigation, it is found that there is no index buffer object in the class GLBatch, for example if a quad is needed to be drew, six vertices are needed, and the
glDrawArray(GL_TRIANGLES, 0, 6);
is used. There are two vertices are duplicated. The GLBatch cannot be used directly.
But the triangle mesh is still needed to be removed. I want to create a vertex batch for all the vertices data, and create two index buffer object, one for regularly drawing triangle(GL_TRIANGLES) and one for drawing polygon wireframe(GL_LINES).
2010/8/17
Curvature tonsor
The principal curvature directions (red line for KMax, green line for KMin) are renderred using the the flat shader of the stock shaders in GLTools/GLShadermanager.h/cpp.
To build up the 3*3 tensor matrix (used by the Normal Cycle approximation algorithm), need to loop and search a neighborhood region of a start vertex.
push the start vertex into a stack (why use stack);
while stack is not empty
v = pop up the top vertex;
loop the one-ring neighbor of v;
if the neighbor meets the qualify, operate on it and push it into stack.
This search algorithm remind me of the Dijkstra’s algo.
To improve the curvature quality, some smoothing steps are need.
Triangle is evil?
Doing with mesh, i always asking why the quad mesh is used so often and i saw most of the model created by so-called artist are quad mesh, not triangle mesh, not even the n-sided mesh.
Maybe, this is one of the reason.
(a). Two quad faces share one edge, it is easy to set these two faces are symmetric.
(b). Tessellate those two faces in (a) into triangles, what happen the red triangles are set to symmetric? It’s wrong i guess, the topology are not symmetric, though the vertices are symmetric.
(c). even worse.
Thinking about managing ImageFilter/MeshBrush
In the plugin “Image Filter Tool”, there are some image filters can be applied to the image. There is a base class ImageFilter, i can write derive class of it in another plugin(dll) to define new image filter. My question is after the new image filter type is defined, how to add it into the main application, and create ui(for example button, or combo item) for it?
The function registerImageFilters(...) can be put into a ImageFilterFactory class as a static member functon:
typedef (ImageFilter *)(FuntionPointer)();
void ImageFilterFactor::registerImageFilter(string name, FuntionPointer funcPointer);
Can it be better?
(1). do not create the instance until the filter is selected.
(2). do not use the callback function to create the instance in plugin, but use running time type info(rtti) to create a instance in the main application. Declare a new image filter like this:
class ImageFilter : public XObject {
X_OBJECT
...
};
in plugin:
class XImageFilter: public ImageFilter {
X_OBJECT
...
};
Something looks like the object system in Qt :-) then the XImageFilter type is added into the object system, later we can check whether we have a type named “XImageFilter” in the object system, if yes, we use:
ClassInfo * findClassInfo(“XImageFilter”);
ImageFilter *pIF = pCI->createInstance();
Recommended book: Design of Design http://www.informit.com/store/product.aspx?isbn=0201362988 sample chapters are on the right hand side.
(some one said “Run, you run” can be translated into 跑啊, 你丫快跑啊:-)
There are many things to learn and do. In order to render the curvature tensor, which is property of mesh, i need to add shader step-up and organize the vertices from curvatures into vbo (OpenGL 3.x is used).
However, there is already shader step-up and vbo using in the scene::render(), i don’t want to duplicate the code in the class Model. So, shader manager and vertex batch classes are need.
After googling, i come across to http://www.informit.com/articles/article.aspx?p=1616796&seqNum=4, the free chapters of OpenGL SuperBible 5th, and the greatest thing is its code is stored in google code project, from where i can download it. Must read!
Another resource is http://prideout.net/blog/?p=22 (anti-aliased cel shading, and shader wrapper).
Expected result:
1. Refactor the shader loading, create the batch class, render the scene(world frame, grid, mesh) using this new one.
2. render the curvature tonsor.
3. integrate the anti-aliased cel shading.
Notes:
1. there are two ways to get the vertex attribute location(index). The explicit way, use the
glBindAttribLocation(uint program, int index, char *name);
The inexplicit way, use the
int index = glGetAttribLocation( uint program, const char *name );
the index will be used later by puting vertex data into it.
2. To render the model, there is only mesh data at the current time, which is a polygon/n-sided mesh, using GL_TRIANGLES, a triangle mesh is created. The triangle mesh is used exclusively on rendering, but the mesh adjacency information is not used so data is wasted to record that. After integrate the GLBatch from GLTools of OpenGL SuperBible 5th, I wonder how about remove the triangle mesh, put the triangle data of the polygon mesh into the a instance of class GLBatch.
After further investigation, it is found that there is no index buffer object in the class GLBatch, for example if a quad is needed to be drew, six vertices are needed, and the
glDrawArray(GL_TRIANGLES, 0, 6);
is used. There are two vertices are duplicated. The GLBatch cannot be used directly.
But the triangle mesh is still needed to be removed. I want to create a vertex batch for all the vertices data, and create two index buffer object, one for regularly drawing triangle(GL_TRIANGLES) and one for drawing polygon wireframe(GL_LINES).
2010/8/17
Curvature tonsor
The principal curvature directions (red line for KMax, green line for KMin) are renderred using the the flat shader of the stock shaders in GLTools/GLShadermanager.h/cpp.
To build up the 3*3 tensor matrix (used by the Normal Cycle approximation algorithm), need to loop and search a neighborhood region of a start vertex.
push the start vertex into a stack (why use stack);
while stack is not empty
v = pop up the top vertex;
loop the one-ring neighbor of v;
if the neighbor meets the qualify, operate on it and push it into stack.
This search algorithm remind me of the Dijkstra’s algo.
To improve the curvature quality, some smoothing steps are need.
Triangle is evil?
Doing with mesh, i always asking why the quad mesh is used so often and i saw most of the model created by so-called artist are quad mesh, not triangle mesh, not even the n-sided mesh.
Maybe, this is one of the reason.
(a). Two quad faces share one edge, it is easy to set these two faces are symmetric.
(b). Tessellate those two faces in (a) into triangles, what happen the red triangles are set to symmetric? It’s wrong i guess, the topology are not symmetric, though the vertices are symmetric.
(c). even worse.
Thinking about managing ImageFilter/MeshBrush
In the plugin “Image Filter Tool”, there are some image filters can be applied to the image. There is a base class ImageFilter, i can write derive class of it in another plugin(dll) to define new image filter. My question is after the new image filter type is defined, how to add it into the main application, and create ui(for example button, or combo item) for it?
The function registerImageFilters(...) can be put into a ImageFilterFactory class as a static member functon:
typedef (ImageFilter *)(FuntionPointer)();
void ImageFilterFactor::registerImageFilter(string name, FuntionPointer funcPointer);
Can it be better?
(1). do not create the instance until the filter is selected.
(2). do not use the callback function to create the instance in plugin, but use running time type info(rtti) to create a instance in the main application. Declare a new image filter like this:
class ImageFilter : public XObject {
X_OBJECT
...
};
in plugin:
class XImageFilter: public ImageFilter {
X_OBJECT
...
};
Something looks like the object system in Qt :-) then the XImageFilter type is added into the object system, later we can check whether we have a type named “XImageFilter” in the object system, if yes, we use:
ClassInfo * findClassInfo(“XImageFilter”);
ImageFilter *pIF = pCI->createInstance();
Recommended book: Design of Design http://www.informit.com/store/product.aspx?isbn=0201362988 sample chapters are on the right hand side.
(some one said “Run, you run” can be translated into 跑啊, 你丫快跑啊:-)
when i was thinking about the ImageFilters example, the concern is when the filter instance is created?
回复删除(1). when the plugin is loaded by the main application, before/on/after register this plugin, a filter instance of this new type can be added.
(2). after plugins loading, create the ui for the image filters, instances can be created at this time, too.
(3). not created untill user choose/click this filter to use.