I am using vizard 4 to interface with the oculus rift and am having problems using multiple post-process effects. When the main window is linked to the oculus, turning on a second post-process effect causes the effect to be applied to a new window. This is not a problem when the oculus is not linked to the screen.
Code:
from viz import *
import viz
import vizact
import oculus
import vizfx.postprocess
from vizfx.postprocess.color import BrightnessEffect
from vizfx.postprocess.composite import BlendMaskEffect
from vizfx.postprocess.color import SaturationEffect
from vizfx.postprocess.effect import BaseShaderEffect
ground = viz.addChild('piazza.osgb')
#set up oculus rift
hmd = oculus.Rift()
sensor = hmd.getSensor()
viz.link(hmd.getSensor(), viz.MainView)
vizact.onkeydown('r',sensor.reset)
viz.setMultiSample(8)
viz.go(viz.FULLSCREEN)
#fog
viz.fog(0.1)
viz.fogcolor(0.15,.20,.28)
#water postprocess effect
class UnderwaterEffect(BaseShaderEffect):
def __init__(self, speed=1.9, scale=1.5, density=30.0, **kw):
self._speed = speed
self._scale = scale
self._density = density
BaseShaderEffect.__init__(self,**kw)
def _getFragmentCode(self):
return """
uniform sampler2D vizpp_InputTex;
uniform float osg_FrameTime;
uniform float speed;
uniform float scale;
uniform float density;
void main()
{
vec2 uv = gl_TexCoord[0].xy;
//bumpUV.y = fract(bumpUV.y - osg_FrameTime*0.1);
vec2 dt;
dt.x = sin(speed*osg_FrameTime+uv.y*density)*0.001*scale;
dt.y = cos(0.7+0.7*speed*osg_FrameTime+uv.x*density)*0.001*scale;
gl_FragColor = texture2D(vizpp_InputTex,uv+dt);
}
"""
def _createUniforms(self):
self.uniforms.addFloat('speed',self._speed)
self.uniforms.addFloat('scale',self._scale)
self.uniforms.addFloat('density',self._density)
def setSpeed(self,speed):
self._speed = speed
self.uniforms.setValue('speed',speed)
def getSpeed(self):
return self._speed
def setScale(self,scale):
self._scale = scale
self.uniforms.setValue('scale',scale)
def getScale(self):
return self._scale
def setDensity(self,density):
self._density = density
self.uniforms.setValue('density',density)
def getDensity(self):
return self._density
uweffect = UnderwaterEffect()
vizfx.postprocess.addEffect(uweffect)
flash = BrightnessEffect(brightness = .8)
urmask = viz.addTexture('urblendmask.jpg')
ulmask = viz.addTexture('ulblendmask.jpg')
drmask = viz.addTexture('drblendmask.jpg')
dlmask = viz.addTexture('dlblendmask.jpg')
stimeffects = []
ulstimeffect = BlendMaskEffect(ulmask,black=flash)
vizfx.postprocess.addEffect(ulstimeffect,window=viz.MainWindow)
ulstimeffect.setEnabled(viz.OFF)
stimeffects.append(ulstimeffect)
urstimeffect = BlendMaskEffect(urmask,black=flash)
vizfx.postprocess.addEffect(urstimeffect,window=viz.MainWindow)
urstimeffect.setEnabled(viz.OFF)
stimeffects.append(urstimeffect)
dlstimeffect = BlendMaskEffect(dlmask,black=flash)
vizfx.postprocess.addEffect(dlstimeffect,window=viz.MainWindow)
dlstimeffect.setEnabled(viz.OFF)
stimeffects.append(dlstimeffect)
drstimeffect = BlendMaskEffect(drmask,black=flash)
vizfx.postprocess.addEffect(drstimeffect,window=viz.MainWindow)
drstimeffect.setEnabled(viz.OFF)
stimeffects.append(drstimeffect)
vizact.onkeydown('1',ulstimeffect.setEnabled,viz.TOGGLE)
vizact.onkeydown('2',urstimeffect.setEnabled,viz.TOGGLE)
vizact.onkeydown('3',dlstimeffect.setEnabled,viz.TOGGLE)
vizact.onkeydown('4',drstimeffect.setEnabled,viz.TOGGLE)
vizact.onkeydown( '#', viz.window.screenCapture, 'image.bmp' )
Specifying the window does not appear to solve the problem, though I may be doing this incorrectly.
Is there a different way of interfacing with the oculus in vizard 4 (i.e. not using vizconnect) that will allow multiple post-process effects to be used at once?
If not, is there a way of creating a composite effect that could include both of these effects at once and allow me to update it and turn one of them off and on?