Esempio n. 1
0
void DirectusMaterial::Reflect(weak_ptr<GameObject> gameobject)
{
    m_inspectedMaterial = weak_ptr<Material>();

    // Catch the evil case
    if (gameobject.expired())
    {
        this->hide();
        return;
    }

    MeshRenderer* meshRenderer = gameobject.lock()->GetComponent<MeshRenderer>().lock().get();
    if (!meshRenderer)
    {
        this->hide();
        return;
    }



    m_inspectedMaterial = meshRenderer->GetMaterial();
    if (m_inspectedMaterial.expired())
    {
        this->hide();
        return;
    }

    // Do the actual reflection
    ReflectName();
    ReflectShader();
    ReflectAlbedo();
    ReflectRoughness();
    ReflectMetallic();
    ReflectNormal();
    ReflectHeight();
    ReflectOcclusion();
    ReflectEmission();
    ReflectMask();
    ReflectTiling();
    ReflectOffset();

    SetPropertiesVisible(m_inspectedMaterial.lock()->IsEditable() ? true : false);

    // Make this widget visible
    this->show();
}
void Scene::Render( RenderPass renderPass, Viewport* viewport )
{
	static Mesh* skyboxMesh = ResourceManager::GetGenMesh(GenMeshes::Cube);

	std::string viewportName = viewport != NULL ? viewport->GetName() : "";

	bool ignoreShadowCast = true;
	if (renderPass == RenderPass::ShadowPass)
	{
		ignoreShadowCast = false;
	}

	for (uint rank = 0; rank < m_layers.size(); rank++)
	{
		if ( !m_layers[rank]->IsEnabled() )	continue;

		RenderManager::UseNewLayer(renderPass);

		if (rank == 0)
		{
			if ( m_skyboxMaterial != NULL && renderPass != RenderPass::PickingPass )
			{
				Transform transform(NULL);
				transform.SetPositionWorld( RenderManager::GetRenderCamera()->GetComponent<Transform>()->GetPositionWorld() );
				transform.SetScaleWorld( Vector3(m_skyboxSize) );

				MeshRenderer renderer;
				renderer.SetMaterial(m_skyboxMaterial);
				renderer.SetMesh(skyboxMesh);
				renderer.SetFaceCulling( FaceCulling::CULL_FRONT );

				RenderManager::ObjectToRender objectToRender;
				objectToRender.transform = &transform;
				objectToRender.meshRenderer = &renderer;
				objectToRender.renderPass = renderPass;

				RenderManager::RenderObject( objectToRender );
			}

			GizmoManager::RenderGrid( renderPass );
		}

#if (ME3D_SHADING_MODE == ME3D_CLASSIC_SHADING)
	
		if (viewport != NULL && viewport->HasEnableLights() && renderPass != RenderPass::PickingPass)
		{
			for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
			{
				GameObject* obj = m_layers[rank]->GetObjectAt(j);

				if (obj->IsFullyActive())
				{
					Light* lightComp = obj->GetComponent<Light>();
					if (lightComp != NULL && lightComp->IsEnabled())
					{
						RenderManager::ActiveLight activeLight;
						activeLight.light = lightComp;
						activeLight.transform = obj->GetComponent<Transform>();

						RenderManager::AddActiveLight( activeLight );
					}
				}
			}
		}
#endif


		for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
		{
			GameObject* obj = m_layers[rank]->GetObjectAt(j);

			if ( !obj->IsIgnoringViewport(viewportName)
				&& obj->IsFullyActive() )
			{
				GizmoManager::RenderFollower( obj, renderPass );

				MeshRenderer* renderer = obj->GetComponent<MeshRenderer>();
				GuiTexture* guiTexture = obj->GetComponent<GuiTexture>();

				glEnable(GL_DEPTH_TEST);
				glDepthMask(GL_TRUE);

				glEnable(GL_BLEND);
				glBlendEquation(GL_FUNC_ADD);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

				if (renderer != NULL &&
					renderer->GetMaterial() != NULL &&
					renderer->GetMesh() != NULL &&
					(ignoreShadowCast || renderer->IsCastingShadows()) )
				{
					RenderManager::ObjectToRender objectToRender;
					objectToRender.uniqueIndex = obj->GetUniqueIndex();
					objectToRender.transform = obj->GetComponent<Transform>();
					objectToRender.meshRenderer = renderer;
					objectToRender.renderPass = renderPass;

					RenderManager::RenderObject( objectToRender );
				}

				if (guiTexture != NULL)
				{
					RenderManager::ObjectToRender objectToRender;
					objectToRender.uniqueIndex = obj->GetUniqueIndex();
					objectToRender.guiTexture = guiTexture;

					RenderManager::RenderObject( objectToRender );
				}
			}
		}


#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)

		if (viewport != NULL && viewport->HasEnableLights() && renderPass != RenderPass::PickingPass)
		{
			for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
			{
				GameObject* obj = m_layers[rank]->GetObjectAt(j);

				if (obj->IsFullyActive())
				{
					Light* lightComp = obj->GetComponent<Light>();
					if (lightComp != NULL && lightComp->IsEnabled())
					{
						RenderManager::ActiveLight activeLight;
						activeLight.light = lightComp;
						activeLight.transform = obj->GetComponent<Transform>();

						switch (lightComp->GetType())
						{
						case LightType::Directional:
							RenderManager::DeferredDirectional(activeLight);
							break;
						case LightType::Point:
						case LightType::Spot:
							RenderManager::DeferredPointAndSpot(activeLight);
							break;
						}
					}
				}
			}
		}
#endif


#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
		if (renderPass != RenderPass::PickingPass)
		{
			RenderManager::DeferredUnlit();
		}
#endif

		RenderManager::CollapseLayer(renderPass);

	} // end for
	 


	// layer for gizmo
	RenderManager::UseNewLayer(renderPass);
		
	GizmoManager::RenderTools(renderPass);

#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
	if (renderPass != RenderPass::PickingPass)
	{
		RenderManager::DeferredUnlit();
	}
#endif

	RenderManager::CollapseLayer(renderPass);



	// layer for menu
	RenderManager::UseNewLayer(renderPass);
		
	MenuManager::Render(renderPass, viewportName);

#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
	if (renderPass != RenderPass::PickingPass)
	{
		RenderManager::DeferredUnlit();
	}
#endif

	RenderManager::CollapseLayer(renderPass);

}