//-----------------------------------------------------------------------------
void SGMaterialSerializerListener::materialEventRaised(MaterialSerializer* ser, 
														MaterialSerializer::SerializeEvent event, 
														bool& skip, const Material* mat)
{
	if (event == MaterialSerializer::MSE_PRE_WRITE)
	{
		MaterialPtr matPtr = MaterialManager::getSingleton().getByName(mat->getName());
		mSourceMaterial = matPtr.get();
		createSGPassList(mSourceMaterial, mSGPassList);
	}

	if (event == MaterialSerializer::MSE_POST_WRITE)
	{
		mSourceMaterial = NULL;
		mSGPassList.clear();
	}
}
	//------------------------------------------------------------------------
	MtlPtr MaterialUtil::getMtl(const MaterialPtr& _material, MatGenParams& _rMatGenParams)
	{
		if(!_material->getNumTechniques())
			return MtlPtr();
		
		Technique* technique = _material->getTechnique(0);
		UserObjectBindings& uob = technique->getUserObjectBindings();
		Any mtlAny = uob.getUserAny( USER_MTL );
		Any matGenParamsAny = uob.getUserAny( USER_MAT_GEN_PARAMS );
		
		if(mtlAny.isEmpty() || matGenParamsAny.isEmpty())
			return MtlPtr();

		MtlPtr mtl = *any_cast<MtlPtr>(&mtlAny);
		_rMatGenParams = *any_cast<MatGenParams>(&matGenParamsAny);
		return mtl;	
	}
Esempio n. 3
0
void launcher::Launcher::loadMaterialsFromXml(NodeList matNodes)
{
    Engine& engine = Engine::getInstance();
    for(auto& matNode: matNodes)
    {
        MaterialPtr mat = MaterialLoader::getInstance().load(matNode);
        try
        {
            engine.getMaterial(mat->getName());
            LOG_WARN("Material \"" << mat->getName() << "\" already loaded. Ignoring duplicate.");
        }
        catch (Exception& e)
        {
            engine.addMaterial(mat);
        }
    }
}
void IsotropicRheologyMatrixSetter::setY(gcm_matrix& a, const MaterialPtr& material, const ICalcNode& node)
{
    a.clear();
    
    auto rho = material->getRho();
    auto mu = material->getMu();
    auto la = material->getLa();
    
    a(0, 4) = -1 / rho;
    a(1, 6) = -1 / rho;
    a(2, 7) = -1 / rho;
    a(3, 1) = -la;
    a(4, 0) = -mu;
    a(6, 1) = -la - 2 * mu;
    a(7, 2) = -mu;
    a(8, 1) = -la;
}
Esempio n. 5
0
 void State::pushMaterial(MaterialPtr m)
 {
   if (!m_materials.isEmpty() && m_materials.back()) m_materials.back()->unbind();
   m_materials.push_back(m);
   m_usedMaterials << m;
   push();
   if (m) m->bind(*this);
 }
Esempio n. 6
0
//-----------------------------------------------------------------------
MaterialPtr CompositorInstance::createLocalMaterial()
{
static size_t dummyCounter = 0;
    MaterialPtr mat = 
        MaterialManager::getSingleton().create(
            "CompositorInstanceMaterial"+StringConverter::toString(dummyCounter),
            ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME
        );
    ++dummyCounter;
    /// This is safe, as we hold a private reference
    /// XXX does not compile due to ResourcePtr conversion :
    ///     MaterialManager::getSingleton().remove(mat);
    MaterialManager::getSingleton().remove(mat->getName());
    /// Remove all passes from first technique
    mat->getTechnique(0)->removeAllPasses();
    return mat;
}
Esempio n. 7
0
//  HUD utils
//---------------------------------------------------------------------------------------------------------------
void CHud::UpdMiniTer()
{
	MaterialPtr mm = MaterialManager::getSingleton().getByName("circle_minimap");
	Pass* pass = mm->getTechnique(0)->getPass(0);
	if (!pass)  return;
	try
	{	GpuProgramParametersSharedPtr par = pass->getFragmentProgramParameters();
		bool ter = app->scn->sc->ter;
		if (par->_findNamedConstantDefinition("showTerrain",false))
			par->setNamedConstant("showTerrain", pSet->mini_terrain && ter ? 1.f : 0.f);
		if (par->_findNamedConstantDefinition("showBorder",false))
			par->setNamedConstant("showBorder", pSet->mini_border && ter ? 1.f : 0.f);
		if (par->_findNamedConstantDefinition("square",false))
			par->setNamedConstant("square", pSet->mini_zoomed && ter ? 0.f : 1.f);
	}
	catch(...){  }
}
OgreQtOverlay::OgreQtOverlay(Ogre::Root *root, Ogre::RenderWindow *window, Ogre::uint w, Ogre::uint h, QObject *parent)
 : QGraphicsScene(parent), _width(w), _height(h)
{
	_root = root;
	_window = window;
	_time.start(); //start a timer for key events
	
	//Connect redraw signal to this class
	QObject::connect(this,SIGNAL(changed(QList<QRectF>)),this,SLOT(sceneChanged(QList<QRectF>)));
	
	//qDebug() << "WIDTH:" << _width << "HEIGHT:" << _height;
	
	//create a texture the size of the screen to draw into
	_texture = TextureManager::getSingleton().createManual("OgreQtTexture",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
			,TEX_TYPE_2D,_width,_height,0,PF_A8R8G8B8,TU_DYNAMIC_WRITE_ONLY).getPointer();
	
	//save texture buffer for later
	_buffer = _texture->getBuffer().getPointer();
	
	//Create a material
	MaterialPtr material = MaterialManager::getSingleton().create("DynamicTextureMaterial",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	material->getTechnique(0)->getPass(0)->createTextureUnitState("OgreQtTexture");
	material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
	
	//Load overlay
	_overlay = OverlayManager::getSingleton().getByName("MyOverlays/OgreQt");
	OverlayElement *element = OverlayManager::getSingleton().getOverlayElement("MyOverlayElements/QtPanel");
	element->setMaterialName("DynamicTextureMaterial");
	
	//set the screen rect for the graphicsscene
	float ratio = (float)_width / (float)_height;
	setSceneRect(QRectF(0.0,0.0,_width,_height));
	
	//Create Cursor Pixmap
	_cursor = addPixmap(QPixmap(POINTER_FILE));
	_cursor->scale(POINTER_SCALE_X,POINTER_SCALE_Y);
	_cursor->setZValue(POINTER_Z);
	
	//set some default values
	_modifiers = Qt::NoModifier;
	_lastkeytime=0;
	_repeating=false;
	_lastclicktime = 0;
	_visible=false;
	_overlay->hide();
}
Esempio n. 9
0
void Splash::createScene()
{
	log("[Loading] Creating the splash screen...");
	// Loading picture
	overlayManager = &OverlayManager::getSingleton();
	overlay = overlayManager->create("LoadingOverlay");
	((MaterialPtr)MaterialManager::getSingleton().create("LoadingMaterial","splash"))->getTechnique(0)->getPass(0)->createTextureUnitState("loading.png");
	OverlayContainer* panel = static_cast<OverlayContainer*>(overlayManager->createOverlayElement("Panel","LoadingPanel"));
	panel->setMaterialName("LoadingMaterial");
	panel->setDimensions(1,0.96f);

	// Progess bar
	OverlayContainer* progressBar = static_cast<OverlayContainer*>(overlayManager->createOverlayElement("Panel","ProgressBar"));
	progressBar->setDimensions(1,0.04f);
	progressBar->setPosition(0,0.96f);
	MaterialPtr progressBGMat = MaterialManager::getSingleton().create("progressBG","splash");
	progressBGMat->getTechnique(0)->getPass(0)->createTextureUnitState()->setColourOperationEx(LBX_SOURCE1,LBS_MANUAL,LBS_CURRENT,ColourValue(0.9f, 0.9f, 0.9f));;
	MaterialPtr progressFGMat = MaterialManager::getSingleton().create("progressFG","splash");
	progressFGMat->getTechnique(0)->getPass(0)->createTextureUnitState()->setColourOperationEx(LBX_SOURCE1,LBS_MANUAL,LBS_CURRENT,ColourValue(0.23f, 0.88f, 0.5f));;
	progressBG = static_cast<OverlayContainer*>(overlayManager->createOverlayElement("Panel","ProgressBarBG"));
	progressBG->setMaterialName("progressBG");
	progressBG->setDimensions(1,1);
	progressFG = static_cast<OverlayContainer*>(overlayManager->createOverlayElement("Panel","ProgressBarFG"));
	progressFG->setMaterialName("progressFG");
	progressFG->setDimensions(0,1);

	// Loading text
	FontManager::getSingleton().getByName("BlueHighway")->load(); // HACK: Workaround for bug #324 in Ogre
	progressText = static_cast<TextAreaOverlayElement*>(overlayManager->createOverlayElement("TextArea", "text"));
	progressText->setMetricsMode(GuiMetricsMode::GMM_RELATIVE);
	progressText->setLeft(0.01f);
	progressText->setTop(0.01f);
	progressText->setHorizontalAlignment(GHA_LEFT);
	progressText->setVerticalAlignment(GVA_TOP);
	progressText->setFontName("BlueHighway");
	progressText->setCharHeight(0.03f);
	progressText->setColour(Ogre::ColourValue(0,0,0));

	progressBar->addChild(progressBG);
	progressBar->addChild(progressFG);
	progressBar->addChild(progressText);
	overlay->add2D(panel);
	overlay->add2D(progressBar);
	overlay->show();
}
Esempio n. 10
0
void DepthOfFieldEffect::createDepthRenderTexture()
{
	// Create the depth render texture
	mDepthTexture = TextureManager::getSingleton().createManual(
		"DoF_Depth",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		TEX_TYPE_2D, mWidth, mHeight,
		0, PF_L8, TU_RENDERTARGET);

	// Get its render target and add a viewport to it
	mDepthTarget = mDepthTexture->getBuffer()->getRenderTarget();
	mDepthViewport = mDepthTarget->addViewport(gEnv->mainCamera);

	// Register 'this' as a render target listener
	mDepthTarget->addListener(this);

	// Get the technique to use when rendering the depth render texture
	mDepthMaterial = MaterialManager::getSingleton().getByName("DoF_Depth");
	mDepthMaterial->load(); // needs to be loaded manually
	mDepthTechnique = mDepthMaterial->getBestTechnique();

	// Create a custom render queue invocation sequence for the depth render texture
    RenderQueueInvocationSequence* invocationSequence = Root::getSingleton().createRenderQueueInvocationSequence("DoF_Depth");

	// Add a render queue invocation to the sequence, and disable shadows for it
	/*
	RenderQueueInvocation* invocation = invocationSequence->add(RENDER_QUEUE_MAIN, "main");
    invocation->setSuppressShadows(true);
	//invocation->setSuppressRenderStateChanges(true);
	invocation->setSolidsOrganisation(QueuedRenderableCollection::OM_SORT_ASCENDING);
	// Set the render queue invocation sequence for the depth render texture viewport
    mDepthViewport->setRenderQueueInvocationSequenceName("DoF_Depth");
	*/

	mDepthViewport->setShadowsEnabled(false);
	mDepthViewport->setOverlaysEnabled(false);
	//mDepthViewport->setSkiesEnabled(false);

	mDepthViewport->setVisibilityMask(~DEPTHMAP_DISABLED);

	//re-set texture "DoF_Depth"
	MaterialPtr p = MaterialManager::getSingleton().getByName("DoF_DepthOfField");
	p->load();
	p->getBestTechnique()->getPass(0)->getTextureUnitState("depth")->setTextureName("DoF_Depth");
	p->unload();
}
Esempio n. 11
0
int ShadowManager::updateShadowTechnique()
{
    float scoef = 0.5;
    gEnv->sceneManager->setShadowColour(Ogre::ColourValue(0.563 + scoef, 0.578 + scoef, 0.625 + scoef));
    gEnv->sceneManager->setShowDebugShadows(false);

    RoR::App::GfxShadowType type = RoR::App::GetGfxShadowType();

    if (type == RoR::App::GFX_SHADOW_TYPE_TEXTURE)
    {
        gEnv->sceneManager->setShadowFarDistance(RoR::App::GetGfxSightRange());
        processTextureShadows();
    }
    else if (type == RoR::App::GFX_SHADOW_TYPE_PSSM)
    {
        processPSSM();
        if (gEnv->sceneManager->getShowDebugShadows())
        {
            // add the overlay elements to show the shadow maps:
            // init overlay elements
            OverlayManager& mgr = Ogre::OverlayManager::getSingleton();
            Overlay* overlay = mgr.create("DebugOverlay");

            for (int i = 0; i < PSSM_Shadows.ShadowsTextureNum; ++i)
            {
                TexturePtr tex = gEnv->sceneManager->getShadowTexture(i);

                // Set up a debug panel to display the shadow
                MaterialPtr debugMat = MaterialManager::getSingleton().create("Ogre/DebugTexture" + StringConverter::toString(i), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
                debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
                TextureUnitState* t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName());
                t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);

                OverlayContainer* debugPanel = (OverlayContainer*)(OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugTexPanel" + StringConverter::toString(i)));
                debugPanel->_setPosition(0.8, i * 0.25);
                debugPanel->_setDimensions(0.2, 0.24);
                debugPanel->setMaterialName(debugMat->getName());
                debugPanel->setEnabled(true);
                overlay->add2D(debugPanel);
                overlay->show();
            }
        }
    }
    return 0;
}
Esempio n. 12
0
std::shared_ptr<TextSurface>
TextSurface::create(const std::string& text, const TextProperties& text_props)
{
  Cairo::TextExtents text_extents;
  Cairo::FontExtents font_extents;

  Cairo::RefPtr<Cairo::ImageSurface> surface = create_cairo_surface(text, text_props,
                                                                    text_extents, font_extents);
  int width  = surface->get_width();
  int height = surface->get_height();
  TexturePtr texture = create_opengl_texture(surface);

  MaterialPtr material = std::make_shared<Material>();

  material->set_program(Program::create(Shader::from_file(GL_VERTEX_SHADER,   "src/basic_texture.vert"),
                                        Shader::from_file(GL_FRAGMENT_SHADER, "src/basic_texture.frag")));

  material->enable(GL_BLEND);
  material->blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  material->set_texture(0, texture);
  material->set_uniform("texture_diff", 0);
  material->set_uniform("MVP", UniformSymbol::ModelViewProjectionMatrix);

  return std::make_shared<TextSurface>(material, width, height,
                                       text_extents, font_extents);
}
Esempio n. 13
0
void HDRListener::notifyMaterialSetup(uint32 pass_id, MaterialPtr &mat)
{
	//  Prepare the fragment params offsets
	switch (pass_id)
	{
		//case 994: // rt_lum4
	case 993: // rt_lum3
	case 992: // rt_lum2
	case 991: // rt_lum1
	case 990: // rt_lum0
		break;
	case 800: // rt_brightpass
		break;
	case 701: // rt_bloom1
		{
			// horizontal bloom
			try
			{	mat->load();
				GpuProgramParametersSharedPtr fparams =
					mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
				fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsHorz[0], 15);
				fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
			}
			catch(...)
			{	}

			break;
		}
	case 700: // rt_bloom0
		{
			// vertical bloom
			try
			{	mat->load();
				GpuProgramParametersSharedPtr fparams =
					mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
				fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsVert[0], 15);
				fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
			}
			catch(...)
			{	}

			break;
		}
	}
}
Esempio n. 14
0
TextSprite::TextSprite(ObjectManager *o, const std::string &name, vmml::Vector3f color, const std::string &text, FontPtr font, PropertiesPtr properties)
	: Sprite(), _text(text), _font(font)
{
	// Create geometry
	createGeometry();

	// Create shader and material
	ShaderPtr shader = o->generateShader(name, { 0, false, true, false, false, true, false, false, false, false, false, false, true });
	MaterialPtr material = o->createMaterial(name, shader);
	
	// Add atlas texture to the material
	material->setTexture(bRenderer::DEFAULT_SHADER_UNIFORM_CHARACTER_MAP(), font->getAtlas());
	// Pass color to material (don't pass texture, has to be treated separately to bind right tex unit)
	material->setVector(bRenderer::WAVEFRONT_MATERIAL_DIFFUSE_COLOR(), color);

	setMaterial(material);
	setProperties(properties);
}
Esempio n. 15
0
void SetupRGBMaterial()
{
	Ogre::TexturePtr depthTexture = Ogre::TextureManager::getSingleton().createManual(
			"MyRGBTexture", // name
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D,      // type
			RGBX, RGBY,         // width & height
			0,                // number of mipmaps
			PF_BYTE_RGB,     // pixel format
			TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

		
	// Create a material using the texture
	MaterialPtr material = MaterialManager::getSingleton().create(
			"RGBTextureMaterial", // name
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	material->getTechnique(0)->getPass(0)->createTextureUnitState("MyRGBTexture");
}
Esempio n. 16
0
	void CMesh::setMeshAmbientColour(Ogre::ColourValue colourValue) {
		
		unsigned int nbSubEnt = mEntity->getNumSubEntities();
		for(unsigned int i = 0;i < nbSubEnt;i++) {

			MaterialPtr mat = mEntity->getSubEntity(i)->getMaterial();

			 mEntity->getSubEntity(i)->getMaterial()->getTechnique(0)->getPass(0)->setAmbient(colourValue);

			Ogre::GpuProgramParametersSharedPtr gpup;

			Ogre::String name = mat->getTechnique(0)->getPass(0)->getVertexProgramName();
			if(name == "ambient_vs") {
				gpup = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();
				gpup->setNamedConstant("ambient", colourValue);
			}
		}
	}
Esempio n. 17
0
MaterialPtr
MaterialFactory::create_skybox()
{
  MaterialPtr material = std::make_shared<Material>();

  material->blend_func(GL_ONE, GL_ONE);
  material->enable(GL_BLEND);
  material->enable(GL_CULL_FACE);
  material->enable(GL_DEPTH_TEST);
  material->set_texture(0, Texture::cubemap_from_file("data/textures/miramar/"));
  material->set_uniform("diffuse", glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
  material->set_uniform("diffuse_texture", 0);
  material->set_uniform("MVP", UniformSymbol::ModelViewProjectionMatrix);
  material->set_program(Program::create(Shader::from_file(GL_VERTEX_SHADER, "src/cubemap.vert"),
                                        Shader::from_file(GL_FRAGMENT_SHADER, "src/cubemap.frag")));

  return material;
}
    //-----------------------------------------------------------------------
    void MaterialManager::initialise(void)
    {
        // Set up default material - don't use name constructor as we want to avoid applying defaults
        mDefaultSettings = create("DefaultSettings", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
        // Add a single technique and pass, non-programmable
        mDefaultSettings->createTechnique()->createPass();

        // Set the default LOD strategy
        mDefaultSettings->setLodStrategy(LodStrategyManager::getSingleton().getDefaultStrategy());

        // Set up a lit base white material
        create("BaseWhite", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
        // Set up an unlit base white material
        MaterialPtr baseWhiteNoLighting = create("BaseWhiteNoLighting",
        ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
        baseWhiteNoLighting->setLightingEnabled(false);

    }
Esempio n. 19
0
void ShadowManager::updatePSSM(Ogre::Terrain* terrain)
{
	if (!PSSM_Shadows.mPSSMSetup.get())  return;

	Ogre::TerrainMaterialGeneratorA::SM2Profile *matProfile = 0;
	if (Ogre::TerrainGlobalOptions::getSingletonPtr())
	{
		matProfile = static_cast<Ogre::TerrainMaterialGeneratorA::SM2Profile*>(Ogre::TerrainGlobalOptions::getSingleton().getDefaultMaterialGenerator()->getActiveProfile());
		matProfile->setReceiveDynamicShadowsEnabled(true);
		matProfile->setReceiveDynamicShadowsLowLod(true);
		matProfile->setGlobalColourMapEnabled(true);
	}


	Ogre::PSSMShadowCameraSetup* pssmSetup = static_cast<Ogre::PSSMShadowCameraSetup*>(PSSM_Shadows.mPSSMSetup.get());
	Ogre::PSSMShadowCameraSetup::SplitPointList splitPointList = pssmSetup->getSplitPoints();

	
	splitPointList[0] = 1.0;
	splitPointList[1] = 95.0;
	splitPointList[2] = 255.0;
	splitPointList[3] = 512.0;
	pssmSetup->setSplitPoints(splitPointList);
	
	
	Ogre::Vector4 splitPoints;
	for (int i = 0; i < PSSM_Shadows.ShadowsTextureNum; ++i)
		splitPoints[i] = splitPointList[i];

	MaterialPtr mat = MaterialManager::getSingleton().getByName("RoR/Managed_Mats/Base");
	mat->getTechnique("ShadowTechnique")->getPass(0)->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);

	// TODO: fix this
/*	setMaterialSplitPoints("road", splitPoints);
	setMaterialSplitPoints("road2", splitPoints);
	*/

	if (matProfile && terrain)
	{
		matProfile->generateForCompositeMap(terrain);
		matProfile->setReceiveDynamicShadowsDepth(PSSM_Shadows.mDepthShadows);
		matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(PSSM_Shadows.mPSSMSetup.get()));
	}
}
Esempio n. 20
0
static void AddFrictionSamples(SceneManager* const sceneMgr, OgreNewtonWorld* const world, const Vector3& location, int materialStartID)
{
    Vector3 blockBoxSize (0.75f, 0.25f, 0.5f);
    dNewtonCollisionBox shape (world, blockBoxSize.x, blockBoxSize.y, blockBoxSize.z, m_all);

    // create a texture for using with this material
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().load("smilli.tga", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

    // make a material to use with this mesh
    MaterialPtr renderMaterial = MaterialManager::getSingleton().create("smalli", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    renderMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(true);
    renderMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("smilli.tga");
    renderMaterial->setAmbient(0.2f, 0.2f, 0.2f);

    OgreNewtonMesh boxMesh (&shape);
    boxMesh.Triangulate();
    int materialId = boxMesh.AddMaterial(renderMaterial);
    boxMesh.ApplyBoxMapping (materialId, materialId, materialId);

    // create a manual object for rendering
    ManualObject* const object = boxMesh.CreateEntity(MakeName ("ramp"));
    MeshPtr mesh (object->convertToMesh (MakeName ("ramp")));

    //Matrix4 matrix (Matrix4::IDENTITY);
    Matrix4 matrix (Quaternion (Degree(-30.0f), Vector3 (0.0f, 0.0f, 1.0f)));
    Vector3 origin (location.x - 8.0f, location.y + 5.125f, location.z + 15.0f);

    dFloat mass = 10.0f;
    for (int i = 0; i < 10; i ++) {
        matrix.setTrans (origin);
        origin.z -= 3.0f;
        Entity* const ent = sceneMgr->createEntity(MakeName ("ramp"), mesh);
        SceneNode* const node = CreateNode (sceneMgr, ent, matrix.getTrans(), matrix.extractQuaternion());

        shape.SetMaterialId(materialStartID + i);
        OgreNewtonDynamicBody* const body = new OgreNewtonDynamicBody (world, mass, &shape, node, matrix);

        // set the linear and angular drag do zero
        body->SetLinearDrag (0.0f);
        body->SetAngularDrag(Vector3 (0.0f, 0.0f, 0.0f));
    }

    delete object;
}
Esempio n. 21
0
void DepthOfFieldListener::notifyMaterialSetup(uint32 pass_id, MaterialPtr &mat)
{
	if (pass_id == 1)
	{
		float blurScale =.5f;

		Vector4 pixelSize(1.0f / (mViewportWidth * blurScale), 1.0f / (mViewportHeight * blurScale), 0.0f, 0.0f);

		mat->load();
		Pass *pass = mat->getBestTechnique()->getPass(0);
		GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();

		if (params->_findNamedConstantDefinition("pixelSize"))
			params->setNamedConstant("pixelSize", pixelSize);

	}
	else if (pass_id == 2)
	{
		float blurScale =.5f;
		Vector4  pixelSize(1.0f / mViewportWidth, 1.0f / mViewportHeight,1.0f / (mViewportWidth * blurScale), 1.0f / (mViewportHeight * blurScale) );

		Pass *pass = mat->getBestTechnique()->getPass(0);
		GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();

		if (params->_findNamedConstantDefinition("pixelSize"))
			params->setNamedConstant("pixelSize", pixelSize);

		// this is the camera you're using
		#ifndef SR_EDITOR
		Camera *cam = mApp->mSplitMgr->mCameras.front();
		#else
		Camera *cam = mApp->mCamera;
		#endif

		if (params->_findNamedConstantDefinition("far"))
			params->setNamedConstant("far", cam->getFarClipDistance());

		if (params->_findNamedConstantDefinition("dofparams"))
		{
			Vector4 dofParams(0.0f,mApp->pSet->dof_focus,mApp->pSet->dof_far,1.0);
			params->setNamedConstant("dofparams", dofParams);
		}
	}
}
Esempio n. 22
0
void prepareCircleMaterial()
{
	char *bmap = new char[256 * 256 * 4] ;
	memset(bmap, 127, 256 * 256 * 4);
	for(int b=0;b<16;b++) {
		int x0 = b % 4 ;
		int y0 = b >> 2 ;
		Real radius = 4.0f + 1.4 * (float) b ;
		for(int x=0;x<64;x++) {
			for(int y=0;y<64;y++) {
				Real dist = Math::Sqrt((x-32)*(x-32)+(y-32)*(y-32)); // 0..ca.45
				dist = fabs(dist -radius -2) / 2.0f ;
				dist = dist * 255.0f;
				if (dist>255)
					dist=255 ;
				int colour = 255-(int)dist ;
				colour = (int)( ((Real)(15-b))/15.0f * (Real) colour );

				bmap[4*(256*(y+64*y0)+x+64*x0)+0]=colour ;
				bmap[4*(256*(y+64*y0)+x+64*x0)+1]=colour ;
				bmap[4*(256*(y+64*y0)+x+64*x0)+2]=colour ;
				bmap[4*(256*(y+64*y0)+x+64*x0)+3]=colour ;
			}
		}
	}

	DataStreamPtr imgstream(new MemoryDataStream(bmap, 256 * 256 * 4));
	//~ Image img;
	//~ img.loadRawData( imgstream, 256, 256, PF_A8R8G8B8 );
	//~ TextureManager::getSingleton().loadImage( CIRCLES_MATERIAL , img );
	TextureManager::getSingleton().loadRawData(CIRCLES_MATERIAL,
        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		imgstream, 256, 256, PF_A8R8G8B8);
	MaterialPtr material =
		MaterialManager::getSingleton().create( CIRCLES_MATERIAL,
        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	TextureUnitState *texLayer = material->getTechnique(0)->getPass(0)->createTextureUnitState( CIRCLES_MATERIAL );
	texLayer->setTextureAddressingMode( TextureUnitState::TAM_CLAMP );
	material->setSceneBlending( SBT_ADD );
	material->setDepthWriteEnabled( false ) ;
    material->load();
    // finished with bmap so release the memory
    delete [] bmap;
}
Esempio n. 23
0
MaterialPtr Visuals::getMaterial(std::string name, int red, int green, int blue, int alpha) {

	// Create the texture
	TexturePtr texture = TextureManager::getSingleton().createManual(
		name,				// name
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		TEX_TYPE_2D,      // type
		256, 256,         // width & height
		0,                // number of mipmaps
		PF_BYTE_BGRA,     // pixel format
		TU_DEFAULT);      // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
	// textures updated very often (e.g. each frame)

	// Get the pixel buffer
	HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();

	// Lock the pixel buffer and get a pixel box
	pixelBuffer->lock(HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD!
	const PixelBox& pixelBox = pixelBuffer->getCurrentLock();

	uint8* pDest = static_cast<uint8*>(pixelBox.data);

	// Fill in some pixel data. This will give a semi-transparent blue,
	// but this is of course dependent on the chosen pixel format.
	for (size_t j = 0; j < 256; j++) {
		for(size_t i = 0; i < 256; i++)
		{
			*pDest++ = blue; // B
			*pDest++ = green; // G
			*pDest++ = red; // R
			*pDest++ = alpha; // A
		}
	}

	// Unlock the pixel buffer
	pixelBuffer->unlock();

	MaterialPtr material = MaterialManager::getSingleton().create(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

	material->getTechnique(0)->getPass(0)->createTextureUnitState(name);
	material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);

	return material;
}
Esempio n. 24
0
void DepthOfFieldEffect::notifyMaterialSetup(uint32 passId, MaterialPtr& material)
{
	switch (passId)
	{
	case BlurPass:
		{
			//float pixelSize[2] = {
			//	1.0f / (gEnv->ogreViewPort->getActualWidth() / BLUR_DIVISOR),
			//	1.0f / (gEnv->ogreViewPort->getActualHeight() / BLUR_DIVISOR)};

			// Adjust fragment program parameters
			Ogre::Vector3 ps = Ogre::Vector3(1.0f / (mWidth / BLUR_DIVISOR),1.0f / (mHeight / BLUR_DIVISOR), 1.0f);
			float pixelSize[3] = { ps.x, ps.y, ps.z };
			GpuProgramParametersSharedPtr fragParams = material->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
			if ((!fragParams.isNull())&&(fragParams->_findNamedConstantDefinition("pixelSize")))
				fragParams->setNamedConstant("pixelSize", pixelSize, 1, 3);

			break;
		}

	case OutputPass:
		{
			float pixelSizeScene[3] = {
				1.0f / mWidth,
				1.0f / mHeight,
				0};

			float pixelSizeBlur[3] = {
				1.0f / (mWidth / BLUR_DIVISOR),
				1.0f / (mHeight / BLUR_DIVISOR),
				0};

			// Adjust fragment program parameters
			GpuProgramParametersSharedPtr fragParams =
				material->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
			if ((!fragParams.isNull())&&(fragParams->_findNamedConstantDefinition("pixelSizeScene")))
				fragParams->setNamedConstant("pixelSizeScene", pixelSizeScene,1,3);
			if ((!fragParams.isNull())&&(fragParams->_findNamedConstantDefinition("pixelSizeBlur")))
				fragParams->setNamedConstant("pixelSizeBlur", pixelSizeBlur,1,3);

			break;
		}
	}
}
//-----------------------------------------------------------------------
void parseScale(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex)
{
	if (numParams != 3)
	{
		LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in "
			+ pMat->getName() + ", wrong number of parameters (expected 3)");
		return;
	}
	pTex->setTextureScale(StringConverter::parseReal(params[1].c_str()), StringConverter::parseReal(params[2].c_str()) );
}
//-----------------------------------------------------------------------
void parseLayerAnisotropy(StringVector::iterator& params, int numParams, MaterialPtr& pMat, TextureUnitState* pTex)
{
	if (numParams != 2)
	{
		LogManager::getSingleton().logMessage("Bad " + params[0] + " attribute line in "
			+ pMat->getName() + ", wrong number of parameters (expected 2)");
		return;
	}
	pTex->setTextureAnisotropy(atoi(params[1].c_str()));
}
Esempio n. 27
0
	//--------------------------------------------------------------------------------
	bool MaterialUtil::isPortal(const MaterialPtr& _material)
	{
		const String& name = _material->getName();
		if(name.length() >= 2)
		{
			if(tolower(name[0]) == 'p' && name[1] == ':')
				return true;
		}
		return false;
	}
Esempio n. 28
0
	//--------------------------------------------------------------------------------
	MaterialPtr MaterialUtil::getUnselectedVersion(const MaterialPtr& _selectedMaterial)
	{
		const String& selName = _selectedMaterial->getName();
		String name = getUnselectedVersionName(selName);
		if(selName == name)
			return _selectedMaterial;

		MaterialPtr material = MaterialManager::getSingleton().getByName(name);
		return material;
	}
Esempio n. 29
0
void Character::updateCharacterNetworkColour()
{
#ifdef USE_SOCKETW
    const String materialName = "tracks/" + myName;
    const int textureUnitStateNum = 2;

    MaterialPtr mat = MaterialManager::getSingleton().getByName(materialName);
    if (mat.isNull())
        return;

    if (mat->getNumTechniques() > 0 && mat->getTechnique(0)->getNumPasses() > 0 && textureUnitStateNum < mat->getTechnique(0)->getPass(0)->getNumTextureUnitStates())
    {
        auto state = mat->getTechnique(0)->getPass(0)->getTextureUnitState(textureUnitStateNum);
        auto color = Networking::GetPlayerColor(colourNumber);
        state->setAlphaOperation(LBX_BLEND_CURRENT_ALPHA, LBS_MANUAL, LBS_CURRENT, 0.8);
        state->setColourOperationEx(LBX_BLEND_CURRENT_ALPHA, LBS_MANUAL, LBS_CURRENT, color, color, 1);
    }
#endif // USE_SOCKETW
}
Esempio n. 30
0
void PlayPen_testManualBlend::setupContent()
{
	// create material
	MaterialPtr mat = MaterialManager::getSingleton().create("TestMat", 
		TRANSIENT_RESOURCE_GROUP);
	Pass * p = mat->getTechnique(0)->getPass(0);
	p->setLightingEnabled(false);
	p->createTextureUnitState("Dirt.jpg");
	TextureUnitState* t = p->createTextureUnitState("ogrelogo.png");
	t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT, 
		ColourValue::White, ColourValue::White, 0.75);

	Entity *planeEnt = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt);
	planeEnt->setMaterialName("TestMat");

	mCamera->setPosition(0,0,600);
	mCamera->lookAt(Vector3::ZERO);
}