Panajev2001a
Veteran
Hello everyone !
I have been working at a small tech demo (I am iterating on it, adding techniques as I learn them, as a way to learn the ropes of OpenGL ES programming on iDevices for an iPad application I am working on).
Due to its quite good pipeline, I did choose to start from the SIO2 engine, but the work I am doing now extends a bit beyond that whole staying within the bounds of OpenGL ES 1.1 which is what SIO2 targets.
Since I am working on something that is going to be run on SGX based devices (I am targeting the iPad mainly), I can go a bit beyond what the engine provides as the SIO2 engine is designed for maximum compatibility with MBX based iDevices (no stencil buffer, only 2 TU's, etc...). One thing that is gained from all of this is that code that works on playing around with the texture matrix does not need to worry about correct perspective corrected texturing/coordinates interpolation at the pixel level (which is a problem with the PowerVR MBX).
The two problems am having now (with this multi-pass implementation that follows the basic rendering loop outlined here: http://titan.cs.ukzn.ac.za/opengl/opengl-d6/adv-course/notes/node100.html) are:
1.) a false positive with the backprojection fix code (standard clipper texture approach: Plane's equation in the first row of the texture matrix used to sample the clipper texture, leaving the second and third row of the matrix empty, and only the fourth column of the fourth row set to 1.0f... white texture with black texel at (s,t) = (0,0)...)... some portions of the scene do not receive the projected texture because the pixel in question is flagged as sitting behind the projector's plane.
2.) the spotlight is not brightening the shadowed areas correctly... you can see that they do get a little bit brighter, but not enough. The planar shadows are rendered last (using stencil to first delimit the area they are cast upon and then to mark where they fall... changing the stencil test to recognize the shadowed areas, I re-render the shadow receiving plane with the blocked light turned off) and blended on top of the result of the previous passes.
Do you have any suggestions (beside "use multi-texturing you fool!") concerning those two issues?
You can see them in action here: http://www.youtube.com/watch?v=tGC6y_zT4MA
This is my rendering loop basically:
http://code.google.com/p/si02-r-n-d..._iPhone_iPad_Application/Classes/Projector.mm (it contains the texture projection code, texture matrices included)
http://code.google.com/p/si02-r-n-d...C_iPhone_iPad_Application/Classes/EAGLView.mm (various math functions and general OpenGL ES glue code...)
P.S.: http://forum.sio2interactive.com/viewtopic.php?f=3&t=841&start=10#p4338 (some more blabbering about the techniques used in this demo)
http://forum.sio2interactive.com/viewtopic.php?f=3&t=841#p4296 (more blabbering about texture projection)
http://forum.sio2interactive.com/viewtopic.php?f=3&t=841#p4300 (even more blabbering about planar shadows and the use of the stencil buffer to fix that technique's shortcomings)
I have been working at a small tech demo (I am iterating on it, adding techniques as I learn them, as a way to learn the ropes of OpenGL ES programming on iDevices for an iPad application I am working on).
Due to its quite good pipeline, I did choose to start from the SIO2 engine, but the work I am doing now extends a bit beyond that whole staying within the bounds of OpenGL ES 1.1 which is what SIO2 targets.
Since I am working on something that is going to be run on SGX based devices (I am targeting the iPad mainly), I can go a bit beyond what the engine provides as the SIO2 engine is designed for maximum compatibility with MBX based iDevices (no stencil buffer, only 2 TU's, etc...). One thing that is gained from all of this is that code that works on playing around with the texture matrix does not need to worry about correct perspective corrected texturing/coordinates interpolation at the pixel level (which is a problem with the PowerVR MBX).
The two problems am having now (with this multi-pass implementation that follows the basic rendering loop outlined here: http://titan.cs.ukzn.ac.za/opengl/opengl-d6/adv-course/notes/node100.html) are:
1.) a false positive with the backprojection fix code (standard clipper texture approach: Plane's equation in the first row of the texture matrix used to sample the clipper texture, leaving the second and third row of the matrix empty, and only the fourth column of the fourth row set to 1.0f... white texture with black texel at (s,t) = (0,0)...)... some portions of the scene do not receive the projected texture because the pixel in question is flagged as sitting behind the projector's plane.
2.) the spotlight is not brightening the shadowed areas correctly... you can see that they do get a little bit brighter, but not enough. The planar shadows are rendered last (using stencil to first delimit the area they are cast upon and then to mark where they fall... changing the stencil test to recognize the shadowed areas, I re-render the shadow receiving plane with the blocked light turned off) and blended on top of the result of the previous passes.
Do you have any suggestions (beside "use multi-texturing you fool!") concerning those two issues?
You can see them in action here: http://www.youtube.com/watch?v=tGC6y_zT4MA
This is my rendering loop basically:
Code:
void templateRender( void )
{
const GLfloat light0Ambient[] = {0.08, 0.08, 0.08, 1.0};
//// Basic rendering loop setup at the beginning of the current frame
{
glStencilMask(0xFF);
glLightfv(GL_LIGHT0, GL_AMBIENT, light0Ambient);
glClearColor(light0Ambient[0], light0Ambient[1], light0Ambient[2], 1);
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
}
////
MATRIX mView;
[[EAGLView sharedGLView]matLookAt:&mView eye:sio2->_SIO2camera->_SIO2transform->loc
vDir:sio2->_SIO2camera->_SIO2transform->dir upVector:(vec3*)&upWorld];
/*Initialize the depth buffer.
Clear the color buffer to a constant value which represents the scene ambient illumination.
Draw the scene with depth buffering enabled and color buffer writes disabled.
Load and enable the spotlight texture, set the texture environment to GL_MODULATE.
Enable the texgen functions, load the texture matrix.
Enable blending and set the blend function to GL_ONE, GL_ONE.
Disable depth buffer updates and set the depth function to GL_EQUAL.
Draw the scene with the vertex colors set to 1.0.
Disable the spotlight texture, texgen and texture transformation.
Set the blend function to GL_DST_COLOR.
Draw the scene with normal illumination.*/
glEnable(GL_BLEND);
if(INVERTED_ZRANGE) glDepthFunc(GL_GREATER);
else glDepthFunc(GL_LESS);
[[EAGLView sharedGLView]renderCameraModelViewMatrix:&mView enableLandscape:TRUE];
{
BOOL projEnable = projectorEnable;
//projEnable = NO;
if(projEnable){
glDisable(GL_LIGHTING);
DEPTH_WRITES_ON();
RGBA_WRITES_OFF();
[[EAGLView sharedGLView] renderAllObjects];
RGBA_WRITES_ON();
glBlendEquationOES( GL_FUNC_ADD_OES );
glBlendFunc( GL_ONE, GL_ONE );
[[[EAGLView sharedGLView]sceneProjector] calculateProjector];
glDepthFunc(GL_EQUAL);
[[[EAGLView sharedGLView]sceneProjector] rotateZ:0.48f];
[[[EAGLView sharedGLView]sceneProjector] submitProjectorGL];
glEnable(GL_LIGHTING);
//glEnable(GL_DEPTH_TEST);
}
DEPTH_WRITES_ON();
RGBA_WRITES_OFF();
[[EAGLView sharedGLView] renderAllObjects];
RGBA_WRITES_ON();
DEPTH_WRITES_OFF();
sio2LampEnableLight();
{
[[EAGLView sharedGLView]renderIPO];
[[EAGLView sharedGLView]renderLights];
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, light0Ambient);
glBlendEquationOES( GL_FUNC_ADD_OES );
glBlendFunc( GL_ONE, GL_SRC_COLOR );
if(INVERTED_ZRANGE) glDepthFunc(GL_GEQUAL);
else glDepthFunc(GL_LEQUAL);
[[EAGLView sharedGLView]renderShadowCasters];
for (int i = 0; i < 3; i++) {
[[EAGLView sharedGLView]renderShadowReceiverObject:shadowReceivers[i]];
}
renderPlanarShadows();
//STENCIL_ON();
//glEnable(GL_BLEND);
//[[[EAGLView sharedGLView]sceneProjector] submitProjectorGL];
//renderPlanarShadows();
STENCIL_OFF();
}
SIO2camera* projector = ( SIO2camera * )sio2ResourceGet( sio2->_SIO2resource,
SIO2_CAMERA,
(char*)"camera/Projector");
[[EAGLView sharedGLView]drawNormal:projector->_SIO2transform->dir ofPoint:projector->_SIO2transform->loc];
[[EAGLView sharedGLView]drawCameraFrustum:projector aspectRatio:1.0f];
SIO2_SOFT_RESET();
}
MODELVIEW_LANDSCAPE_OFF();
//templateRender2D();
[[EAGLView sharedGLView]setUpdateCameraModelViewMatrix:TRUE];
[SysTools checkGLerrors];
templateGameLoop();
}
http://code.google.com/p/si02-r-n-d..._iPhone_iPad_Application/Classes/Projector.mm (it contains the texture projection code, texture matrices included)
http://code.google.com/p/si02-r-n-d...C_iPhone_iPad_Application/Classes/EAGLView.mm (various math functions and general OpenGL ES glue code...)
P.S.: http://forum.sio2interactive.com/viewtopic.php?f=3&t=841&start=10#p4338 (some more blabbering about the techniques used in this demo)
http://forum.sio2interactive.com/viewtopic.php?f=3&t=841#p4296 (more blabbering about texture projection)
http://forum.sio2interactive.com/viewtopic.php?f=3&t=841#p4300 (even more blabbering about planar shadows and the use of the stencil buffer to fix that technique's shortcomings)
Last edited by a moderator: