예제 #1
0
bool IsLayerVisible(MDagPath& dp)
{
    MStatus stat = MStatus::kSuccess;
    MDagPath dagPath = dp;
    while (stat == MStatus::kSuccess)
    {
        MFnDependencyNode node(dagPath.node());
        MPlug doPlug = node.findPlug("drawOverride", &stat);
        if (stat)
        {
            MObject layer = getOtherSideNode(doPlug);
            MFnDependencyNode layerNode(layer, &stat);
            if (stat)
            {
                bool visibility = true;
                if (getBool("visibility", layerNode, visibility))
                    if (!visibility)
                        return false;
                if (getEnumInt("displayType", layerNode) == 1) // template
                    return false;
            }
        }
        stat = dagPath.pop();
    }
    return true;
}
예제 #2
0
void CoronaRenderer::defineColorMapping()
{
	float gamma = 2.2f;
#if MAYA_API_VERSION > 2015
	if (MColorManagementUtilities::isColorManagementEnabled())
		gamma = 1.0f;
#endif
	MFnDependencyNode depFn(getRenderGlobalsNode());
	context.colorMappingData->colorTemperature = getFloatAttr("colorMapping_colorTemperature", depFn, 6500.0f);
	context.colorMappingData->contrast = getFloatAttr("colorMapping_contrast", depFn, 1.0f);
	context.colorMappingData->gamma = gamma;
	context.colorMappingData->tint = toCorona(getColorAttr("colorMapping_tint", depFn));
	context.colorMappingData->exposure.simple.exponent = getFloatAttr("colorMapping_simpleExposure", depFn, 0.0f);
	context.colorMappingData->highlightCompression = getFloatAttr("colorMapping_highlightCompression", depFn, 1.0f);
	context.colorMappingData->photographicExposure = getEnumInt("exposure_type", depFn) == 1;

	// release 0.39 override camera settings
	if (context.colorMappingData->photographicExposure)
	{
		context.colorMappingData->exposure.photographic.fStop = getFloatAttr("colorMapping_fStop", depFn, 5.6);
		context.colorMappingData->exposure.photographic.iso = getFloatAttr("colorMapping_iso", depFn, 100.0);
		context.colorMappingData->exposure.photographic.shutterSpeed = 1.0f / getFloatAttr("colorMapping_shutterSpeed", depFn, 250.0f);

		if ( this->renderCam != MObject::kNullObj)
		{
			MFnDependencyNode camFn(renderCam);
			if (getBoolAttr("mtco_overrideRenderSettings", camFn, false))
			{
				context.settings->set(Corona::PARAM_COLORMAP_ISO, getFloatAttr("mtco_iso", camFn, 1.0));
				context.settings->set(Corona::PARAM_COLORMAP_F_STOP, getFloatAttr("fStop", camFn, 5.6));
				context.settings->set(Corona::PARAM_COLORMAP_SHUTTER_SPEED, 1.0f / getFloatAttr("mtco_shutterSpeed", camFn, 250.0f));
			}
		}
	}
}
예제 #3
0
SkyMap::SkyMap(MObject sObject)
{
	MFnDependencyNode depFn(sObject);

	this->params = new Corona::SkyParams;

	params->multiplier = getFloatAttr("pSkyMultiplier", depFn, 1.0);
	int skyModel = getEnumInt("pSkyModel", depFn);
	if (skyModel == 0)
		params->mode = Corona::SkyModelType::MODEL_PREETHAM;
	if (skyModel == 1)
		params->mode = Corona::SkyModelType::MODEL_RAWAFAKE;
	if (skyModel == 2)
		params->mode = Corona::SkyModelType::MODEL_HOSEK;
	params->groundColor = toCorona(getColorAttr("pSkyGroundColor", depFn));
	params->horizonBlur = getFloatAttr("pSkyHorizBlur", depFn, .1f);
	params->skyAffectGround = getBoolAttr("pSkyAffectGround", depFn, true);
	params->preetham.turbidity = getFloatAttr("pSkyPreethamTurb", depFn, 2.5f);
	params->rawafake.horizon = toCorona(getColorAttr("pSkyHorizon", depFn));
	params->rawafake.horizon = toCorona(getColorAttr("pSkyZenith", depFn));
	params->rawafake.sunBleed = getFloatAttr("pSkySunBleed", depFn, 1.0f);
	params->rawafake.sunFalloff = getFloatAttr("pSkySunFalloff", depFn, 3.0f);
	params->rawafake.sunGlow = getFloatAttr("pSkySunGlow", depFn, 1.0f);
	params->rawafake.sunSideGlow = getFloatAttr("pSkySunSideGlow", depFn, .2f);

	this->initSky();
};
예제 #4
0
void CoronaRenderer::defineColorMapping()
{
	float gamma = 2.2f;
#if MAYA_API_VERSION > 2015
	if (MColorManagementUtilities::isColorManagementEnabled())
		gamma = 1.0f;
#endif
	MFnDependencyNode depFn(getRenderGlobalsNode());
	context.colorMappingData->colorTemperature = getFloatAttr("colorMapping_colorTemperature", depFn, 6500.0f);
	context.colorMappingData->contrast = getFloatAttr("colorMapping_contrast", depFn, 1.0f);
	context.colorMappingData->gamma = gamma;
	context.colorMappingData->tint = toCorona(getColorAttr("colorMapping_tint", depFn));
	context.colorMappingData->exposure.simple.exponent = getFloatAttr("colorMapping_simpleExposure", depFn, 0.0f);
	context.colorMappingData->highlightCompression = getFloatAttr("colorMapping_highlightCompression", depFn, 1.0f);
	context.colorMappingData->photographicExposure = getEnumInt("exposure_type", depFn) == 1;

	// release 0.39 override camera settings
	if (context.colorMappingData->photographicExposure)
	{
		context.colorMappingData->exposure.photographic.fStop = getFloatAttr("colorMapping_fStop", depFn, 5.6);
		context.colorMappingData->exposure.photographic.iso = getFloatAttr("colorMapping_iso", depFn, 100.0);
		context.colorMappingData->exposure.photographic.shutterSpeed = 1.0f / getFloatAttr("colorMapping_shutterSpeed", depFn, 250.0f);

		std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr;
		for (auto cam : mayaScene->camList)
		{
			if (!isCameraRenderable(cam->mobject) && (!(cam->dagPath == mayaScene->uiCamera)))
				continue;
			MFnDependencyNode camFn(cam->mobject);
			if (getBoolAttr("mtco_overrideRenderSettings", camFn, false))
			{
				context.settings->set(Corona::PARAM_COLORMAP_ISO, getFloatAttr("mtco_iso", camFn, 1.0));
				context.settings->set(Corona::PARAM_COLORMAP_F_STOP, getFloatAttr("fStop", camFn, 5.6));
				context.settings->set(Corona::PARAM_COLORMAP_SHUTTER_SPEED, 1.0f / getFloatAttr("mtco_shutterSpeed", camFn, 250.0f));
			}
		}
	}
}
예제 #5
0
void CoronaRenderer::defineMesh(std::shared_ptr<MayaObject> mobj)
{
	std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr;
	std::shared_ptr<mtco_MayaObject> obj = std::static_pointer_cast<mtco_MayaObject>(mobj);

	MObject meshObject = obj->mobject;
	MStatus stat = MStatus::kSuccess;
	
	bool hasDisplacement = false;
	Corona::SharedPtr<Corona::Abstract::Map> displacementMap = nullptr;
	float displacementMin = 0.0f;
	float displacementMax = 0.01f;
	bool displacementAdaptive = false;
	bool diplacementIsHdr = true;
	Corona::DisplacementMode displacementMode = Corona::DisplacementMode::DISPLACEMENT_NORMAL;
	// I do it here for displacement mapping, maybe we should to another place
	getObjectShadingGroups(obj->dagPath, obj->perFaceAssignments, obj->shadingGroups, true);
	if( obj->shadingGroups.length() > 0)
	{
		MFnDependencyNode shadingGroup(obj->shadingGroups[0]);
		MString sgn = shadingGroup.name();
		MObject displacementObj = getConnectedInNode(obj->shadingGroups[0], "displacementShader");
		MString doo = getObjectName(displacementObj);

		if( (displacementObj != MObject::kNullObj) && (displacementObj.hasFn(MFn::kDisplacementShader)))
		{
			MObject displacementMapObj = getConnectedInNode(displacementObj, "displacement");
			MObject vectorDisplacementMapObj = getConnectedInNode(displacementObj, "vectorDisplacement");

			if( (displacementMapObj != MObject::kNullObj) && (displacementMapObj.hasFn(MFn::kFileTexture)))
			{
				MFnDependencyNode displacmentMapNode(displacementObj);				
				int dispMode = getEnumInt("displacementMode", displacmentMapNode);
				if (dispMode == 1)
					displacementMode = Corona::DisplacementMode::DISPLACEMENT_VECTOR_TANGENT;
				if (dispMode > 1)
					displacementMode = Corona::DisplacementMode::DISPLACEMENT_VECTOR_OBJECT;
				
				displacementAdaptive = getBoolAttr("mtco_displacementAdaptive", displacmentMapNode, false);
				getFloat("mtco_displacementMin", displacmentMapNode, displacementMin);
				getFloat("mtco_displacementMax", displacmentMapNode, displacementMax);
				MObject fileTextureObject = getConnectedInNode(displacementObj, "displacement");
				MString fileTexturePath = getConnectedFileTexturePath(MString("displacement"), displacmentMapNode);
				int vectorEncoding = getEnumInt("vectorEncoding", displacmentMapNode);
				if (vectorEncoding == 0) // absolute, no negative values
					diplacementIsHdr = false;

				if( fileTexturePath != "")
				{
					if( !textureFileSupported(fileTexturePath))
					{
						Logging::error(MString("File texture extension is not supported: ") + fileTexturePath);
					}else{
						MObject nullObj;
						mtco_MapLoader loader(fileTextureObject);
						displacementMap = loader.loadBitmap("");
						hasDisplacement = true;
					}
				}
			}
		}
	}
	
	MFnMesh meshFn(meshObject, &stat);
	CHECK_MSTATUS(stat);

	MPointArray points;
	MFloatVectorArray normals;
	MFloatArray uArray, vArray;
	MIntArray triPointIds, triNormalIds, triUvIds, triMatIds;
	Logging::debug("defineMesh pre getMeshData");
	obj->getMeshData(points, normals, uArray, vArray, triPointIds, triNormalIds, triUvIds, triMatIds);

	int numSteps = (int)obj->meshDataList.size();
	uint numVertices = points.length();
	uint numNormals = normals.length();
	uint numUvs = uArray.length();

	MString meshFullName = makeGoodString(meshFn.fullPathName());

	Corona::TriangleData td;
	Corona::IGeometryGroup* geom = nullptr;	
	geom = this->context.scene->addGeomGroup();
	geom->setMapChannelCount(1);

	// to capture the vertex and normal positions, we capture the data during the motion steps
	// and save them in a an std::vector. The uv's do not change, so we only sample them once.
	// we always have at least one motionstep even if we have no motionblur
	uint npts = 0;
	for( int mbStep = 0; mbStep < numSteps; mbStep++)
	{
		MeshData& md = obj->meshDataList[mbStep];
		if (md.points.length() != numVertices)
		{
			Logging::debug(MString("Error there is a mismatch between point data length and num vertices."));
			numSteps = 1;
			return;
		}
		if( mbStep > 0)
		{
			uint npts1 = md.points.length();
			if (npts1 != obj->meshDataList[0].points.length())
			{
				Logging::debug(MString("Error there is a mismatch between point data length between mb steps."));
				numSteps = 1;
				break;
			}
		}
		npts = md.points.length();
		for( uint vtxId = 0; vtxId < md.points.length(); vtxId++)
		{
			MPoint& p = md.points[vtxId];
			geom->getVertices().push(Corona::Pos(p.x,p.y,p.z));
		}
	
		for (uint nId = 0; nId < md.normals.length(); nId++)
		{
			MFloatVector& n =  md.normals[nId];
			geom->getNormals().push(Corona::Dir(n.x, n.y, n.z));
		}
	}

	for( uint tId = 0; tId < uArray.length(); tId++)
	{
		size_t mcl = geom->getMapCoordIndices().size();
		geom->getMapCoordIndices().push(mcl);
		geom->getMapCoords().push(Corona::Pos(uArray[tId], vArray[tId], 0.0f));
	}   

	obj->geom = geom;
	int numTris = triPointIds.length() / 3;
	
	for (uint triId = 0; triId < numTris; triId++)
	{
		uint index = triId * 3;
		int perFaceShadingGroup = triMatIds[triId];
		int vtxId0 = triPointIds[index];
		int vtxId1 = triPointIds[index + 1];
		int vtxId2 = triPointIds[index + 2];
		int normalId0 = triNormalIds[index];
		int normalId1 = triNormalIds[index + 1];
		int normalId2 = triNormalIds[index + 2];
		int uvId0 = triUvIds[index];
		int uvId1 = triUvIds[index + 1];
		int uvId2 = triUvIds[index + 2];

		if ((vtxId0 >= npts) || (vtxId1 >= npts) || (vtxId2 >= npts))
			Logging::error(MString("Index > npts!!! -- Obj: ") + obj->shortName);

		std::auto_ptr<Corona::TriangleData> trip;

		if (hasDisplacement)
		{
			std::auto_ptr<Corona::DisplacedTriangleData> dtrip = std::auto_ptr<Corona::DisplacedTriangleData>(new Corona::DisplacedTriangleData);
			dtrip->displacement.mode = displacementMode;
			dtrip->displacement.isHdr = diplacementIsHdr;	
			dtrip->displacement.mapChannel = 0;
			dtrip->displacement.map = displacementMap;
			dtrip->displacement.waterLevel = -Corona::INFINITY;
			dtrip->displacement.min = displacementMin;
			dtrip->displacement.max = displacementMax;
			dtrip->displacement.adaptive = displacementAdaptive;
			trip = dtrip;
		}
		else{
			trip = std::auto_ptr<Corona::TriangleData>(new Corona::TriangleData);
		}

		trip->v.setSegments(1 - 1); // fixme for deformation motionblur
		trip->n.setSegments(1 - 1); // fixme for deformation motionblur

		for (int stepId = 0; stepId < 1; stepId++)
		{
			trip->v[stepId][0] = vtxId0 + numVertices * stepId;
			trip->v[stepId][1] = vtxId1 + numVertices * stepId;
			trip->v[stepId][2] = vtxId2 + numVertices * stepId;
			trip->n[stepId][0] = normalId0 + numNormals * stepId;
			trip->n[stepId][1] = normalId1 + numNormals * stepId;
			trip->n[stepId][2] = normalId2 + numNormals * stepId;
		}

		if (numUvs > 0)
		{
			trip->t[0] = uvId0;
			trip->t[1] = uvId1;
			trip->t[2] = uvId2;
		}
		trip->materialId = perFaceShadingGroup;
		trip->edgeVis[0] = trip->edgeVis[1] = trip->edgeVis[2] = true;
		geom->addPrimitive(*trip);

	}
	//Logging::debug("}");
	obj->perFaceAssignments.clear();
	obj->meshDataList.clear();
}
예제 #6
0
void CoronaRenderer::updateLight(std::shared_ptr<MayaObject> mobj)
{
	std::shared_ptr<mtco_MayaObject> obj(std::static_pointer_cast<mtco_MayaObject>(mobj));

	if (obj->lightShader != nullptr)
	{
		if (this->context.scene->hasLightShader(obj->lightShader))
			this->context.scene->deleteLightShader(obj->lightShader);
	}
	if (obj->removed)
		return;

	if (MayaTo::getWorldPtr()->renderType == MayaTo::MayaToWorld::WorldRenderType::IPRRENDER)
	{
		obj->transformMatrices.clear();
		obj->transformMatrices.push_back(obj->dagPath.inclusiveMatrix());
	}
	MFnDependencyNode rGlNode(getRenderGlobalsNode());
	MObject coronaGlobals = getRenderGlobalsNode();
	std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr;
	std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr;

	MObjectArray nodeList;
	MStatus stat;

	MFnDependencyNode glFn(getRenderGlobalsNode());
	Corona::Rgb bgRgb = toCorona(getColorAttr("bgColor", glFn));
	int bgType = getEnumInt("bgType", glFn);

	MayaObject *sunLight = nullptr;

	MFnDependencyNode depFn(obj->mobject);

	if (obj->mobject.hasFn(MFn::kPointLight))
	{
		MColor col;
		getColor("color", depFn, col);
		float intensity = 1.0f;
		getFloat("intensity", depFn, intensity);
		int decay = 0;
		getEnum(MString("decayRate"), depFn, decay);
		MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix;
		Corona::Pos LP(m[3][0], m[3][1], m[3][2]);
		PointLight *pl = new PointLight;
		pl->LP = LP;
		pl->distFactor = 1.0 / renderGlobals->scaleFactor;
		pl->lightColor = Corona::Rgb(col.r, col.g, col.b);
		pl->lightIntensity = intensity;
		getEnum(MString("decayRate"), depFn, pl->decayType);
		pl->lightRadius = getFloatAttr("lightRadius", depFn, 0.0) * renderGlobals->scaleFactor;
		pl->doShadows = getBoolAttr("useRayTraceShadows", depFn, true);
		col = getColorAttr("shadowColor", depFn);
		pl->shadowColor = Corona::Rgb(col.r, col.g, col.b);
		for (auto excludedObj : obj->excludedObjects)
		{
			pl->excludeList.nodes.push(excludedObj.get());
		}
		this->context.scene->addLightShader(pl);
		obj->lightShader = pl;
	}
	if (obj->mobject.hasFn(MFn::kSpotLight))
	{
		MVector lightDir(0, 0, -1);
		MColor col;
		getColor("color", depFn, col);
		float intensity = 1.0f;
		getFloat("intensity", depFn, intensity);
		MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix;
		lightDir *= obj->transformMatrices[0] * renderGlobals->globalConversionMatrix;
		lightDir.normalize();
		Corona::Pos LP(m[3][0], m[3][1], m[3][2]);
		SpotLight *sl = new SpotLight;
		sl->LP = LP;
		sl->lightColor = Corona::Rgb(col.r, col.g, col.b);
		sl->lightIntensity = intensity;
		sl->LD = Corona::Dir(lightDir.x, lightDir.y, lightDir.z);
		sl->angle = 45.0f;
		sl->distFactor = 1.0 / renderGlobals->scaleFactor;
		getEnum(MString("decayRate"), depFn, sl->decayType);
		getFloat("coneAngle", depFn, sl->angle);
		getFloat("penumbraAngle", depFn, sl->penumbraAngle);
		getFloat("dropoff", depFn, sl->dropoff);
		sl->lightRadius = getFloatAttr("lightRadius", depFn, 0.0) * renderGlobals->scaleFactor;
		sl->doShadows = getBoolAttr("useRayTraceShadows", depFn, true);
		col = getColorAttr("shadowColor", depFn);
		sl->shadowColor = Corona::Rgb(col.r, col.g, col.b);
		for (auto excludedObj : obj->excludedObjects)
		{
			sl->excludeList.nodes.push(excludedObj.get());
		}
		Corona::AffineTm tm;
		setTransformationMatrix(sl->lightWorldInverseMatrix, m);
		ShadingNetwork network(obj->mobject);
		sl->lightColorMap = defineAttribute(MString("color"), depFn, network, oslRenderer);
		this->context.scene->addLightShader(sl);
		obj->lightShader = sl;
	}
	if (obj->mobject.hasFn(MFn::kDirectionalLight))
	{
		if (getBoolAttr("mtco_useAsSun", depFn, false))
		{
			if (sunLight != nullptr)
			{
				Logging::error(MString("A sun light is already defined, ignoring ") + obj->shortName);
				return;
			}
			sunLight = obj.get();
			MVector lightDir(0, 0, 1); // default dir light dir
			lightDir *= obj->transformMatrices[0];
			lightDir *= renderGlobals->globalConversionMatrix;
			lightDir.normalize();

			MColor sunColor(1);
			MFnDependencyNode sunNode(obj->mobject);
			getColor("color", sunNode, sunColor);
			sunColor *= getFloatAttr("intensity", sunNode, 1.0f);
			//float colorMultiplier colorMultiplier = getFloatAttr("mtco_sun_multiplier", sunNode, 1.0f);
			const float intensityFactor = (1.f - cos(Corona::SUN_PROJECTED_HALF_ANGLE)) / (1.f - cos(getFloatAttr("sunSizeMulti", rGlNode, 1.0f) * Corona::SUN_PROJECTED_HALF_ANGLE));
			sunColor *= intensityFactor * 1.0;// 2000000;
			Corona::Sun sun;

			Corona::ColorOrMap bgCoMap = this->context.scene->getBackground();
			SkyMap *sky = dynamic_cast<SkyMap *>(bgCoMap.getMap());
			Corona::Rgb avgColor(1, 1, 1);
			if (sky != nullptr)
			{
				avgColor = sky->sc();
			}

			Corona::Rgb sColor(sunColor.r, sunColor.g, sunColor.b);
			sun.color = sColor * avgColor;
			sun.active = true;
			sun.dirTo = Corona::Dir(lightDir.x, lightDir.y, lightDir.z).getNormalized();
			//sun.color = Corona::Rgb(sunColor.r,sunColor.g,sunColor.b);
			sun.visibleDirect = true;
			sun.visibleReflect = true;
			sun.visibleRefract = true;
			sun.sizeMultiplier = getFloatAttr("sunSizeMulti", rGlNode, 1.0);
			this->context.scene->getSun() = sun;
			if (sky != nullptr)
			{
				sky->initSky();
				this->context.scene->setBackground(bgCoMap);
				avgColor = sky->sc();
				this->context.scene->getSun().color = sColor * avgColor;
			}
		}
		else{
			MVector lightDir(0, 0, -1);
			MVector lightDirTangent(1, 0, 0);
			MVector lightDirBiTangent(0, 1, 0);
			MColor col;
			getColor("color", depFn, col);
			float intensity = 1.0f;
			getFloat("intensity", depFn, intensity);
			MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix;
			lightDir *= m;
			lightDirTangent *= m;
			lightDirBiTangent *= m;
			lightDir.normalize();

			Corona::Pos LP(m[3][0], m[3][1], m[3][2]);
			DirectionalLight *dl = new DirectionalLight;
			dl->LP = LP;
			dl->lightColor = Corona::Rgb(col.r, col.g, col.b);
			dl->lightIntensity = intensity;
			dl->LD = Corona::Dir(lightDir.x, lightDir.y, lightDir.z);
			dl->LT = Corona::Dir(lightDirTangent.x, lightDirTangent.y, lightDirTangent.z);
			dl->LBT = Corona::Dir(lightDirBiTangent.x, lightDirBiTangent.y, lightDirBiTangent.z);
			dl->lightAngle = getFloatAttr("lightAngle", depFn, 0.0);
			dl->doShadows = getBoolAttr("useRayTraceShadows", depFn, true);
			col = getColorAttr("shadowColor", depFn);
			dl->shadowColor = Corona::Rgb(col.r, col.g, col.b);
			for (auto excludedObj : obj->excludedObjects)
			{
				dl->excludeList.nodes.push(excludedObj.get());
			}

			this->context.scene->addLightShader(dl);
			obj->lightShader = dl;
		}
	}
	if (obj->mobject.hasFn(MFn::kAreaLight))
	{
		MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix;
		if ( obj->geom == nullptr)
			obj->geom = defineStdPlane();
		obj->geom->deleteAllInstances();

		Corona::AnimatedAffineTm atm;
		this->setAnimatedTransformationMatrix(atm, obj);
		obj->instance = obj->geom->addInstance(atm, nullptr, nullptr);
		if (getBoolAttr("mtco_envPortal", depFn, false))
		{
			Corona::EnviroPortalMtlData data;
			Corona::SharedPtr<Corona::IMaterial> mat = data.createMaterial();
			Corona::IMaterialSet ms = Corona::IMaterialSet(mat);
			obj->instance->addMaterial(ms);
		}
		else{
			Corona::NativeMtlData data;
			MColor lightColor = getColorAttr("color", depFn);
			float intensity = getFloatAttr("intensity", depFn, 1.0f);
			lightColor *= intensity;
			Corona::ColorOrMap com;
			// experimental direct corona texture
			if (getBoolAttr("mtco_noOSL", depFn, false))
			{
				MObject fileNode = getConnectedInNode(obj->mobject, "color");
				if ((fileNode != MObject::kNullObj) && (fileNode.hasFn(MFn::kFileTexture)))
				{
					MFnDependencyNode fileDep(fileNode);
					mtco_MapLoader loader(fileNode);
					Corona::SharedPtr<Corona::Abstract::Map> texmap = loader.loadBitmap("");
					com = Corona::ColorOrMap(bgRgb, texmap);
				}
			}
			else
			{
				com = defineAttribute(MString("color"), obj->mobject, oslRenderer);
				OSLMap *oslmap = (OSLMap *)com.getMap();
				if (oslmap != nullptr)
				{
					oslmap->multiplier = intensity;
				}
				else{
					Corona::Rgb col = com.getConstantColor() * intensity;
					com.setColor(col);
				}
			}

			data.emission.color = com;
			data.castsShadows = getBoolAttr("mtco_castShadows", depFn, false);

			for (auto excludedObj : obj->excludedObjects)
			{
				data.emission.excluded.nodes.push(excludedObj.get());
			}
			data.emission.disableSampling = false;
			data.emission.useTwoSidedEmission = getBoolAttr("mtco_doubleSided", depFn, false);

			Corona::SharedPtr<Corona::IMaterial> mat = data.createMaterial();
			Corona::IMaterialSet ms = Corona::IMaterialSet(mat);
			ms.visibility.direct = getBoolAttr("mtco_areaVisible", depFn, true);
			ms.visibility.reflect = getBoolAttr("mtco_visibleInReflection", depFn, true);
			ms.visibility.refract = getBoolAttr("mtco_visibleInRefraction", depFn, true);

			obj->instance->addMaterial(ms);
		}
	}
}
예제 #7
0
bool RenderGlobals::getDefaultGlobals()
{
	MSelectionList defaultGlobals;
	defaultGlobals.add("defaultRenderGlobals");

	if( defaultGlobals.length() == 0 )
	{
		Logging::debug("defaultRenderGlobals not found. Stopping.");
		return false;
	}
	MCommonRenderSettingsData data;
	MRenderUtil::getCommonRenderSettings(data);

	MObject node;
	defaultGlobals.getDependNode(0, node);
	MFnDependencyNode fnRenderGlobals(node);

	MTime tv = MAnimControl::currentTime();
	this->currentFrameNumber = (float)(tv.value());
	tv = data.frameStart;
	this->startFrame = (float)(tv.value());
	tv = data.frameEnd;
	this->endFrame = (float)(tv.value());
	tv = data.frameBy;
	this->byFrame = (float)(tv.value());

	// check if we are in a batch render mode or if we are rendering from UI
	if( MGlobal::mayaState() == MGlobal::kBatch )
	{
		this->inBatch = true;
		if( data.isAnimated() )
		{
			Logging::debug(MString("animation on, rendering frame sequence from ") + this->startFrame + " to " + this->endFrame);
			// these are the frames that are supposed to be rendered in batch mode
			this->doAnimation = true;
			for( double frame = this->startFrame; frame <= this->endFrame; frame += this->byFrame)
				this->frameList.push_back((float)frame);
		}else{
			Logging::debug(MString("animation off, rendering current frame"));
			this->frameList.push_back(this->currentFrameNumber );
			this->doAnimation = false;
		}
	}else{
		// we are rendering from the UI so only render the current frame
		this->inBatch = false;
		this->frameList.push_back(this->currentFrameNumber );
		this->doAnimation = false; // at the moment, if rendering comes from UI dont do animation
	}

	this->imgHeight = data.height;
	this->imgWidth = data.width;
	this->pixelAspect = data.pixelAspectRatio;
	
	this->regionLeft = 0;
	this->regionRight = this->imgWidth;
	this->regionBottom = 0;
	this->regionTop = this->imgHeight;

	regionLeft = getIntAttr("left", fnRenderGlobals, 0);
	regionRight = getIntAttr("rght", fnRenderGlobals, imgWidth);
	regionBottom = getIntAttr("bot", fnRenderGlobals, 0);
	regionTop = getIntAttr("top", fnRenderGlobals, imgHeight);

	getBool(MString("enableDefaultLight"), fnRenderGlobals, this->createDefaultLight);

	getString(MString("preRenderMel"), fnRenderGlobals, this->preFrameScript);
	getString(MString("postRenderMel"), fnRenderGlobals, this->postFrameScript);
	getString(MString("preRenderLayerMel"), fnRenderGlobals, this->preRenderLayerScript);
	getString(MString("postRenderLayerMel"), fnRenderGlobals, this->postRenderLayerScript);

	MFnDependencyNode depFn(getRenderGlobalsNode());
	this->maxTraceDepth = getIntAttr("maxTraceDepth", depFn, 4);
	this->doMb = getBoolAttr("doMotionBlur", depFn, false);
	this->doDof = getBoolAttr("doDof", depFn, false);
	this->motionBlurRange = getFloatAttr("motionBlurRange", depFn, 0.4f);
	this->motionBlurType = 0; // center
	this->xftimesamples = getIntAttr("xftimesamples", depFn, 2);
	this->geotimesamples = getIntAttr("geotimesamples", depFn, 2);
	this->createDefaultLight = false;
	this->renderType = RenderType::FINAL;
	this->exportSceneFile = getBoolAttr("exportSceneFile", depFn, false);
	this->adaptiveSampling = getBoolAttr("adaptiveSampling", depFn, false);
	this->imageName = getStringAttr("imageName", depFn, "");
	this->basePath = getStringAttr("basePath", depFn, "");
	this->exportSceneFileName = getStringAttr("exportSceneFileName", depFn, "");
	this->imagePath = getStringAttr("imagePath", depFn, "");
	this->threads = getIntAttr("threads", depFn, 4);
	this->translatorVerbosity = getEnumInt("translatorVerbosity", depFn);
	this->rendererVerbosity = getEnumInt("rendererVerbosity", depFn);
	this->useSunLightConnection = getBoolAttr("useSunLightConnection", depFn, false);
	this->tilesize = getIntAttr("tileSize", depFn, 64);
	this->sceneScale = getFloatAttr("sceneScale", depFn, 1.0f);
	this->filterSize = getFloatAttr("filterSize", depFn, 3.0f);
	this->good = true;
	return true;
}
예제 #8
0
void CoronaRenderer::defineSettings()
{
	MFnDependencyNode depFn(getRenderGlobalsNode());
	std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr;
	int w = renderGlobals->getWidth();
	int h = renderGlobals->getHeight();
	context.settings->set(Corona::PARAM_IMAGE_WIDTH, w);
	context.settings->set(Corona::PARAM_IMAGE_HEIGHT, h);

	if (MayaTo::getWorldPtr()->renderType == MayaTo::MayaToWorld::WorldRenderType::IPRRENDER)
		context.settings->set(Corona::PARAM_MINIMIZE_PRECOMP, true);

	if (getBoolAttr("lockSamplingPattern",depFn, false))
		context.settings->set(Corona::PARAM_RANDOM_SEED, 1234);
	else
		context.settings->set(Corona::PARAM_RANDOM_SEED, 0);

	if (renderGlobals->getUseRenderRegion())
	{
		int left, bottom, right, top;
		renderGlobals->getRenderRegion(left, bottom, right, top);
		context.settings->set(Corona::PARAM_IMAGE_REGION_START_X, left);
		context.settings->set(Corona::PARAM_IMAGE_REGION_START_Y, bottom);
		context.settings->set(Corona::PARAM_IMAGE_REGION_END_X, right);
		context.settings->set(Corona::PARAM_IMAGE_REGION_END_Y, top);
	}

	int renderer = getIntAttr("renderer", depFn, 0);
	if( renderer == 0) // progressive
		context.settings->set(Corona::PARAM_RENDER_ENGINE, Corona::RENDER_ENGINE_PROGRESSIVE);
	if( renderer == 1) // bucket rendering
		context.settings->set(Corona::PARAM_RENDER_ENGINE, Corona::RENDER_ENGINE_BUCKET);
	if( renderer == 2) // vcm rendering
		context.settings->set(Corona::PARAM_RENDER_ENGINE, Corona::RENDER_ENGINE_VCM);

	//context.settings->set(Corona::PARAM_RESUME_RENDERING, false);
	
	context.settings->set(Corona::PARAM_BUCKET_SIZE, getIntAttr("image_bucketSize", depFn, 64));
	context.settings->set(Corona::PARAM_BUCKET_SAMPLES_PER_ITERATION, getIntAttr("buckets_initialSamples", depFn, 4));
	context.settings->set(Corona::PARAM_BUCKET_PASSES, getIntAttr("buckets_adaptiveSteps", depFn, 4));
	context.settings->set(Corona::PARAM_BUCKET_ADAPTIVE_THRESHOLD, getFloatAttr("buckets_adaptiveThreshold", depFn, 0.03f));

	context.settings->set(Corona::PARAM_PROGRESSIVE_PASS_LIMIT, getIntAttr("progressive_maxPasses", depFn, 0));
	context.settings->set(Corona::PARAM_PROGRESSIVE_TIME_LIMIT, getIntAttr("progressive_timeLimit", depFn, 60) * 1000);

	context.settings->set(Corona::PARAM_VCM_MODE, getEnumInt("vcm_mode", depFn));
	context.settings->set(Corona::PARAM_PPM_INITIAL_RADIUS, getFloatAttr("ppm_initialRadius", depFn, 2.0f));
	//context.settings->set(Corona::PARAM_BIDIR_DO_MIS, getBoolAttr("bidir_doMis", depFn, true));
	context.settings->set(Corona::PARAM_PPM_PHOTONS_PER_ITER, getIntAttr("ppm_photonsPerIter", depFn, 5000000));
	context.settings->set(Corona::PARAM_PPM_ALPHA, getFloatAttr("ppm_alpha", depFn, .666f));

	context.settings->set(Corona::PARAM_MAX_SAMPLE_INTENSITY, getFloatAttr("maxPtSampleIntensity", depFn, 20.0f));	
	context.settings->set(Corona::PARAM_NUM_THREADS, getIntAttr("threads", depFn, 4));

	if (getBoolAttr("exportSceneFile", depFn, false))
		context.settings->set(Corona::PARAM_EXPORT_PATH, renderGlobals->exportSceneFileName.asChar());
	 
	context.settings->set(Corona::PARAM_THREAD_PRIORITY, Corona::IScheduler::PRIORITY_BELOW_NORMAL); // always render with low priority

	Corona::DisplaceSubdivType subdivTypes[] = { Corona::DisplaceSubdivType::DISPLACE_SUBDIV_WORLD, Corona::DisplaceSubdivType::DISPLACE_SUBDIV_PROJECTED };
	context.settings->set(Corona::PARAM_DISPLACE_SUBDIV_TYPE, subdivTypes[(int)getBoolAttr("displace_useProjectionSize", depFn, true)]);
	context.settings->set(Corona::PARAM_DISPLACE_MAX_SIZE_SCREEN, getFloatAttr("displace_maxProjectSize", depFn, 2.0f));
	context.settings->set(Corona::PARAM_DISPLACE_MAX_SIZE_WORLD, getFloatAttr("displace_maxWorldSize", depFn, 1.0f));

	context.settings->set(Corona::PARAM_MAX_RAY_DEPTH, getIntAttr("raycaster_maxDepth", depFn, 25));
	context.settings->set(Corona::PARAM_MIN_INSTANCE_SAVING, getIntAttr("instance_minSize", depFn, 50000));

	int f = getEnumInt("filtertype", depFn);
	float fw = getFloatAttr("imagefilter_width", depFn, 1.5f);
	float fb = getFloatAttr("imagefilter_blurring", depFn, .5f);
	context.settings->set(Corona::PARAM_IMAGEFILTER, getEnumInt("filtertype", depFn));
	context.settings->set(Corona::PARAM_IMAGEFILTER_WIDTH, getFloatAttr("imagefilter_width", depFn, 1.5f));
	context.settings->set(Corona::PARAM_IMAGEFILTER_BLURRING, getFloatAttr("imagefilter_blurring", depFn, .5f));

	context.settings->set(Corona::PARAM_SHADING_ENABLE, getBoolAttr("doShading", depFn, true));

	Corona::GiSolverType solverTypes[] = { Corona::GiSolverType::GISOLVER_NONE, Corona::GiSolverType::GISOLVER_PATHTRACING, Corona::GiSolverType::GISOLVER_HD_CACHE, Corona::GiSolverType::GISOLVER_UHD_CACHE };
	context.settings->set(Corona::PARAM_SHADING_PRIMARY_SOLVER, solverTypes[getEnumInt("gi_primarySolver", depFn)]);
	context.settings->set(Corona::PARAM_SHADING_SECONDARY_SOLVER, solverTypes[getEnumInt("gi_secondarySolver", depFn)]);

	context.settings->set(Corona::PARAM_GI_TO_AA_RATIO, getIntAttr("pathtracingSamples", depFn, 16));
	//context.settings->set(Corona::PARAM_LIGHT_SAMPLES_MULT, getFloatAttr("lights_areaSamplesMult", depFn, 2.0f));

	context.settings->set(Corona::PARAM_HDCACHE_SAVE, getBoolAttr("gi_saveSecondary", depFn, false));
	context.settings->set(Corona::PARAM_HDCACHE_PRECALC_MODE, getEnumInt("gi_hdCache_precalcMode", depFn));
	context.settings->set(Corona::PARAM_HDCACHE_FILE, Corona::String(getStringAttr("gi_secondaryFile", depFn, "").asChar()));
	context.settings->set(Corona::PARAM_HDCACHE_PRECOMP_DENSITY, getFloatAttr("gi_hdCache_precompMult", depFn, 1.0f));
	context.settings->set(Corona::PARAM_HDCACHE_INTERPOLATION_COUNT, getIntAttr("gi_hdCache_interpolationCount", depFn, 3));
	context.settings->set(Corona::PARAM_HDCACHE_RECORD_QUALITY, getIntAttr("gi_hdCache_ptSamples", depFn, 256));
	context.settings->set(Corona::PARAM_HDCACHE_SMOOTHING, getFloatAttr("gi_hdCache_smoothing", depFn, 2.0f));
	context.settings->set(Corona::PARAM_HDCACHE_MAX_RECORDS, getIntAttr("gi_hdCache_maxRecords", depFn, 100000));
	context.settings->set(Corona::PARAM_HDCACHE_GLOSS_THRESHOLD, getFloatAttr("gi_hdCache_glossyThreshold", depFn, .9f));
	context.settings->set(Corona::PARAM_HDCACHE_WRITABLE_PASSES, getIntAttr("gi_hdCache_writePasses", depFn, 0));
	context.settings->set(Corona::PARAM_HDCACHE_DIR_SENSITIVITY, getFloatAttr("gi_hdCache_dirSensitivity", depFn, 2.0f));
	context.settings->set(Corona::PARAM_HDCACHE_POS_SENSITIVITY, getFloatAttr("gi_hdCache_posSensitivity", depFn, 20.0f));
	context.settings->set(Corona::PARAM_HDCACHE_NORMAL_SENSITIVITY, getFloatAttr("gi_hdCache_normalSensitivity", depFn, 3.0f));

	float uhd_precision = getFloatAttr("uhdPrecision", depFn, 1.0f);
	context.settings->set(Corona::PARAM_UHDCACHE_PRECISION, uhd_precision);

	int uhd_recordQuality = 512;
	float uhd_strictness = 0.075f;
	float uhd_msi = 3.0f;
	int uhdType = getEnumInt("uhdCacheType", depFn);
	if (getEnumInt("gi_secondarySolver", depFn) == 4) // uhd cache
	{
		// 0 == still, 1 == animation. Only animation needs not default settings.
		if (uhdType == 1)
		{
			context.settings->set(Corona::PARAM_UHDCACHE_MSI, uhd_msi * 3.0f);
			context.settings->set(Corona::PARAM_UHDCACHE_RECORD_QUALITY, uhd_recordQuality * .5f);
			context.settings->set(Corona::PARAM_UHDCACHE_STRICTNESS, uhd_strictness * .33f);
			context.settings->set(Corona::PARAM_UHDCACHE_PRECISION, uhd_precision * .4f);
		}
	}

	float gamma = 2.2f;
#if MAYA_API_VERSION > 2015
	if (MColorManagementUtilities::isColorManagementEnabled())
		gamma = 1.0f;
#endif
	context.settings->set(Corona::PARAM_COLORMAP_GAMMA, gamma);
	context.settings->set(Corona::PARAM_COLORMAP_HIGHLIGHT_COMPRESSION, getFloatAttr("colorMapping_highlightCompression", depFn, 1.0f));
	context.settings->set(Corona::PARAM_COLORMAP_CONTRAST, getFloatAttr("colorMapping_contrast", depFn, 1.0f));

	context.settings->set(Corona::PARAM_COLORMAP_COLOR_TEMP, getFloatAttr("colorMapping_colorTemperature", depFn, 6500.0f));
	context.settings->set(Corona::PARAM_COLORMAP_SIMPLE_EXPOSURE, getFloatAttr("colorMapping_simpleExposure", depFn, 0.0f));
	context.settings->set(Corona::PARAM_COLORMAP_TINT, toCorona(getColorAttr("colorMapping_tint", depFn)));
	context.settings->set(Corona::PARAM_COLORMAP_USE_PHOTOGRAPHIC, !getBoolAttr("colorMapping_useSimpleExposure", depFn, true));

	context.settings->set(Corona::PARAM_COLORMAP_ISO, getFloatAttr("colorMapping_iso", depFn, 100.0));
	context.settings->set(Corona::PARAM_COLORMAP_F_STOP, getFloatAttr("colorMapping_fStop", depFn, 5.6));
	context.settings->set(Corona::PARAM_COLORMAP_SHUTTER_SPEED, 1.0f / getFloatAttr("colorMapping_shutterSpeed", depFn, 250.0f));
	// v2.8 exposure from camera
	std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr;
	if (mayaScene)
	{
		for (auto cam : mayaScene->camList)
		{
			if (!isCameraRenderable(cam->mobject) && (!(cam->dagPath == mayaScene->uiCamera)))
				continue;
			MFnDependencyNode camFn(cam->mobject);
			if (getBoolAttr("mtco_overrideRenderSettings", camFn, false))
			{
				context.settings->set(Corona::PARAM_COLORMAP_ISO, getFloatAttr("mtco_iso", camFn, 1.0));
				context.settings->set(Corona::PARAM_COLORMAP_F_STOP, getFloatAttr("fStop", camFn, 5.6));
				context.settings->set(Corona::PARAM_COLORMAP_SHUTTER_SPEED, 1.0f / getFloatAttr("mtco_shutterSpeed", camFn, 250.0f));
			}
			break;
		}
	}
}
예제 #9
0
void TheaRenderer::defineEnvironment()
{
	MFnDependencyNode gFn(getRenderGlobalsNode());
	std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr;
	std::shared_ptr<TheaRenderer> renderer = std::static_pointer_cast<TheaRenderer>(MayaTo::getWorldPtr()->worldRendererPtr);

	if( renderGlobals->exportSceneFile )
	{	
		TheaSDK::XML::EnvironmentOptions env;	
		int illumination = getEnumInt("illumination", gFn);
		switch (illumination)
		{
		case 0:
			break;
		case 1: // dome light
			{
				env.illumination = TheaSDK::DomeIllumination;
				MColor bg = getColorAttr("backgroundColor", gFn);
				TheaSDK::Rgb bgColor(bg.r, bg.g, bg.b);
				env.backgroundColor = bgColor;
			}
			break;
		case 2: // ibl
			{
				env.illumination = TheaSDK::IBLIllumination;
				defineIBLNode(env.illuminationMap, "illuminationMap");
				defineIBLNode(env.backgroundMap, "backgroundMap");
				defineIBLNode(env.reflectionMap, "reflectionMap");
				defineIBLNode(env.refractionMap, "refractionMap");
			}
			break;
		case 3: // physical sky
			{
				env.illumination = TheaSDK::PhysicalSkyIllumination;
				env.turbidity = getFloatAttr("turbidity", gFn, 2.5f);
				env.ozone = getFloatAttr("ozone", gFn, 0.35f);
				env.waterVapor = getFloatAttr("waterVapor", gFn, 2.0f);
				env.turbidityCoefficient = getFloatAttr("turbidityCoefficient", gFn, .046f);
				env.wavelengthExponent = getFloatAttr("wavelengthExponent", gFn, 1.3f);
				env.albedo = getFloatAttr("albedo", gFn, .5f);

				env.location = getStringAttr("location", gFn, "").asChar();

				env.timezone = getIntAttr("timezone", gFn, 0); // from -12 to +12.
				env.date = getStringAttr("date", gFn, "").asChar(); // format dd/mm/yy.
				env.localtime = getStringAttr("localtime", gFn, "").asChar(); // format hh/mm/ss.

				env.latitude = getFloatAttr("latitude", gFn, .0f);
				env.longitude = getFloatAttr("longitude", gFn, .0f);

				env.sunDirection = this->getSunDirection();
				env.sunPolarAngle = getFloatAttr("sunPolarAngle", gFn, -1.0f); // in degrees.
				env.sunAzimuth = getFloatAttr("sunAzimuth", gFn, -1.0f); // in degrees.
			}
			break;
		default:
			break;				
		};

		if (illumination > 0)
		{
			this->sceneXML.setEnvironmentOptions(env);
		}

	}else{
		if (TheaSDK::SetRgbParameter(TheaSDK::GetGlobalSettings(),"Background Color",TheaSDK::Rgb(0.1f,0.1f,0.6f))==false)
			return;
		if (TheaSDK::SetStringParameter(TheaSDK::GetGlobalSettings(),"Background Type","Background Color")==false)
			return;

		if (TheaSDK::SetRealParameter(TheaSDK::GetGlobalSettings(),"./Sun/Polar Angle (deg)",45)==false)
			return ;
		if (TheaSDK::SetRealParameter(TheaSDK::GetGlobalSettings(),"./Sun/Azimuth (deg)",45)==false)
			return;
		if (TheaSDK::SetStringParameter(TheaSDK::GetGlobalSettings(),"Illumination","Physical Sky")==false)
			return;
		if (TheaSDK::SetIntegerParameter(TheaSDK::GetRootObject(),"GenerateSun",2)==false)
			return;
	}
}
예제 #10
0
void IndigoRenderer::defineEnvironment()
{

	std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr;
	std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr;

	MFnDependencyNode gFn(getRenderGlobalsNode());

	switch (getEnumInt("environmentType", gFn))
	{
		case 0: // off
		{ 
			break;
		}
		case 1: // environment light map
		{
			MString texName;
			bool useTexture = false;
			Indigo::String texturePath = "";
			MObject fileTexObj;
			if( getConnectedFileTexturePath(MString("environmentColor"), MString("indigoGlobals"), texName, fileTexObj) )
			{
				useTexture = true;
				texturePath = texName.asChar();
			}
			MFnDependencyNode fileTexNode(fileTexObj);
			MColor bgColor = getColorAttr("environmentColor", gFn);
			int mapType = getIntAttr("environmentMapType", gFn, 0);
			Indigo::SceneNodeBackgroundSettingsRef background_settings(new Indigo::SceneNodeBackgroundSettings());
			Reference<Indigo::DiffuseMaterial> mat(new Indigo::DiffuseMaterial());
			// Albedo should be zero.
			mat->albedo = Reference<Indigo::WavelengthDependentParam>(new Indigo::ConstantWavelengthDependentParam(Reference<Indigo::Spectrum>(new Indigo::UniformSpectrum(0))));
			Indigo::Texture texture;

			if( useTexture )
			{
				texture.path = texturePath;
				texture.exponent = 1; // Since we will usually use a HDR image, the exponent (gamma) should be set to one.
				MColor colorGain(1,1,1);
				getColor("colorGain", fileTexNode, colorGain);
				MColor colorOffset(0,0,0);
				getColor("colorOffset", fileTexNode, colorOffset);
				double cg = (colorGain.r + colorGain.g + colorGain.b) / 3.0;
				double co = (colorOffset.r + colorOffset.g + colorOffset.b) / 3.0;
				texture.a = 0.0;
				texture.b = cg;
				texture.c = co;
				texture.tex_coord_generation = Reference<Indigo::TexCoordGenerator>(new Indigo::SphericalTexCoordGenerator(Reference<Indigo::Rotation>(new Indigo::MatrixRotation())));
				if( mapType == 1 )
				{
					texture.tex_coord_generation = Reference<Indigo::TexCoordGenerator>(new Indigo::SphericalEnvTexCoordGenerator(Reference<Indigo::Rotation>(new Indigo::MatrixRotation())));
				}
				mat->emission = Reference<Indigo::WavelengthDependentParam>(new Indigo::TextureWavelengthDependentParam(0));
				mat->textures.push_back(texture);
			}else{
				Indigo::RGBSpectrum *iBgColor = new Indigo::RGBSpectrum(Indigo::Vec3d(bgColor.r,bgColor.g,bgColor.b), 2.2);
				mat->emission = Reference<Indigo::WavelengthDependentParam>(new Indigo::ConstantWavelengthDependentParam(Reference<Indigo::Spectrum>(iBgColor)));
			}

			// Base emission is the emitted spectral radiance. No effect here?
			double multiplier = (double)getFloatAttr("environmentMapMultiplier", gFn, 1.0) * 1000.0;
			mat->base_emission = Reference<Indigo::WavelengthDependentParam>(new Indigo::ConstantWavelengthDependentParam(Reference<Indigo::Spectrum>(new Indigo::UniformSpectrum(multiplier))));

			background_settings->background_material = mat;
			sceneRootRef->addChildNode(background_settings);
			break;
		}
		case 2: // sun/sky
		{
			// first get the globals node and serach for a directional light connection
			MObjectArray nodeList;
			getConnectedInNodes(MString("sunLightConnection"), gFn.object(), nodeList);
			if( nodeList.length() > 0)
			{
				MObject sunObj = nodeList[0];
				if(sunObj.hasFn(MFn::kTransform))
				{
					// we suppose what's connected here is a dir light transform
					MVector lightDir(0,0,1); // default dir light dir
					MFnDagNode sunDagNode(sunObj);
					lightDir *= sunDagNode.transformationMatrix() * renderGlobals->globalConversionMatrix;
					lightDir.normalize();

					Indigo::SceneNodeBackgroundSettingsRef background_settings_node(new Indigo::SceneNodeBackgroundSettings());
					Reference<Indigo::SunSkyMaterial> sun_sky_mat(new Indigo::SunSkyMaterial());
					
					MString sky_model;
					int modelId;
					getEnum("sky_model", gFn, modelId, sky_model);
					sun_sky_mat->model = sky_model.asChar();
					sun_sky_mat->enable_sky = true;
					getBool("extra_atmospheric", gFn, sun_sky_mat->extra_atmospheric);
					sun_sky_mat->name = "sunsky";
					getUInt("sky_layer", gFn, sun_sky_mat->sky_layer);
					getUInt("sun_layer", gFn, sun_sky_mat->sun_layer);
					getDouble(MString("turbidity"), gFn, sun_sky_mat->turbidity);

					sun_sky_mat->sundir = Indigo::Vec3d(lightDir.x, lightDir.y, lightDir.z); // Direction to sun.

					background_settings_node->background_material = sun_sky_mat;
					sceneRootRef->addChildNode(background_settings_node);
				}
			}

			break;
		}
	}
}