View Single Post
  #3  
Old 04-10-2008, 05:33 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
I've tried the node.alpha command, but it doesn't work with my mirrorsurface. The texquad becomes transparent, but the reflection texture doesn't. So it tried tex.alpha(0.5) but that didn't work. Is there any way I can modify the mirrorsurface in the code below so that it reflects and is transparent? How would the static reflection texture work?
Code:
import viz

viz.go()

import viz
viz.go()

def addMirror(mirror,mat=None):

	#If mirror matrix is not specifed, get matrix of mirror object
	if mat is None:
		mat = mirror.getMatrix()
		
	#Position of mirror
	pos = viz.Vector(mat.getPosition())
	
	#Direction mirror is pointing
	dir = viz.Vector(mat.getForward())
	dir.normalize()

	#Quaternion rotation of mirror
	quat = mat.getQuat()
	
	#Create render texture
	tex = viz.addRenderTexture()
	
	#Create render node for rendering reflection
	lens = viz.addRenderNode(size=[1024,1024])
	lens.attachTexture(tex)
	lens.setInheritView(True,viz.POST_MULT)
	lens.disable(viz.CULL_FACE,op=viz.OP_SET_OVERRIDE)
	
	#Setup reflection matrix
	rot = viz.Matrix.quat(quat)
	invRot = rot.inverse()
	lens.setMatrix(viz.Matrix.translate(pos*-1.0)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos))
	
	#Setup reflection clip plane
	plane = vizmat.Plane(pos=pos,normal=dir)
	dist = plane.distance([0,0,0])
	lens.clipPlane([-dir[0],-dir[1],-dir[2],dist+0.001])
	
	#Project reflection texture onto mirror
	mirror.texture(tex)
	mirror.texGen(viz.TEXGEN_PROJECT_EYE)
	
	
#Add gallery environment
gallery = viz.add('gallery.ive')

#Use existing painting as mirror and specify the matrix
mirrorsurface = viz.addTexQuad()
mirrorsurface.alpha(.5)
mirrorsurface.setPosition([0, 1, 2]) #Y,Z,X
mirrorsurfacerotation = [0,0,0] #rotation around the Z,Y,X axes
mirrorsurface.rotate(mirrorsurfacerotation) 
m = viz.Matrix()
m.setPosition(mirrorsurface.getPosition(viz.ABS_GLOBAL))
m.setEuler(mirrorsurfacerotation[0]-180,-mirrorsurfacerotation[1], mirrorsurfacerotation[2]) #Z,X,Y

#Apply mirror settings to mirror object
addMirror(mirrorsurface,m)

#Increase ambient lighting
viz.MainView.getHeadLight().ambient(1,1,1)

Last edited by Frank Verberne; 04-10-2008 at 05:38 AM.
Reply With Quote