renderman rsl


#1

I’m a beginner using renderman shader code and I am trying to figure out how to add opacity to everything outside the if statement, which is a pattern. If you run the .sl code below you will see the issue.

surface
   js_st_pattern (float Kfb = 1; float Kd = 1;)
   {
   
   color surfcolor = 0;
   	   
   if ((((s-.5)*(s-.5))+((t-.5)*(t-.5))<.1) && (((s-.6)*(s-.6))+((t-.5)*(t-.5))>.1))
   surfcolor = color (1.0, .5, 0);
   
   Oi = Os;
   
   Ci = Oi * Cs * surfcolor * Kfb;
   }

#2
surface 
 js_st_pattern (
 	float Kfb = 1;
 	color outOpacity = 1;
 )
 {
 	color surfcolor = 0;
 	Oi = Os;
 		  
 	if ((((s-.5)*(s-.5))+((t-.5)*(t-.5))<.1) && (((s-.6)*(s-.6))+((t-.5)*(t-.5))>.1))
 		surfcolor = color (1.0, .5, 0);
 	else
 		Oi = outOpacity;
    
 	Ci = Oi * Cs * surfcolor * Kfb;
 }

Like this?


#3

I tried the code but now the outside is back, transparency has gone though but I’m back at square 1. Here’s a screen shot from “it”.


#4

Ok, figured it out. Actually setting Oi to a color that has different rgb values is wrong, thats why I was seeing strange tinting. Instead I assigned Oi = color (0.0, 0.0, 0.0); which cut out the pattern as expected.

The final assignment was

Ci = Oi * Cs * surfcolor * Kd;


#5

i think lunat1k thought you want to use your shader parameter outOpacity to control the opacity outside your solid shape. the code he wrote should work fine and for totally transparent regions simply set outOpacity to black.

renderman uses color values to define the value. like this it is not like an alpha but also supports color information


#6

You must be taking Professor Kesson’s Renderman class !

: )


#7

Thanks for the help guys. I do have another issue. I’m not sure if it’s the labs here at uni but Renderman is popping frames from my animation sequence. It either pops the geometry or it completely disappears on arbitrary frames but consistent dependant on the object and or it’s duplicates. This has happened before with people and some never. I don’t understand what it is that causes this. I have a plant that I rigged 3-4 different ways and animated it 3-4 different ways and still get the popping and disappearing act. It’s frustrating and seems to be an issue no one knows why it occurs. Does anyone know what causes this wonky behavior?

I tried animating with deformers, joints, hair system and still get the same issue. I’m at the point now where I’m laughing at the monitor because I have done just about everything I can think of. I have nit picked details of the construction to this animation and tried different methods but nothing seems to work.

Does anyone know how to fix this or has this ever happened to anyone?


#8

Now things could have changed alot and i’ll sound like an idiot, but I remember that Kesson gives the class a script to actually duplicate the animation onto the placeholder boxes. The script had trouble ping-ponging the animation loop… that was the only unexplained phenomena I remember. Things could be - and probably are - totally different now.

if your really suffering you can post the scripts ur using and i can look at them. Granted I’ll probably send them back in python…


#9

He provided 2 scripts for this work flow. The script I use to batch render the sequence is called batchRenderRI.mel. I have another one called rmanOutputDelayedReadArchive.mel which is used to add an archive attribute that reads in the rib files. From what I have heard the work flow changes, not sure if this change is working in my favor.

#batchRenderRI.mel#

    global proc string getParentPath(string $path)
    {
    string $tokens[];
    string $parent = "";
    int $hasLeadingSlash = (startsWith($path, "/")) ? 1 : 0;
    tokenize($path, "/", $tokens);
    for($n = 0; $n < size($tokens) - 1; $n++)
    	if($n == 0)
    		$parent += $tokens[$n];
    	else
    		$parent += "/" + $tokens[$n];
    if($hasLeadingSlash)
    	return "/" + $parent;
    else
    	return $parent;
    }
    //-----------------------------------------------------------------------
    global proc batchRenderRI()
    {
    rman genrib;	// Generate the ribs
      
    string $batchName;
    if(`about -os` == "nt" || `about -os` == "win64")
    	$batchName = "batchRender.bat";
    else
    	$batchName = "batchRender.sh";
    	
    $rmsScriptPath = `getenv "RMS_SCRIPT_PATHS"`;
    $pyScriptPath = getParentPath($rmsScriptPath) + "/RMS_python/batchRender.py";
      
    string $projPath = `workspace -q -rootDirectory`;
    string $sceneName = `file -q -sceneName -shortName`;
    // If the user has not saved their scene RfM Pro will
    // reference it as "untitled"
    if(size($sceneName) == 0)
    	$sceneName = "untitled";
    else
    	{
    	string $b[];
    	if(tokenize($sceneName, ".", $b) != 0)
    		$sceneName = $b[0];
    	}
    string $cmd = "python";
    string $arg1 = $sceneName;
    string $arg2 = $projPath;
    print("Calling python script: \"" + $pyScriptPath + "\"
");
    print("Arg 1 (Scene Name):	\"" + $arg1 + "\"
");
    print("Arg 2 (Project Path):  \"" + $arg2 + "\"
");
    system ($cmd + " " + $pyScriptPath + " " + $arg1 + " " + $arg2);
     
    // Run the batch rendering script
    string $batchRenderPath = $projPath + $batchName;
      
    if(`about -os` == "nt" || `about -os` == "win64") {
    	$batchRenderPath = "start " + $batchRenderPath;
    	print("Executing script:\"" + $batchRenderPath + "\"
");
    	system ($batchRenderPath);
    	}
    else
    	{
    	print("Executing script:\"" + $batchRenderPath + "\"
");
    	system ($batchRenderPath + " &");
    	}
    }
    
#rmanOutputDelayedReadArchive.mel#

    // rmanOutputDelayedReadArchive.mel
    // This is a modified version of a Pixar script. The original can be found
    // at,
    // 		RenderManStudio-2.0.2-maya2008/scripts/rmanOutputDelayedReadArchive.mel
    //
    // This script ensures a sequence of rib archives can be looped. Suppose 
    // this script is used in a 72 frame animation but only a 24 prebaked ribs 
    // are available. For example,
    //		plant.0001.rib
    //		plant.0002.rib
    //		...
    //		plant.0024.rib
    // The script will access the 24 ribs three times. To provide a variation
    // to the looping, a random offset is applied. The offset is derived from
    // the numeric suffix of the poly object to which the script has been 
    // assigned as a pre-shape MEL insertion point. It is assumed the archive
    // rib sequence begins at 0001 and that there are 4 padding characters.
    //
    // This script does not replace the original but, instead, should be saved
    // in the users,
    //		maya/projects/RMS_mel
    // directory. Because of the order in which scripts are sourced by RenderMan
    // Studio this script will, in effect, "hide" Pixar's original script.
    //
    // M.Kesson Oct 3 2010
    //	version 2
    //
    global proc rmanOutputDelayedReadArchive()
    {
    // Find the object context within which this script is being called.
    string $object = `rman ctxGetObject`;
    
    rmanResizeDRAProxy $object;
    	
    // Get the value of the draFile attr.
    string $attr = `rmanGetAttrName "draFile"`;
    string $drafile = `getAttr ($object + "." + $attr)`;
    
    	
    // Check whether the file should be treated as a sequence
    $attr = `rmanGetAttrName "draUseSequenceNumber"`;
    int $doSeq = `getAttr ($object + "." + $attr)`;
    	
    if( $doSeq ) {
    	// Replace the frame number in the file name with the current frame.
    	/* 	Because of the customization of this script we no longer require
    		the next three lines of code.
    	$attr = `rmanGetAttrName "draSequenceNumber"`;
    	int $seqNum = `getAttr ($object + "." + $attr)`;
    	$drafile = `rmanReplaceFrameNumber $drafile $seqNum`;
    	*/
    	// Begin additional code______________________________________
    	int	$frame = `currentTime -q`;
    	string 	$temp[] = getFileInfo($drafile);
    	string 	$archivePath = $temp[0] + "/";
    	string	$ribName = $temp[1];
    
    	//print(">>$archivePath " + $archivePath + "<
");
    	string 	$ribs[] = `getFileList -folder $archivePath -filespec ($ribName + ".*.rib")`;
    	int		$numRibs = size($ribs);
    	int 	$n;
    	if($numRibs == 0) {
    		print("Error: Cannot find a sequence of ribs beginning with \"" + $ribName + "\"
");
    		print("		in the directory \"" + $archivePath + "\"
");
    		}
    	else if($frame == 1) {
    		print("Found the following sequence of rib archive files
");
    		for($n = 0; $n < $numRibs; $n++)
    			print("	\"" + $ribs[$n] + "\"
");
    			}
    	// The shape node may hava a number in its name that we can use to set the
    	// random number generator
    	int	$nodeNumber = `match "[0-9]+" $object`;
    	int $randOffset = 0;	
    	
    	if($nodeNumber != "") {
    		seed(int($nodeNumber));
    		$randOffset = rand(0, 100);
    		}
    	
    	// Loop over the available ribs
    	int $index = fmod($frame + $randOffset, $numRibs);
    	if($index == 0)
    		$index = $numRibs;
    	//print("Frame = " + $frame + " mod = " + $index + "
");
    	string $numExt;
    	if($index < 10) 
    		$numExt = "000" + $index;
    	else if($index < 99)
    		$numExt = "00" + $index;
    	else if($index < 999)
    		$numExt = "0" + $index;
    	else 
    		$numExt = "" + $index;
    	//print("Frame = " + $frame + " $numExt = \"" + $numExt + "\"
");
    	// Now we have the padded numeric extension we can reconstruct the
    	// full path to the appropriate rib archive
    	$drafile = $archivePath + "/" + $ribName + "." + $numExt + ".rib";
    	//print("$randOffset = " + $randOffset + "  Frame = " + $frame + " $drafile = \"" + $drafile + "\"
");
    	// End additional code______________________________________
    
    	}
    	
    	// Get the bounding box from the maya shape node, which we'll assume 
    	// encompasses the RIB archive.  RenderMan wants the bbox to be in 
    	// centimeters in object space.
    	string $curUnit = `currentUnit -q -linear`;
    	currentUnit -linear "cm";  // temporarily change to centimeters
    	float $bbMin[3] = `getAttr ($object + ".boundingBoxMin")`;
    	float $bbMax[3] = `getAttr ($object + ".boundingBoxMax")`;
    	currentUnit -linear $curUnit;
    	RiProcedural "DelayedReadArchive" $drafile $bbMin[0] $bbMax[0] $bbMin[1] $bbMax[1] $bbMin[2] $bbMax[2];
    }
    
    global proc string[] getFileInfo(string $fullPath)
    {
    string $name = "";
    string $parent = dirname( $fullPath );
    
    string $result[2] = { $parent, $name };
    if(size($fullPath) == 0)
    	return $result;
    	
    string $buffer[];
    $numTokens = `tokenize $fullPath "/" $buffer`;
    if($numTokens == 0)
    	return $result;
    	
    string $ribName = $buffer[size($buffer) - 1];
    $numTokens = `tokenize $ribName "." $buffer`;
    if($numTokens == 0)
    	return $result;
    $name = $buffer[0];
    $result[1] = $name;
    return $result;
    }
    

Now, my animation is not looped but I’m assured it works by simply exporting say 200 frames of the animation and opening the sequence. I have seen it work doing a longer frame range but I have had no luck. It imports of course and renders, but like I said a duplicate or the original instanced or not will disappear for a frame and come back. Later, when I baked the animation the disappearing act stopped for the most part but the sequence was not being read in correctly causing the animation to jump, at different intervals of each duplicate. Malcolm mentioned that baking the animation in Maya is not necessary to bake the ribs and should not be a component to the errors.


#10

hmm difficult for me to see a problem without testing…

this is of course a dumb question, but, when you run the scrip, is your current time set to 1 ?


#11

Yup yup :stuck_out_tongue_winking_eye:


#12

i had some strange problems with things disappearing etc but that was with scenes which did not came from me so i can’t say what was causing it.

what sometimes helps a lot is flattening your ribs. can’t say much from the image you’ve uploaded about your scene but maybe you want to give it a try. go to the render globals->advanced->rib options->flatten

also if you have a frame which does not render properly the first thing you should do is checking the rib file. this file will tell you exactly whats going on and from there on you could debug your scene


#13

Gravedigger, I tried to flatten and still get the disappearing.

You say checking the rib file will tell me exactly whats going on. What exactly am I looking for, where do I look in the rib and how would I debug it? Please elaborate.

I don’t think it has something do with the final scene to render out because I’ve tried deleting 1 of the duplicates an error shows up and adding another instance or duplication and it goes away but pops onto another frame on another object. Here’s the error I’m getting right now.

// Error: (11/07 20:19) rfm Error: R12001 File E:/CLASS/VSFX319/maya/projects/vsfx319_projects/palmetto/RIB_archive/spikes.099.rib cannot be opened by RiReadArchive. [<Splitting> Object: pCube31|pCubeShape4] //
currentTime 23 ;

This happens on arbitrary duplicated objects and it makes no damn sense to me.

I also tried re exporting a single rib from the error and still get this. Unfortunately, Malcolm doesn’t know what the hell is going on either so I’m out of luck at the moment.


#14

hi jonathan

hoped that it would help to flatten!
i think malcolm is already discussing this in the pixar forum but i’m not 100% sure because theres going on quite a lot at the moment because of the new release

i can’t really say where this could come from but what i could offer is that you send me over your scene file and i try to get it to work here. just send me a private message

its always nice to hear from the students from malcolms class

grs
Patrik


#15

Gravedigger or anyone for this matter,

Look at the #rmanOutputDelayedReadArchive.mel# I attached above.

I’m thinking the script could be causing the problems. My sequence is 240 frames. I sense he made this script for the use of looping.

If I’m seeing this correctly is it possible to alter this script to make it just render out the explicit frames instead of adding an offset or extra stuff?

**To batch render my scene I have to run batchRenderRI in the mel command. If it helps here’s the python script batchRenderRI calls.

# Refer to www.fundza.com/rms/batching/index.html for more
# details about this script and its used with Maya.
# Malcolm Kesson (Feb 29 2008)
  
import re, sys, os
  
#-----------------------------------------------------
def convertToWindows(linuxpath):
	pattern = re.compile(r"/")
	return pattern.sub(r'\\', linuxpath)
#-----------------------------------------------------
# Given the relative path to a beauty pass rib file this proc
# returns the relative path of its primary image. For example,
#	getImagePath("renderman/untitled/rib/0001/perspShape_Final.0001.rib")
# might return,
#	"renderman/untitled/images/untitled.0001.iff"
#
def getImagePath(beautyRib, projectPath):
	f = open(os.path.join(projectPath,beautyRib), 'r')
	lines = f.readlines()
	for line in lines:
		if line.strip().startswith("Display "):
			tokens = line.split('"')
			path = tokens[1]
			if path.startswith("+") == False:
				return path
	f.close()
#-----------------------------------------------------
# Given the relative path of an image this proc will substitute
# the numberic extension with a single "#" (pound) symbol. For
# example,
#	replaceNumericWithPound("renderman/untitled/rib/0001/perspShape_Final.0001.rib")
# would return,
#	renderman/untitled/rib/0001/perspShape_Final.#.rib
# This makes the path useable within a Shake script.
#
def replaceNumericWithPound(imagepath):
	parent,name = os.path.split(imagepath)
	pattern = re.compile(r"[.]\d+[.]")
	name = pattern.sub(r'.#.',name)
	return os.path.join(parent,name)
#-----------------------------------------------------
# Given the name of a scene this proc returns a list of the
# relative paths of the beauty ribs. For example,
#	getListOfBeautyRibs("untitled")
# would return say,
#	renderman/untitled/rib/0001/perspShape_Final.0001.rib
#	renderman/untitled/rib/0001/perspShape_Final.0002.rib
#	etc...
#
def getListOfBeautyRibs(scene, projectPath):
	outList = [ ]
	targetRibDir = "/renderman/" + scene + "/rib"
	targetSubDirs = os.listdir(projectPath + targetRibDir)
	
	# There are many rib files but a beauty pass rib can be
	# identified by the text "_Final" in their name.
	pattern = re.compile(r"_Final")
	for subdir in targetSubDirs:
		# Rib sub-directories are named with 4 digits
		if len(subdir) == 4:
			ribs = os.listdir(projectPath + targetRibDir + "/" + subdir)
			for rib in ribs:
				ribpath = targetRibDir + "/" + subdir + "/" + rib
				if pattern.search(ribpath, 1):
					outList.append(ribpath)
	return outList
#-----------------------------------------------------
# Given the name of the scene and a path to the users project
# this proc returns a list of paths to the, what might be
# the "root" rib files. The "root" ribs are those with four
# digit names, for example,
#	renderman/untitled/rib/0001/0001.rib
#	renderman/untitled/rib/0002/0002.rib
#
def getListOfRootRibs(scene, projectPath):
	outList = [ ]
	targetRibDir = "renderman/" + scene + "/rib"
	targetSubDirs = os.listdir(projectPath + targetRibDir)
	
	for subdir in targetSubDirs:
		if len(subdir) == 4:
			ribpath = targetRibDir + "/" + subdir + "/" + subdir + ".rib"
			outList.append(ribpath)
	return outList
#-----------------------------------------------------
# Writes a batch list for rendering with prman. For example,
#	prman FULL_PATH/renderman/untitled/rib/0001/0001.rib
#	prman FULL_PATH/renderman/untitled/rib/0002/0002.rib
#	ditto...
# This proc also appends a call to run a shake script (refer
# to the next proc) that will automatically read the rendered
# images into a FileIn node. This allows the image sequence
# to be viewed in a Shake flipbook
#
def makeBatchFromList(batchName, projectPath, ribList):
	batchPath = os.path.join(projectPath,batchName)
	f = open(batchPath, 'w')
	if os.name == "posix":
		f.write("source /etc/profile
")
	else:
		f.write("SET
")
	trimmedPath = projectPath[:len(projectPath) - 1]
	if os.name == "nt":
		projectPath = convertToWindows(projectPath)
		trimmedPath = convertToWindows(trimmedPath)
	f.write("cd " + trimmedPath + "
")
	for rib in ribList:
		if os.name == "nt":
			rib = convertToWindows(rib)
		f.write("prman " + os.path.join(projectPath,rib) + "
")
	shkPath = os.path.join(projectPath, "batch.shk")
	f.write("openFcheck.bat")
	# or use shake if you wish...
	# f.write("shake -script %s" % shkPath)
	f.close()
	return batchPath
#-----------------------------------------------------
# Writes a simple Shake script that loads an image sequence and
# displays it in a flipbook.
def makeShakeScript(scriptPath, frameCount, imagePath):
	f = open(scriptPath, 'w')
	f.write('SetTimeRange("1-%s");
' % frameCount)
	if os.name == "nt":
		imagePath = convertToWindows(imagePath)
	f.write('FileIn("%s");' % imagePath)
	f.close()
#-----------------------------------------------------
# Writes a simple batch script that loads an image sequence and
# displays it in fcheck.
def makeFcheckScript(scriptPath, frameCount, imagePath):
	if os.name == "nt":
		imagePath = convertToWindows(imagePath)
	f = open(scriptPath, 'w')
	f.write('fcheck -n 1 %s 1 %s
' % (frameCount, imagePath))
	f.close()
#-----------------------------------------------------
  
def main():
	sceneName = "untitled"
	projectPath = "./"
	args = sys.argv[1:]
	sceneName = args[0]
	projectPath = args[1]
	
	# Get a list of beauty pass rib files associated with a scene.
	beautyRibs = getListOfBeautyRibs(sceneName, projectPath)
	# Get a list of the "root" rib files.
	rootRibs = getListOfRootRibs(sceneName, projectPath)
	
	if len(rootRibs) > 0:
		# Write a batch rendering file
		if os.name == "posix":
			batchName = "batchRender.sh"
			batchPath = makeBatchFromList(batchName, projectPath, rootRibs)
			os.chmod(batchPath, 0777)
		else:
			batchName = "batchRender.bat"
			makeBatchFromList(batchName, projectPath, rootRibs)
	
	# Look into one of the beauty pass ribs to find the relative path
	# specified by its "Dispay" statement.
	imagePath = getImagePath(beautyRibs[0], projectPath)
	# Convert the relative path to a full path and substitute
	# the numeric extension to a "#" symbol.
	imagePath = replaceNumericWithPound(imagePath)
	
	#projectPath = convertToWindows(projectPath)
	#makeShakeScript(os.path.join(projectPath,"batch.shk"),len(beautyRibs),
	#os.path.join(projectPath,imagePath))
	
	makeFcheckScript(os.path.join(projectPath,"openFcheck.bat"),len(beautyRibs),
	os.path.join(projectPath,imagePath))

if __name__ == "__main__":
	main()


#16

hi jonathan,

the problem can be in the script but its difficult to tell without having the possibility to try it here.

what i meant by having a look at the rib file is that you can check if the necessary calls are in there or if already the rib file generated for this frame lacks the call which makes the object not to render. if there is the call in the rib the error happens during rendering and the error you’ve posted “cannot be opened by RiReadArchive” tells you that renderman couldn’t use the rib during the render. mostly this is because the rib does not exist so what i would suggest is to double check if this rib file really exists and wether the path really is 100% correct.

if all of this doesn’t get you any further we should discuss alternative ways of rendering your scene. what exactly does your scene look like? is it one object which is duplicated? what i usually do is that i use the RiReadArchive “archive.rib” call to check and then i go on using the RiProcedrual “DelayedReadArchive” call with the correct bounding boxes.

sorry that i can’t provide you more. give us some more info an well surely could trace the problem down!

grs
Patrik


#17

Right now, the method I was shown to set up the rib archive is to make a cube to the dimensions of whatever object you want to import.
Next select it and go to the attribute editor > Attributes > Renderman > Add Archive Controls.

Browse to the rib in question, select the first 1 and switch on Use Sequence Number.

I have instanced the objects, but I have tried simply duplicating and get the same flickering.
Funny thing is, it begins to go away around the 95th frame (of 240).


#18

this workflow usually works without any problems. you are sure that those files exist in your sequence?

as an alternative could you try creating a cube go to attributes->renderman->manage attributes. then select invis and preShapeMEL and add those. now right at the bottom set the invis to proxy and in the preShapeMEL line you have to enter something like:


RiReadArchive "archive.rib";

if you want to use a rib sequence you’d need some more scripting so instead you could go to your script editor and enter this:


global proc string getFormatTime() {
 	$t = int(`currentTime -q`);
 	if($t>=1000)
 		return $t;
 	if($t>=100)
 		return "0"+$t;
 	if($t>=10)
 		return "00"+$t;
 	return "000"+$t;
 };

then enter in the preShapeMEL:


RiReadArchive ("pathToArchive/archive."+getFormatTime()+".rib");


keep in mind the getFormatTime() function formats the string for sequences like 0001 0002 0003 etc not 001 002 003. you’d have to adjust this if you need it.

with this you could check wether it is some kind of bounding box problem. its a bit tedious to try to solve the problem like this but as i said we’d need more info.

grs
Patrik


#19

I figured it could be a bounding box issue and re rendered 100 frames with 1 instanced duplicate but I still get some hiccups.

I’m going to try this workflow now and see what happens.

**Those ribs with errors are there and have tried baking them back out but no good.


#20

I have to ask.

Would I replace what you call RIReadArchive with the name of my folder archive called RIB_Archive

=======================

I am not seeing the geometry just a rendered cube doing this. I’m not getting an error. Here’s the script editor results

// (11/11 13:01) rfm Info: Validating texture: E:/CLASS/VSFX319/maya/projects/vsfx319_projects/palmetto/images/sky.jpg //
// (11/11 13:01) rfm Notice: Rendering rmanDeepShadowPass1 at 100 //
// (11/11 13:02) rfm Notice: Rendering perspShape_Final at 100 //

and this is what I put into the Pre Shape MEL

RiReadArchive (“E:/CLASS/VSFX319/maya/projects/vsfx319_projects/palmetto/RIB_archive/palm.”+getFormatTime()+".rib");