예제 #1
0
void CarReflection::Create()
{
	//bFirstFrame = true;
	if (pSet->refl_mode == 1)  cubetexName = "ReflectionCube"; // single: use 1st cubemap
	else if (pSet->refl_mode == 2)
	{
		cubetexName = "ReflectionCube" + toStr(iIndex);
		// first cubemap: no index
		if (cubetexName == "ReflectionCube0")
			cubetexName = "ReflectionCube";
	}
	else /* static */
		cubetexName = "ReflectionCube";
	
	TextureManager* tm = TextureManager::getSingletonPtr();
	int size = ciShadowSizesA[pSet->refl_size];  // /2 ?

	//  create cube render texture
	if ( !(pSet->refl_mode == 1 && iIndex != 0) )
	{
		cubetex = tm->createManual(cubetexName, 
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_CUBE_MAP, 
			size,size, 0/*mips*/, PF_R8G8B8, TU_RENDERTARGET);
			//LogO("created rt cube");

		for (int face = 0; face < 6; face++)
		{
			Camera* mCam = pSceneMgr->createCamera("Reflect_" + toStr(iIndex) + "_" + toStr(face));
			mCam->setAspectRatio(1.0f);  mCam->setFOVy(Degree(90));
			mCam->setNearClipDistance(0.1);
			mCam->setFarClipDistance(pSet->refl_dist * 1.1f);

			RenderTarget* mRT = cubetex->getBuffer(face)->getRenderTarget();
			//LogO( "rt face Name: " + mRT->getName() );
			mRT->removeAllViewports();
			Viewport* vp = mRT->addViewport(mCam);
			vp->setOverlaysEnabled(false);
			vp->setVisibilityMask(RV_MaskReflect);
			vp->setShadowsEnabled(false);
			vp->setMaterialScheme ("reflection");
			mRT->setAutoUpdated(false);
			//mRT->addListener(this);  //-
			mCam->setPosition(Vector3::ZERO);

			Vector3 lookAt(0,0,0), up(0,0,0), right(0,0,0);  switch(face)
			{
				case 0:  lookAt.x =-1;  up.y = 1;  right.z = 1;  break;  // +X
				case 1:  lookAt.x = 1;  up.y = 1;  right.z =-1;  break;	 // -X
				case 2:  lookAt.y =-1;  up.z = 1;  right.x = 1;  break;	 // +Y
				case 3:  lookAt.y = 1;  up.z =-1;  right.x = 1;  break;	 // -Y
				case 4:  lookAt.z = 1;  up.y = 1;  right.x =-1;  break;	 // +Z
				case 5:  lookAt.z =-1;  up.y = 1;  right.x =-1;  break;	 // -Z
			}
			Quaternion orient( right, up, lookAt );  mCam->setOrientation( orient );
			pCams[face] = mCam;
			pRTs[face] = mRT;
		}
	}
}
예제 #2
0
    DepthRenderer::DepthRenderer
    (
        Viewport* masterViewport
    ):
        mMasterViewport (masterViewport),
        mDepthRenderViewport (0),
        mDepthRenderingNow (false),
        mViewportVisibilityMask (~0),
        mUseCustomDepthScheme (true),
        mCustomDepthSchemeName (DEFAULT_CUSTOM_DEPTH_SCHEME_NAME)
    {
        disableRenderGroupRangeFilter ();

		Ogre::String uniqueId = Ogre::StringConverter::toString ((size_t)this);

        // Not cloned!
        mDepthRenderMaterial = MaterialManager::getSingleton ().getByName ("Caelum/DepthRender");
        mDepthRenderMaterial->load();
        if (!mDepthRenderMaterial->getBestTechnique ()) {
            CAELUM_THROW_UNSUPPORTED_EXCEPTION (
                    "Can't load depth render material: " +
                    mDepthRenderMaterial->getUnsupportedTechniquesExplanation(),
                    "DepthComposer");
        }

        TextureManager* texMgr = TextureManager::getSingletonPtr();

        int width = getMasterViewport ()->getActualWidth ();
        int height = getMasterViewport ()->getActualHeight ();
        LogManager::getSingleton ().logMessage (
                    "Caelum::DepthRenderer: Creating depth render texture size " +
                    StringConverter::toString (width) + 
                    "x" + 
                    StringConverter::toString (height));

        PixelFormat desiredFormat = PF_FLOAT32_R;
        PixelFormat requestFormat = desiredFormat;
        if (texMgr->isFormatSupported (TEX_TYPE_2D, desiredFormat, TU_RENDERTARGET)) {
            LogManager::getSingleton ().logMessage (
                    "Caelum::DepthRenderer: RenderSystem has native support for " +
                    PixelUtil::getFormatName (desiredFormat));
        } else if (texMgr->isEquivalentFormatSupported (TEX_TYPE_2D, desiredFormat, TU_RENDERTARGET)) {
            PixelFormat equivFormat = texMgr->getNativeFormat (TEX_TYPE_2D, desiredFormat, TU_RENDERTARGET);
            LogManager::getSingleton ().logMessage (
                    "Caelum::DepthRenderer: RenderSystem supports " +
                    PixelUtil::getFormatName (equivFormat) +
                    " instead of " +
                    PixelUtil::getFormatName (desiredFormat));
            requestFormat = equivFormat;
        } else {
            CAELUM_THROW_UNSUPPORTED_EXCEPTION (
                    PixelUtil::getFormatName(desiredFormat) + " or equivalent not supported",
                    "DepthRenderer");
        }

        if (texMgr->isHardwareFilteringSupported (TEX_TYPE_2D, requestFormat, TU_RENDERTARGET)) {
            LogManager::getSingleton ().logMessage (
                    "Caelum::DepthRenderer: RenderSystem supports hardware filtering for " +
                    PixelUtil::getFormatName (requestFormat));
        } else {
            LogManager::getSingleton ().logMessage (
                    "Caelum::DepthRenderer: RenderSystem does not support hardware filtering for " +
                    PixelUtil::getFormatName (requestFormat));
        }

        // Create depth texture.
        // This depends on the size of the viewport.
        mDepthRenderTexture = texMgr->createManual(
                "Caelum/DepthComposer/" + uniqueId + "/DepthTexture",
                Caelum::RESOURCE_GROUP_NAME,
                TEX_TYPE_2D,
                width, height, 1,
                0,
                requestFormat,
                TU_RENDERTARGET,
                0);

        assert(getDepthRenderTarget());

        // Should be the same format
        LogManager::getSingleton().logMessage (
                "Caelum::DepthRenderer: Created depth render texture"
                " actual format " + PixelUtil::getFormatName (getDepthRenderTexture()->getFormat ()) +
                " desired format " + PixelUtil::getFormatName (getDepthRenderTexture()->getDesiredFormat ()));

        // We do our updates by hand.
        getDepthRenderTarget()->setAutoUpdated (false);

        // Viewport for the depth rtt. Don't set camera here; it can mess Camera::getViewport();
        mDepthRenderViewport = getDepthRenderTarget()->addViewport(0);
        getDepthRenderViewport ()->setShadowsEnabled (false);
        getDepthRenderViewport ()->setOverlaysEnabled (false);
        getDepthRenderViewport ()->setClearEveryFrame (true);

        // Depth buffer values range from 0 to 1 in both OpenGL and Directx; unless depth ranges are used.
        // Clear to the maximum value.
        getDepthRenderViewport ()->setBackgroundColour (Ogre::ColourValue (1, 1, 1, 1));
    }
예제 #3
0
void CarReflection::Create()
{
	bFirstFrame = true;
	if (pSet->refl_mode == "single")  cubetexName = "ReflectionCube"; // single: use 1st cubemap
	else if (pSet->refl_mode == "full")
	{
		cubetexName = "ReflectionCube" + toStr(iIndex);
		// first cubemap: no index
		if (cubetexName == "ReflectionCube0")
			cubetexName = "ReflectionCube";
	}
	else /* static */
		cubetexName = "ReflectionCube";
	
	TextureManager* tm = TextureManager::getSingletonPtr();
	int size = ciShadowSizesA[pSet->refl_size];  // /2 ?

	//  create cube render texture
	if (! (pSet->refl_mode == "single" && iIndex != 0) )
	{
		cubetex = tm->createManual(cubetexName, 
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_CUBE_MAP, 
			size,size, 0/*mips*/, PF_R8G8B8, TU_RENDERTARGET);
			//LogO("created rt cube");

		for (int face = 0; face < 6; face++)
		{
			Camera* mCam = pSceneMgr->createCamera("Reflect_" + toStr(iIndex) + "_" + toStr(face));
			mCam->setAspectRatio(1.0f);  mCam->setFOVy(Degree(90));
			mCam->setNearClipDistance(0.1);
			//mCam->setFarClipDistance(pSet->refl_dist);  //sky-

			RenderTarget* mRT = cubetex->getBuffer(face)->getRenderTarget();
			//LogO( "rt face Name: " + mRT->getName() );
			mRT->removeAllViewports();
			Viewport* vp = mRT->addViewport(mCam);
			vp->setOverlaysEnabled(false);
			vp->setVisibilityMask(RV_MaskReflect);
			mRT->setAutoUpdated(false);
			//mRT->addListener(this);  //-
			mCam->setPosition(Vector3::ZERO);

			Vector3 lookAt(0,0,0), up(0,0,0), right(0,0,0);  switch(face)
			{
				case 0:  lookAt.x =-1;  up.y = 1;  right.z = 1;  break;  // +X
				case 1:  lookAt.x = 1;  up.y = 1;  right.z =-1;  break;	 // -X
				case 2:  lookAt.y =-1;  up.z = 1;  right.x = 1;  break;	 // +Y
				case 3:  lookAt.y = 1;  up.z =-1;  right.x = 1;  break;	 // -Y
				case 4:  lookAt.z = 1;  up.y = 1;  right.x =-1;  break;	 // +Z
				case 5:  lookAt.z =-1;  up.y = 1;  right.x =-1;  break;	 // -Z
			}
			Quaternion orient( right, up, lookAt );  mCam->setOrientation( orient );
			pCams[face] = mCam;
			pRTs[face] = mRT;
		}
	}
	
	// Iterate through our materials and add an index to ReflectionCube texture reference
	for (int i=0; i < NumMaterials; i++)
	{
		MaterialPtr mtr = MaterialManager::getSingleton().getByName(sMtr[i]);
		if (!mtr.isNull())
		{	Material::TechniqueIterator techIt = mtr->getTechniqueIterator();
			while (techIt.hasMoreElements())
			{	Technique* tech = techIt.getNext();
				Technique::PassIterator passIt = tech->getPassIterator();
				while (passIt.hasMoreElements())
				{	Pass* pass = passIt.getNext();
					Pass::TextureUnitStateIterator tusIt = pass->getTextureUnitStateIterator();
					while (tusIt.hasMoreElements())
					{	
						TextureUnitState* tus = tusIt.getNext();
						if (tus->getTextureName() == "ReflectionCube")
							tus->setTextureName(cubetexName);
	}	}	}	}	}
}