Exemplo n.º 1
0
int main(int argc, char *argv[]) {
    if (argc < 2) {
        printf("Not enough arguments given!\n");
        return 1;
    } else if (argc > 2) {
        printf("Too many arguments given!\n");
        return 1;
    }
    char *fprefix = argv[1];
    srand(time(NULL));
    const size_t NUM_FRAMES = 120;
    RtInt md = 4;
    scene_info_t scene;
    double rad = 55.0;
    double t = 0.0;
    const double tmin = 0.0;
    const double tmax = 2.0*PI;
    double dt = (tmax-tmin)/NUM_FRAMES;
    size_t fnum;

    RiBegin(RI_NULL);
    RiOption("trace", "maxdepth", &md, RI_NULL);
    RiSides(1);

    scene.cam.location[0] = rad;
    scene.cam.location[1] = rad;
    scene.cam.location[2] = rad;

    scene.cam.look_at[0]= 0.0;
    scene.cam.look_at[1]= 0.0;
    scene.cam.look_at[2]= 0.0;
    scene.cam.roll = 0.0;

    scene.fprefix = fprefix;

    
    const size_t NUM_POINTS = 100000000;

    RtPoint *pts = malloc(sizeof(RtPoint)* NUM_POINTS);
    randomPoint2D(pts[0]);
    /* pts[0][2] = 0.0; */

    /* RtFloat mats[][3][3] = {{{0.0,0.0,0.0}, */
    /*                          {0.0,0.16,0.0}, */
    /*                          {0.0,0.0,1.0}}, */
    /*                         {{0.85, 0.04, 0.0}, */
    /*                          {-0.04, 0.85, 0.0}, */
    /*                          {0.0,0.0,1.0}}, */
    /*                         {{0.20,-0.26, 0.0}, */
    /*                          {0.23, 0.22, 0.0}, */
    /*                          {0.0,0.0,1.0}}, */
    /*                         {{-0.15, 0.28,0.0}, */
    /*                          {0.26, 0.24, 0.0}, */
    /*                          {0.0,0.0,1.0}}, */
    /* }; */
    RtFloat mats[][3][3] = {{{0.34,0.0,0.0},
                             {0.0,0.34,0.0},
                             {0.0,0.0,0.34}},
                            {{0.34,0.0,0.0},
                             {0.0,0.34,0.0},
                             {0.0,0.0,0.34}},
                            {{0.34,0.0,0.0},
                             {0.0,0.34,0.0},
                             {0.0,0.0,0.34}},
                            {{0.34,0.0,0.0},
                             {0.0,0.34,0.0},
                             {0.0,0.0,0.34}},
                            {{0.34,0.0,0.0},
                             {0.0,0.34,0.0},
                             {0.0,0.0,0.34}},
                            {{0.34,0.0,0.0},
                             {0.0,0.34,0.0},
                             {0.0,0.0,0.34}},
                            {{0.34,0.0,0.0},
                             {0.0,0.34,0.0},
                             {0.0,0.0,0.34}},
    };

    RtPoint offsets[] = {{0.0,0.0,0.66},
                         {0.0,0.0,-0.66},
                         {0.0,0.0,0.0},
                         {0.66,0.0,0.0},
                         {-0.66,0.0,0.0},
                         {0.0,0.66, 0.0},
                         {0.0,-0.66, 0.0},
    };
    RtFloat probs[] = {0.14285714285714285,
                       0.14285714285714285,
                       0.14285714285714285,
                       0.14285714285714285,
                       0.14285714285714285,
                       0.14285714285714285,
                       0.14285714285714285,
    };
    for (size_t i=0; i<NUM_POINTS-1; ++i) {
        ifs(7, mats, offsets, probs, pts[i], pts[i+1]);
    }

    for (fnum = 0; fnum < NUM_FRAMES; ++fnum) {
        scene.cam.location[0] = rad*sin(t);
        scene.cam.location[1] = rad;
        scene.cam.location[2] = rad*cos(t);
        /* scene.cam.look_at[1] = rad; */
        t += dt;
        printf("Rendering frame %lu\n", (unsigned long)fnum);
        RtInt on = 1;
        char buffer[256];
        RtString on_string = "on";
        RtInt samples = 2;
        RtPoint light1Pos = {80,80,80};
        RtPoint light2Pos = {0,120,0};
        RtPoint light3Pos = {0,40,0};

        /* RiImager("background", RI_NULL); */

        RiFrameBegin(fnum);

        
        sprintf(buffer, "images/%s%05lu.jpg", scene.fprefix, (unsigned long)fnum);
        RiDisplay(buffer,(char*)"jpeg",(char*)"rgb",RI_NULL);
  
        RiFormat(1280, 720, 1.0);

        RiProjection((char*)"perspective",RI_NULL);

        PlaceCamera(&scene.cam);
        RiShadingRate(1.0);
        RiShadingInterpolation("smooth");
        /* RtFloat bound = 0.125; */
        /* char *space = "object"; */
        /* RiAttribute ("displacementbound", "sphere", (RtPointer)&bound, "space", (RtPointer)&space, RI_NULL); */
        /* RiAttribute("visibility", "int trace", &on, RI_NULL); */
        /* RiAttribute( "visibility", */
        /*              "int camera", (RtPointer)&on, */
        /*              "int transmission", (RtPointer)&on, */
        /*              "int diffuse", (RtPointer)&on, */
        /*              "int specular", (RtPointer)&on, */
        /*              "int photon", (RtPointer)&on, */
        /*              RI_NULL ); */
        /* RiAttribute( "light", (RtToken)"shadows", (RtPointer)&on_string, (RtToken)"samples", (RtPointer)&samples, RI_NULL ); */

        RiAttribute((RtToken)"light", "string shadow", (RtPointer)&on_string, RI_NULL);
        RiLightSource("distantlight", "point from", (RtPointer)light1Pos, RI_NULL);
        RiLightSource("distantlight", "point from", (RtPointer)light2Pos, RI_NULL);
        /* RiLightSource("pointlight", "point from", (RtPointer)light3Pos, RI_NULL); */
        RiWorldBegin();

        
        RiAttributeBegin();
        /* RtColor col = {((double)fnum)/NUM_FRAMES,1.0-((double)fnum)/NUM_FRAMES,0.0}; */
        RtColor col = {0.0,1.0,0.0};
        RiSurface((char*)"matte", RI_NULL);
        /* RtColor opa = {0.8,0.8,0.8}; */
        /* RiOpacity(opa); */
        /* RtFloat km = 0.125; */
        /* RiDisplacement((char*)"stucco", (RtToken)"Km", (RtPointer)&km, RI_NULL); */
        RiColor(col);
        /* RtColor opa = {0.75,0.75,0.75}; */
        /* RiOpacity(opa); */

        RiScale(50.0,50.0,50.0);
        RtFloat cw = 0.0005;
        RiPoints(NUM_POINTS, "type", "particles", "constantwidth", &cw, RI_P, pts, RI_NULL);
        /* RiSphere(0.2,-0.2,0.2,360.0, RI_NULL); */
        RiAttributeEnd();

        RiWorldEnd();
        RiFrameEnd();

    }
    RiEnd();

    return 0;
}
void tShadowRibWriterMgr::framePrologue_display(const structJob &currentJob)
{
	CM_TRACE_FUNC("tShadowRibWriterMgr::framePrologue_display(job="<<currentJob.name.asChar()<<")");

	//refactor 14-1 begin from liqRibTranslator::framePrologue()
	if( currentJob.pass != rpShadowMap && liqglo.liqglo_rotateCamera  == true )
	{
		// philippe : Rotated Camera Case
		RiFormat( currentJob.height, currentJob.width, currentJob.aspectRatio );
	}else{
		RiFormat( currentJob.width, currentJob.height, currentJob.aspectRatio );
	}
	//refactor 14-1 end

	if( currentJob.pass != rpShadowMap )
	{
		//refactor 14 begin to tHeroRibWriterMgr::framePrologue_display()
		// Smooth Shading
		RiShadingInterpolation( "smooth" );
		// Quantization
		// overriden to floats when in rendering to Maya's renderView
		if( !liqglo.m_renderView && liqglo.quantValue != 0 )
		{
			int whiteValue = (int) pow( 2.0, liqglo.quantValue ) - 1;
			RiQuantize( RI_RGBA, whiteValue, 0, whiteValue, 0.5 );
		}
		else
		{
			RiQuantize( RI_RGBA, 0, 0, 0, 0 );
		}
		if( liqglo.m_rgain != 1.0 || liqglo.m_rgamma != 1.0 )
		{
			RiExposure( liqglo.m_rgain, liqglo.m_rgamma );
		}
		//refactor 14 end
	}

			if( currentJob.pass == rpShadowMap &&(currentJob.shadowType != stDeep || currentJob.samples == 1 ) )
			{	
				//refactor 15
				if( liqglo.liquidRenderer.renderName == MString("Pixie") )
				{
					liqFloat zero = 0;
					RiHider( "hidden", "jitter", &zero, RI_NULL );
				}
				else
				{
					liqInt zero = 0;
					RiHider( "hidden", "int jitter", &zero, RI_NULL );
				}
				//refactor 15
			}
			if( currentJob.pass == rpShadowMap && currentJob.shadowType == stMidPoint )
			{
				//refactor 16
				liqString midPoint = "midpoint";
				liqFloat midRatio = /*liqglo.liqglo_*/currentJob.midPointRatio;

				RiHider( "hidden", "depthfilter", &midPoint, RI_NULL );

				if ( /*liqglo.liqglo_*/currentJob.midPointRatio != 0 )
					RiHider( "hidden", "midpointratio", &midRatio, RI_NULL ); // Output to rib jami
							//refactor 16
			}
			//-----------------------------------------------------
			LIQDEBUGPRINTF( "-> Setting Display Options\n" );
			//if( currentJob.pass == rpShadowMap )
			//MString relativeShadowName( liquidSanitizePath( liquidGetRelativePath( liqglo_relativeFileNames, liqglo_currentJob.imageName, liqglo_projectDir ) ) );
			//refactor 17 begin
			if( currentJob.shadowType != stMinMax )
			{
				if( currentJob.shadowType == stDeep )
				{
					// RiDeclare( "volumeinterpretation", "string" );
					liqString volume = "continuous";

					if ( currentJob.volume != viContinuous )
						volume = "discrete"; 

					if( liqglo.liquidRenderer.renderName == MString("3Delight") )
					{
						RiArchiveRecord( RI_COMMENT, "Display 1");
						RiDisplay( const_cast< char* >( /*liqglo.liqglo_*/currentJob.imageName.asChar()),
							const_cast< char* >( /*liqglo.liqglo_*/currentJob.format.asChar() ),
							(liqToken)/*liqglo.liqglo_*/currentJob.imageMode.asChar(),
							"string volumeinterpretation", &volume,
							RI_NULL );
					}
					else
					{
						// Deep shadows cannot be the primary output driver in PRMan & co.
						// We need to create a null output zfile first, and use the deep
						// shadows as a secondary output.
						//
						if( liqglo.liquidRenderer.renderName != MString("Pixie") )
						{
							RiArchiveRecord( RI_COMMENT, "Display 2");
							RiDisplay( "null", "null", "z", RI_NULL );
						}

						MString deepFileImageName = "+" + /*liqglo.liqglo_*/currentJob.imageName;

						RiArchiveRecord( RI_COMMENT, "Display 3");
						RiDisplay( const_cast< char* >( deepFileImageName.asChar() ),
							const_cast< char* >( /*liqglo.liqglo_*/currentJob.format.asChar() ),
							(liqToken)/*liqglo.liqglo_*/currentJob.imageMode.asChar(),
							"string volumeinterpretation", &volume,
							RI_NULL );
					}
				}//if( liqglo.liqglo_currentJob.deepShadows )
				else
				{
					RiArchiveRecord( RI_COMMENT, "Display 4");
					liqInt aggregate( /*liqglo.liqglo_*/currentJob.shadowAggregation );
					RiDisplay( const_cast< char* >( /*liqglo.liqglo_*/currentJob.imageName.asChar() ),
						const_cast< char* >( /*liqglo.liqglo_*/currentJob.format.asChar() ),
						(liqToken)/*liqglo.liqglo_*/currentJob.imageMode.asChar(),
						"int aggregate", &aggregate,
						RI_NULL );
				}
			}//if( !liqglo.liqglo_currentJob.isMinMaxShadow )
			else
			{
				RiArchiveRecord( RI_COMMENT, "Display 5");
				RiArchiveRecord( RI_COMMENT, "Display Driver:" );
				liqInt minmax = 1;
				RiDisplay( const_cast< char* >( (/*liqglo.liqglo_*/currentJob.imageName+(int)liqglo.liqglo_lframe).asChar() ),//const_cast< char* >( parseString(liqglo_currentJob.imageName).asChar() ),
					const_cast< char* >(/*liqglo.liqglo_*/currentJob.format.asChar()),
					(liqToken)/*liqglo.liqglo_*/currentJob.imageMode.asChar(),
					"minmax", &minmax,
					RI_NULL );
			}
			exportJobCamera( currentJob, currentJob.camera );
			//refactor 17 end
			//}
}
Exemplo n.º 3
0
MStatus ribGenCmd::doIt( const MArgList& args)
{
	/*=========================================*
	  *		the parameters of command															
	  *	=========================================*/
	MString ribPath, shaderPath;					
	unsigned index;
	index = args.flagIndex("p", "ribPath");

	if(MArgList::kInvalidArgIndex != index)
		args.get(index+1, ribPath);
	
	index = args.flagIndex("sp", "shaderPath");
	if(MArgList::kInvalidArgIndex != index)
		args.get(index+1, shaderPath);

	/*=========================================*
	  *		shaderPath & ribPath																		
	  *=========================================*/
	RtToken shader= new char[50] , path=new char[50];
	strcpy(shader, shaderPath.asChar());
	strcpy(path, ribPath.asChar());

	char *curve[] = {"curves"};	

	RtMatrix identityMatrix =
	{	{ 1, 0, 0, 0 },
		{ 0, 1, 0, 0 },
		{ 0, 0, 1, 0 },
		{ 0, 0, 0, 1 }}; 
	
	RtInt ustep, vstep;
	ustep = vstep =1;

  /*=====================================*
	*		Begenning of writting out the .rib file.														
	*=====================================*/	
	RiBegin(path);
		RiAttributeBegin();
			RiTransformBegin();
				//RiSurface(shader);
			RiTransformEnd();


			//RiAttribute("identifier", "name", curve);
			RiConcatTransform(identityMatrix);
			RiShadingInterpolation(RI_SMOOTH);
			RiBasis(RiBezierBasis, ustep, RiBezierBasis, vstep);			



	int nodeId	= 0, knotNum = 0;
	float baseWidth = 0.0f, tipWidth	= 0.0f;
	MObject surface, node;
	/*=========================================*
	  *		get the informations of selected Objects in scene.																		
	  *=========================================*/	
	MSelectionList selection;
	MGlobal::getActiveSelectionList(selection);
	MItSelectionList iter(selection, MFn::kNurbsSurface );

	for(; !iter.isDone(); iter.next())
	{
		RtInt numCurves = 0;
		RtInt numVertexs = 0;

		/*======================================*
		  *		get the drawHairNode from selected NurbsSurface. 
		  *======================================*/
		iter.getDependNode(surface);
		MFnDependencyNode surfaceFn(surface);
		MStatus state;
		MPlug plug = surfaceFn.findPlug("worldSpace",false, &state);

		plug = plug.elementByLogicalIndex(0);
		MPlugArray desPlugs;
		plug.connectedTo(desPlugs,false,true);
		plug = desPlugs[0];
		node = plug.node();				//drawHairNode has found here!!

		/*=====================================*
		  *		get the attributes of drawHairNode. 
		  *=====================================*/
		MFnDependencyNode hairNodeFn(node);
		plug = hairNodeFn.findPlug("nodeId");
		plug.getValue(nodeId);
		MGlobal::displayInfo(MString(" nodeId: ")+nodeId);

		plug = hairNodeFn.findPlug("number");
		plug.getValue(numCurves);

		plug= hairNodeFn.findPlug("smooth");
		plug.getValue(knotNum);

		plug = hairNodeFn.findPlug("baseWidth");
		plug.getValue(baseWidth);

		plug = hairNodeFn.findPlug("tipWidth");
		plug.getValue(tipWidth);

		/*=====================================*
		  *		caculate the linear interpolate of the width of the curve.
		  *=====================================*/
		numVertexs = numCurves * knotNum;
		int widthNum = numCurves * (knotNum -2 );
		float *curveWidth = new float[widthNum];
		
		float widthStep = 0.0f;
		for(int c=0; c<widthNum; ++c){
			widthStep = ((c%(knotNum-2)) / (float)(knotNum-3)) *(tipWidth - baseWidth);
			if(widthStep < epslion)
				widthStep = 0.0f;
			curveWidth[c] = baseWidth + widthStep;
		}
		

		RtInt *nvertices = new RtInt[numCurves];						//the numbers of vertices on each curve.
		RtPoint *vertexs = new RtPoint[numVertexs];				//the total vertexs.

		/*=====================================*
		  *		nvertices[] assignment.														
		  *=====================================*/
		for(int j=0; j<numCurves ; ++j){
			nvertices[j] = knotNum;
		}



		/*=====================================*
		  *		get the hair's datas from the static member 
		  *		named "nodeManager" of the drawHairNode class. 
		  *=====================================*/
		nodeMap::iterator  iter =  drawHairNode::nodeManager.find(nodeId);
		vector<MPointArray> helixVec = iter->second;
		

		/*=====================================*
		  *		vertexs[] assignment.														
		  *=====================================*/	
		float x=0, y=0, z=0;
		int countVT=0;
		for(vector<MPointArray>::iterator it=helixVec.begin();  it != helixVec.end();  ++it){
			MPointArray helixCurve = (MPointArray)(*it);

			for(int k=0; k <  helixCurve.length() ; ++k){
				x = helixCurve[k].x;
				if(fabs(x) < epslion)
					vertexs[countVT][0] = 0;
				else
					vertexs[countVT][0] = helixCurve[k].x;
			
				y = helixCurve[k].y;
				if(fabs(y) < epslion)
					vertexs[countVT][1] = 0;
				else
					vertexs[countVT][1] = helixCurve[k].y;
			
				z = helixCurve[k].z;			
				if(fabs(z) < epslion)
					vertexs[countVT++][2] = 0;
				else
					vertexs[countVT++][2] = helixCurve[k].z;
			}
		}
		RiCurves( RI_CUBIC, numCurves, nvertices, RI_NONPERIODIC, RI_P, vertexs, RI_WIDTH, curveWidth, RI_NULL);
	}
	


		RiAttributeEnd();
	RiEnd();

	return redoIt();
}