>>> Anaglyph 6
>>> Texture shader - draw in color including textures in 1 step. As with
>>> the primitive color shader already implemented in freewrl, this
>>> shader program is run before rendering the scenegraph, so it
>>> replaces that part of the FFP (fixed function pipeline). GLSL Shader
>>> code...
>>
>>
>>> RESULTS:
>>> Not good. The problem is how to detect when no texture is applied so
>>> as to switch to color. Setting a flag is equivalent to going through
>>> scenegraph code to make changes, something I would rather avoid.
>>> When done on tests, it renders faster than the
>>
>>My GLSL books are at home (bedtime reading - sheesh) but, can you
>>query if GL_TEXTURE_2D is enabled or not? Maybe see which if any of
>>the texture units are enabled?
>>
>>BTW - I would like to propose methods of setting global shaders; not
>>just ones on a per-material basis, for X3D. I think it would be a good
>>thing to do. Any comments?
>>
>
> Hello,
>
> querying for GL_TEXTURE_2D during rendering is a performance kill. The
> scenegraph function should be able to tell whether this specific object
> being rendered has or does not has textures / shaders / materials
> enabled. Isn't it ?
>
> Doug: please feed us with example of your work : screen shots, X3D
> example files ;) ... it'd help to understand what you are trying to do.
Michel - I'm still on anaglyph, and I have a wish list for it:
1. don't go messing up scengraph code with if(anaglyph).. - keep it localized/isolated
2. don't require user to change their material colors or do extra work
3. real-time fast
I have an example .c program from elsewhere that I modified to test different anaglyph methods - I put it on my skydrive in the GPUGroupX3D directory anaglyph10.zip - just the source and you need glew,glut.
(My townside X3D photo tour is there too "placeholders" and is awaiting x3d proto routing/extern proto. It would be nice if a corp sponsor funded JAS for a few months to finish that.)
Global shaders might do the job, but you need to know when you have a texture.
If JAS puts in global shaders generally, then that would set up sufficient code structure/flags.
2Step see below is high quality and localized, but slowest (depends on size of viewport,>512 more tiles)
If you have any suggestions for anaglyph methods I can add them to the test program and compare.
-D
more...
Anaglyph - a type of stereovision where you draw the left and right in different colors - usually left red, right blue.
http://3dtv.at/Knowhow/AnaglyphComparison_en.aspx
Then you view with color filter eyewear to see stereo
http://www.berezin.com/3D/3dglasses.htm anaglyph eyeglasses all styles and colors, 10 for $5
http://www.rainbowsymphony.com/3d-anaglyph-glasses.html more anaglyph glasses case of 50 for $25
There are a few different ways to implement anaglyph in a realtime graphics program, in all cases the scenegraph is rendered twice (left and right eye viewpoints).
1. global color mask: change your materials and textures to shades of gray then mask the channels with glColorMask(1,0,0,1) for red channel, glColorMask(0,1,1,1) for cyan.
http://local.wasp.uwa.edu.au/~pbourke/texture_colour/anaglyph/ simple but you must draw grayscale
+ absolute fastest, and simplest for programmer
- must either control materials and textures in program -force to gray- or ask user to change materials to gray
pseudo code
glColorMask(1,0,0,1);
renderscenegraphLeft();
glColorMask(0,0,1,1);
renderscenegraphRight();
2. global color material shader - what I ** IMPLEMENTED ** in freewrl with --anaglyph RG
turn the shader on before rendering the scenegraph, use 2 shaders one for each color, or a uniform variable with some kind of mask or flag indicating the output channels.
Then in the shader there are 2 basic steps:
a) compute gray = .299*red + .587*green + .114*blue using so called NTSC weights
b) compute output color = (gray*maskr, gray*maskg, gray*maskb)
For red channel output color = (gray*1, gray*0, gray*0)
+ user can draw in color; software changes are localized in render(), no changes to scenegraph code
- textures don't render, because the global shader replaces the pipeline and there's nothing in the shader for textures:
const GLchar* shaderSrc = "\
uniform vec3 imask;\n\
void main(void)\n\
{\n\
float gray = dot(gl_Color.rgb, vec3(0.299, 0.587, 0.114));\n\
gl_FragColor = vec4(gray*imask.rgb, gl_Color.a);\n\
}\n\
";
glUseProgram(s);
glUniform3f(umask,1.0f,0.0f,0.0f);
renderscenegraphLeft();
glUniform3f(umask,0.0f,0.0f,1.0f);
renderscenegraphRight();
3. global color texture + material shader - same as above, except somehow detect when a texture is applied and if so use the texture color to compute gray.
+ can draw in color including textures
- must intrude on scenegraph code
const GLchar* shaderSrc = "\
uniform sampler2D tex;\n\
uniform int iflag;\n\ <<< ouch, have to set a flag from scenegraph code
uniform int itex;\n\
void main(void)\n\
{\n\
vec4 tcolor;\n\
float gray;\n\
if(itex == 0)\n\
tcolor = gl_Color;\n\
else\n\
tcolor = texture2D(tex,gl_TexCoord[0].st);\n\
gray = dot(tcolor.rgb,vec3(0.299, 0.587, 0.114));\n\
if(iflag> 0)\n\
gl_FragColor = vec4(gray,0.0,0.0,1.0);\n\
else\n\
gl_FragColor = vec4(0.0,0.0,gray,1.0);\n\
}\n\
";
4. 2 step - render normally to the backbuffer, then copy tilewise 512x512 to texture, and render texture mapped quad back to backbuf with a texture shader.
const GLchar* shaderSrc = "\
uniform sampler2D tex;\n\
uniform vec3 imask;\n\
void main()\n\
{\n\
vec4 tcolor = texture2D(tex,gl_TexCoord[0].st);\n\
float gray = dot(tcolor.rgb, vec3(0.299, 0.587, 0.114));\n\
gl_FragColor = vec4(gray*imask.rgb,1.0);\n\
}\n\
";
renderscenegraphLeft();
glClear(GL_DEPTH_BIT)
for( i = 1, num_512_tiles)
copyTexSubImage2D()
setCameraOrtho
glUseProgram(s)
glUniform3f(umask,1,0,0)
glRenderQuad()
glUseProgram(0)
renderscengraphRight()
...
+ highest quality, takes into account all rendering details - lighting, shadows
- slowest
5. imaging matrix - too slow to render
> BTW : the classical technique is to make a pass for objects with their
> specific characteristics and then make a pass for additional effects
> such as glooming, edges, etc ... I.e two global pass. If you want to
> draw only edges in the second pass you can setup OpenGL to fill only
> points & lines, not 2D primitives.
>
> But better performances & effects are achieved through proper use
> of global shaders added to each rendered object, I think (making all in
> one pass).
_________________________________________________________________
Send and receive email from all of your webmail accounts.
http://go.microsoft.com/?linkid=9671356
|