PDA

View Full Version : linear transform in 2D screen space


stefs
10-09-2009, 06:36 AM
I intend to do some linear transform in 2D window (screen) space in order to do on-the-fly h-/v-keystone correction. I have all the code ready to calculate the linear distortion matrix from four registered corner points of the projection image. At the moment I choose this approach:

current_pm = viz.MainWindow.getProjectionMatrix()
current_pm.postMult(distortion_matrix)
viz.MainWindow.setProjectionMatrix(current_pm)

Where distortion_matrix is a 4x4 matrix that leaves the z untouched. The distortion in 2D space works fine but I still get some strange clipping artifacts.

My question: Is there a more elegant way in Vizard to implement this final viewport distortion as a 2D transform only rather than as a distortion of the 3D projection matrix?

farshizzo
10-09-2009, 10:15 AM
You can use a post-process shader to perform your keystone correction. A shader may be overkill for a simple linear transformation, but it allows for more flexibility for distortion correction. The vizlens module that comes with Vizard uses a post-process shader to perform the lens correction. Here is a simple example of a post-process shader:import viz
import vizpp
viz.go()

KeystoneShader = """
uniform sampler2D vizpp_InputTex;
uniform float osg_FrameTime;
void main (void)
{
float s = gl_TexCoord[0].s + (gl_TexCoord[0].t * sin(osg_FrameTime) * 0.3);
float t = gl_TexCoord[0].t;
gl_FragColor = texture2D( vizpp_InputTex, vec2(s,t) );
}
"""
vizpp.addEffect( vizpp.ShaderEffect(frag=KeystoneShader) )

viz.add('gallery.ive')