WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-29-2008, 08:54 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I've attached a sample script that renders the scene in stereo to a texture and displays it onto a tessellated quad. You can implement the _distortTexCoord function to return distorted texture coordinates, right now it simply returns undistorted coordinates.
Code:
import viz
viz.go(viz.STEREO)

#Initialize environment
viz.clearcolor(viz.GRAY)
viz.add('gallery.ive')

#Hide scene so it is not rendered to frame buffer
viz.MainScene.visible(0,viz.WORLD)

#Distortion grid constants
GRID_WIDTH = 100
GRID_HEIGHT = 100
GRID_STEP = 5

def CreateLensDistortion(eye):
	
	#Create render texture
	tex = viz.addRenderTexture()

	#Determine size of window
	width,height = viz.window.getSize()
	width /= 2

	#Create node to render scene to a texture
	lens = viz.addRenderNode(size=[width,height])
	lens.attachTexture(tex)
	lens.disable(eye)
	
	#Create node to displayed rendered texture to screen
	overlay = viz.addRenderNode()
	overlay.setOrder(viz.POST_RENDER)
	overlay.setHUD(0,GRID_WIDTH,0,GRID_HEIGHT)
	overlay.disable(eye)
	overlay.disable(viz.LIGHTING)

	def _distortTexCoord(x,y):
		#TODO: Distort texture coordinates given (x,y) vertex coordinates
		return x / float(GRID_WIDTH) , y / float(GRID_HEIGHT)
	
	#Create quad with distorted texture coordinates to display render texture
	viz.startlayer(viz.QUADS)
	for i in range(0,GRID_WIDTH,GRID_STEP):
		for j in range(0,GRID_HEIGHT,GRID_STEP):
	
			viz.texcoord(_distortTexCoord(i,j))
			viz.vertex(i,j,0)
			
			viz.texcoord(_distortTexCoord(i+GRID_STEP,j))
			viz.vertex(i+GRID_STEP,j,0)
			
			viz.texcoord(_distortTexCoord(i+GRID_STEP,j+GRID_STEP))
			viz.vertex(i+GRID_STEP,j+GRID_STEP,0)
			
			viz.texcoord(_distortTexCoord(i,j+GRID_STEP))
			viz.vertex(i,j+GRID_STEP,0)
			
	quad = viz.endlayer(parent=overlay)
	quad.texture(tex)

#Create lens distortion for left/right eyes
CreateLensDistortion(viz.RENDER_LEFT)
CreateLensDistortion(viz.RENDER_RIGHT)
Reply With Quote
 

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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
8800 ultra stereo driver Dave Vizard 21 10-25-2009 11:25 AM
anaglyphic stereo, backprojection & screendistance malte Vizard 4 02-23-2008 07:48 AM
stereo projection issue asimbh Vizard 3 10-05-2007 11:22 AM
quad buffered stereo? halley Vizard 2 10-19-2005 01:28 PM
SeeReal stereo with separate scenes Jerry Vizard 2 10-18-2005 01:02 PM


All times are GMT -7. The time now is 12:33 AM.


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