WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-14-2013, 05:18 PM
left_leg left_leg is offline
Member
 
Join Date: Jan 2013
Posts: 6
Question no fog in outer space - trouble getting viz.fog to work

hey guys,

I programmed a starfield environment as action class. since the field size is limited I wanted to use viz.fog to smoothly fade in distant stars while moving through the field. however, the no matter what I do the fog is not appearing in the starfield. checked stuff like color of the fog, different densities, linear or exponential fog and even added a lighting.

my alternative is using a modest gaussian blur postprocessing, but the fog would definitely be the better option...

here is my code, first the starfield action class and then a little demo:

Code:
import vizshape
import viz
import random
import viztask


class Starfield(viz.ActionClass):
	"""
	action class providing a starfield that can be used as optical flow stimulus
	"""
	
	def begin(self,object):
		"""
		constructor: places the stars randomly columns around a column
		center (black cube). columns are stored in a list
		
		"""
		self.data 	   = self._actiondata_.data
		self.nStars    = self.data[0]
		self.starSize  = self.data[1]
		self.colDimXYZ = self.data[2]
		self.nColsXYZ  = self.data[3]
		
		# internal parameters
		self.starsPerColumn = int(self.nStars / (self.nColsXYZ[0] * 
							  self.nColsXYZ[1] * self.nColsXYZ[2]))
		self.xDeltaMax = self.colDimXYZ[0] * self.nColsXYZ[0] / 2
		self.yDeltaMax = self.colDimXYZ[1] * self.nColsXYZ[1] / 2
		self.zDeltaMax = self.colDimXYZ[2] * self.nColsXYZ[2] / 2
		self.countStart = 0
		self.time = 0

		# create a master star
		protoStar = viz.addTexQuad(size = self.starSize)
		protoStar.setPosition([0,1,1])
		diff = viz.add('star.png')
		norm = viz.add('normal1.tif')
		protoStar.texture(diff,'',1)
		protoStar.bumpmap(norm,'',0)
		protoStar.billboard(mode=viz.BILLBOARD_VIEW)
		
		# list with all stars
		self.columns = []
		for idx_x in range(self.nColsXYZ[0]):
			for idx_y in range(self.nColsXYZ[1]):
				for idx_z in range(self.nColsXYZ[2]):
					# create center node as parent for all stars in that column
					columnCenter = vizshape.addCube(size = 0.001)
					columnCenter.color(viz.BLACK)
					columnCenter.setPosition([idx_x * self.colDimXYZ[0],
											  idx_y * self.colDimXYZ[1],
											  idx_z * self.colDimXYZ[2]])
					self.columns.append(columnCenter)
					# randomly create stars within the limits of one column
					for y in range(self.starsPerColumn):
						# positioning
						x = self.colDimXYZ[0] * (random.random() - 0.5)
						y = self.colDimXYZ[1] * (random.random() - 0.5)
						z = self.colDimXYZ[2] * (random.random() - 0.5)
						star = protoStar.clone(columnCenter)
						star.setPosition([x,y,z], mode = viz.ABS_PARENT)
						star.billboard(mode=viz.BILLBOARD_VIEW)
		
		protoStar.remove()



	def update(self,elapsed,object):
		"""
		checks every frame if a column center exceeded the volume
		if yes, it reenters the volume on the oppsite side (like in snake)
		"""

		# get position of the avatar (center of the field)
		[aX, aY, aZ] = object.getPosition(mode = viz.ABS_GLOBAL)
		# for every star: check if within limits of field, if not, reposition using respawn function
		for column in self.columns[self.countStart::4]:
			# get position of the star
			pos = column.getPosition(mode = viz.ABS_GLOBAL)
			# check every coordinate
			x = pos[0] if abs(pos[0] - aX) <= self.xDeltaMax else self.respawn(aX, pos[0], self.xDeltaMax)
			y = pos[1] if abs(pos[1] - aY) <= self.yDeltaMax else self.respawn(aY, pos[1], self.yDeltaMax)
			z = pos[2] if abs(pos[2] - aZ) <= self.zDeltaMax else self.respawn(aZ, pos[2], self.zDeltaMax)

			self.time = elapsed + self.time
			
			# eventually reposition
			column.setPosition([x,y,z], mode = viz.ABS_GLOBAL)
			
		self.countStart = (self.countStart + 1) % 4
		
		if self.time >= 200.00 and self.time <= 200.1:
			object.setPosition([0,0,0], viz.ABS_GLOBAL)
			
		
	def end(self,object):
		print 'starfield ended'		
		
		
	def respawn(self, cAvatar, cPoint, deltaMax):
		""" if point exceeded displayed field, this calculates the reentry coordinates """
		# transform into coordinate system with avatar as (0,0)
		delta  = cPoint - cAvatar
		# how far the point exceeded the limit
		rest   = abs(delta) % deltaMax
		# check on which side
		side   = -1 if cPoint < cAvatar else 1
		# calculate new coordinates in global sys after entering on the other side
		new    = cAvatar - side * (deltaMax - rest)
		return new


def addStarfield(nStars = 10000, starSize = 0.18, colDimXYZ = [5, 30, 5], nColsXYZ = [20, 1, 20], blur = True):
	"""
	creates a starfield around the object it is assigned to as action
	object is center and the cuboid has the edge lenghts dimX, dimY and dimZ
	every frame every star is checked if it exceeds the cuboid, if yes it reenters
	the cuboid on the other side (like playing good old snkae)
	"""	
	
	if blur:
		import vizfx.postprocess
		from vizfx.postprocess.blur import GaussianBlurEffect
		effect = GaussianBlurEffect(blurRadius = 10, blurScale = 0.001, downsample = 0.7)
		vizfx.postprocess.addEffect(effect)
		
	bla 			= viz.ActionData()
	bla.data 		= [nStars, starSize, colDimXYZ, nColsXYZ]
	bla.actionclass	= Starfield
	return bla
Code:
import iStarfield
import viz

# create an invisible avatar (needed to add the starfield action to it)
avatar = viz.add('wheelbarrow.ive')
avatar.visible(viz.OFF)

# add the main view to it
viz.link(viz.MainView, avatar)


# add starfield action to it's OWN ACTION POOL
avatar.addAction(iStarfield.addStarfield(nStars = 10000, starSize = 0.18, colDimXYZ = [5, 30, 5], 
										 nColsXYZ = [20, 1, 20], blur = False                     ), pool = 1)

viz.go()

# adding the fog
viz.fog(0.9)
viz.fogcolor(0.5,0.5,0.5)
Reply With Quote
  #2  
Old 01-15-2013, 04:38 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
What if you set the background color to the fog color, does that work the way you want?
Code:
viz.clearcolor(0.5,0.5,0.5)
Reply With Quote
  #3  
Old 01-16-2013, 02:40 PM
left_leg left_leg is offline
Member
 
Join Date: Jan 2013
Posts: 6
well, good news is that it does something, namely indeed adjusting the background colour. however I still get absolutely no fog, respawning stars just pop up instead of fading in.
Reply With Quote
  #4  
Old 01-17-2013, 11:58 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Can you attach both the textures you're using? I tested with just a diffuse texture on the star and it faded in and out.
Reply With Quote
  #5  
Old 01-17-2013, 03:32 PM
left_leg left_leg is offline
Member
 
Join Date: Jan 2013
Posts: 6
sure, here are the textures
Attached Files
File Type: zip normal1.zip (190.7 KB, 835 views)
Reply With Quote
  #6  
Old 01-23-2013, 03:51 PM
left_leg left_leg is offline
Member
 
Join Date: Jan 2013
Posts: 6
so I played around a little more and it turned out that when I leave out the bumpmap the fog works perfectly fine! no clue why a problem arises when the bumpmap is included, but it doesn't look to bad without it, so I'll just keep it that way. thank's for the help Jeff, your comment led me on the right way!
Reply With Quote
Reply

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


All times are GMT -7. The time now is 10:59 AM.


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