WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-01-2015, 03:37 PM
lklab lklab is offline
Member
 
Join Date: Mar 2015
Posts: 20
Multiple post-process effects with oculus rift

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?
Reply With Quote
  #2  
Old 03-10-2015, 09:20 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Post process effects should work with the oculus. It would be helpful if you could simplify the code down to the most basic reproducible test case.
Reply With Quote
  #3  
Old 03-13-2015, 02:48 PM
lklab lklab is offline
Member
 
Join Date: Mar 2015
Posts: 20
The problem with using multiple post process effects is solved somewhat. It's possible to use the blend effect to use two post-process effects at once with the oculus and to turn off and turn on effects simultaneously to make it appear as if an additional effect is turning on.

The problem I have now is that the blendmask effect does not cause the mask to appear in the same place in each eye for the oculus. Is there a way of doing this that does not involve using the HorizontalSplit effect and doing trial and error with slightly shifted masks until they lineup?


Code:
from viz import *
import viz
import oculus
import vizfx.postprocess 
from vizfx.postprocess.color import BrightnessEffect
from vizfx.postprocess.composite import BlendMaskEffect

ground = viz.addChild('piazza.osgb')
#set up oculus rift
hmd = oculus.Rift()
sensor = hmd.getSensor()
viz.link(hmd.getSensor(), viz.MainView) 
viz.setMultiSample(8)
viz.go(viz.FULLSCREEN)

flash = BrightnessEffect(brightness = .8)
dlmask = viz.addTexture('dlblendmask.jpg')
dlstimeffect = BlendMaskEffect(dlmask,black=flash)
vizfx.postprocess.addEffect(dlstimeffect)
Reply With Quote
Reply

Tags
oculus, post-process, vizard 4, vizfx, window


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Oculus Rift Drift teklab Vizard 20 04-01-2016 08:57 AM
Oculus Rift and 360 Panorama with Vizard Lite Edition mshukun Vizard 4 11-10-2015 12:17 PM
Oculus Rift connection problem mshukun Vizard 1 10-01-2014 01:15 PM
Oculus Rift Fullscreen teklab Vizard 6 05-21-2014 07:11 AM
oculus rift and inertia cube interaction problems apboone Vizard 4 03-13-2014 11:45 AM


All times are GMT -7. The time now is 10:26 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC