![]()  | 
	
| 
	 | 
| 
		 
			 
			#1  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
				
				Applying mask using Stencil Function
			 
			
			
			Hello Friends! 
		
		
		
		
		
		
		
		
	
	I am using Stencil Function to apply and remove the masked portion of an object. before applying the mask my objects are looking like this: ![]() The front object is logo2, the back object is logo1 & in between object is named masked & it'll be used for masking. Simple code for viewing this in your vizard is: Code: 
	import viz
viz.go()
piazza = viz.addChild('piazza.osgb')
logo1 = viz.addChild('logo.ive')
logo1.setPosition(0.3,1,5)
logo2 = viz.addChild('logo.ive')
logo2.setPosition(-0.3,1,3)
mask = viz.addChild('logo.ive')
mask.setPosition(0,1,4)
Code: 
	import viz
viz.setOption('viz.display.stencil',1)
viz.go()
#Clear stencil buffer every frame
viz.MainWindow.setClearMask(viz.GL_STENCIL_BUFFER_BIT,viz.MASK_ADD)
piazza = viz.addChild('piazza.osgb')
logo1 = viz.addChild('logo.ive')
logo1.setPosition(0.3,1,5)
logo2 = viz.addChild('logo.ive')
logo2.setPosition(-0.3,1,3)
mask = viz.addChild('logo.ive')
mask.setPosition(0,1,4)
mask.stencilFunc(viz.StencilFunc.RenderMask())
mask.disable([viz.COLOR_WRITE,viz.DEPTH_WRITE])
mask.enable(viz.CULL_FACE)
mask.drawOrder(-1)
logo1.stencilFunc(viz.StencilFunc.RenderOutsideMask())
logo1.clipPlane([0,0,1,-2])
logo2.stencilFunc(viz.StencilFunc.RenderOutsideMask())
logo2.clipPlane([0,0,1,-2])
![]() Now here you'll notice that both the front and back objects are affected by mask. What we want is only back object should get affected and not the front one. But the function will be applied on both the objects as they keep on rotating in our application so many times the front object will go back side of the mask and that time the mask has to clip that object. Wondering if there is any function viz.StencilFunc.RenderBacksideMask() or viz.StencilFunc.RenderBehindMask()! Can you please suggest me where am I going wrong? Is there any way to do this by using shaders?  | 
| 
		 
			 
			#2  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			No need to use stencil function. We just have to use mask.disable(viz.COLOR_WRITE) this command will not display the object but it'll still write to depth. So the object behind this invisible object will get affected. Don't forget to set mask.drawOrder(-1).  
		
		
		
		
		
		
		
		
	
	Code: Code: 
	import viz
viz.setOption('viz.display.stencil',1)
viz.go()
piazza = viz.addChild('piazza.osgb')
logo1 = viz.addChild('logo.ive')
logo1.setPosition(0.3,1,5)
logo2 = viz.addChild('logo.ive')
logo2.setPosition(-0.3,1,3)
mask = viz.addChild('logo.ive')
mask.setPosition(0,1,4)
mask.disable(viz.COLOR_WRITE)
mask.drawOrder(-1)
![]() Now don't worry about the black mask. if you set the environment scene i.e. piazza draw order lower than mask draw order then piazza will get rendered before mask. add this line to the previous code Code: 
	piazza.drawOrder(-2)  
		 | 
![]()  | 
	
	
| Tags | 
| clipping, hiding, mask, stencil | 
| Thread Tools | |
| Display Modes | Rate This Thread | 
		
  | 
	
		
  | 
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| return variable from keypress function | starbug | Vizard | 2 | 01-07-2010 12:14 PM | 
| Documentating function names | aaThomas | Vizard | 5 | 05-15-2007 10:50 AM | 
| Do you know how to send a value for 'pool' to the onActionEnd function? | ghazanfar | Vizard | 1 | 03-22-2007 11:25 AM | 
| timers and director function | Jerry | Vizard | 1 | 06-22-2006 10:47 AM |