Hi Tim,
I appreciate the comments. Up to this point I do not yet know what a shader does for a
living... except that I presumed it "shaded" surfaces somehow.
So... that will be my first step... I wouldn't have known that they were involved in
"cutting" (culling) unwanted sections of objects, except that I also presume
that while navigating over the vertices of an object, one could force their wishes upon
that object while traversing a plane within it.
You'll undoubtedly come across more accurate and complete descriptions,
but to get you started, here is my way of explaining it.
Shaders are essentially small programs that get run by the GPU once per
(different types of items the GPU processes). So for starters there are
vertex shaders (executed once per vertex) and fragment shaders (executed
once per fragment).
BTW, that last one is called pixel shader in D3D land, but in OpenGL we
call it by the more accurate name fragment shader. A fragment is a pixel
that has passed the z buffer test, and so is sure to be written to the
framebuffer.
There are other types now (geometry and tessellation shaders) but the
most used are vertex and fragment shaders. GPUs started as a big,
unprogrammable stack of state variables that controlled a fixed
pipeline. Now more and more stages of the GPU's pipeline are becoming
programmable, and the means to program them is to write shaders.
Is a shader the right place to do this kind of job?
Are there other places/techniques?
Shaders were the easiest place I could think of. I could have derived
from osgOcean's geometry class (MipmapGeometry I think) and modified the
actual geometry in OSG each frame to cut the shape of the boat's hull in
the ocean surface, or just flatten the waves' geometry in the area
occupied by the hull. That actually might be the best way of getting the
exact shape of the hull, because when doing things on the GPU you're a
bit limited in what you can do, but on the CPU the only limit would be
the amount of time you're willing to spend per frame to do the cutting.
And... I'm sure you or others might suggest the ultimate shading tutorial...
Ahh... I see there is an osgShaders example... perhaps I will find clues to
misusing them there.
Jason already sent you the link to lighthouse3d, I also used that one
when I was learning. It will show you the basics of writing lighting and
texturing shaders, but from there you have to use your imagination to
see what else you can do with them.
For instance, when you get to the "Statements and Functions" page
(http://www.lighthouse3d.com/opengl/glsl/index.php?statements) , you'll
see a quick description of the "discard" keyword. This is what I used in
my ocean surface fragment shader to cut the ocean surface. Essentially,
what I had was four uniform vec3 variables defining the corners of the
rectangle I wanted to cut, and I did a simple point-in-rectangle test to
see if the current fragment was inside that rectangle (making sure to
use world space coordinates for both the rectangle corners and the
fragment's position), and if it was I discarded it.
Hope this helps,
J-S
--
______________________________________________________
Jean-Sebastien Guay [email protected]
http://www.cm-labs.com/
http://whitestar02.dyndns-web.com/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org