void Model::render(const RenderConf & _conf) const
	{
		if (!getShader())
			return;

		if (!Configurator::isDepthTestEnabled())
			glEnable(GL_DEPTH_TEST);

		Shader & shader = *getShader();
		shader.use();

		bool useCustomConf = _conf != RenderConf::Default;

		const auto & lights = useCustomConf ? _conf.lights : getLights();
		const auto & matrices = useCustomConf ? _conf.matrices : getMatrices();

		shader.setMat4f("mvp", matrices.mvp)
			.setMat4f("model", matrices.transform)
			.setMat4f("inverseModel", matrices.inverseTransform)
			.setVec3("cameraPos", matrices.cameraPosition)
			.setFloat("material.shininess", 5.f)
			.setLights("light", lights.cbegin(), lights.cend())
			.setBoolean("useColorOnly", m_useColorOnly)
			.setColor("singleColor", m_color);

		renderMeshes();

		Shader::unuse();

		if (!Configurator::isDepthTestEnabled())
			glDisable(GL_DEPTH_TEST);
	}
bool Ocean::render()
{
	if (!m_isActive || !m_shader || !m_model)
		return true;

	// Define how we want the model to be rendered
	setRenderModes();

	// Define how we want to see the model
	m_shader->setRenderMode(ProjectionMode::Perspective, ViewMode::View);

	// render to render Texture
	if (m_postprocessing == renderMode::On)
	{
		// get and set render texture
		Texture* renderTexture;
		AssetManager::getInstance()->loadTexture(&renderTexture, "renderTexture");
		renderTexture->setRenderTarget();

		// render the model
		renderMeshes();

		// Reset render Target
		DirectXManager::getInstance()->setBackBufferRenderTarget();
		DirectXManager::getInstance()->ResetViewport();

		// Clean Up
		renderTexture = 0;
	}

	// render Mesh
	renderMeshes();

	// Reset Pipeline settings
	resetRenderModes();

	return true;
}
Esempio n. 3
0
void Render::render(RenderCamera* camera, RenderTarget *target, bool depthOnly)
{
	RENDERER_PERFZONE(Render_render);
	const uint32 numLights = (uint32)m_visibleLights.Size();
	if(target)
	{
		target->bind();
	}

	// TODO: ²ÄÖÊ·Ö×é
	if(beginRender())
	{
		if(depthOnly)
		{
			RENDERER_PERFZONE(Render_render_depthOnly);
			bindAmbientState(Colour(0,0,0,1));
			bindViewProj(camera);
			renderMeshes(m_visibleLitMeshes,   RenderMaterial::PASS_DEPTH);
			renderMeshes(m_visibleUnlitMeshes, RenderMaterial::PASS_DEPTH);
		}
		else if(numLights > RENDERER_DEFERRED_THRESHOLD)
		{
			RENDERER_PERFZONE(Render_render_deferred);
			bindDeferredState();
			bindViewProj(camera);
			renderMeshes(m_visibleLitMeshes,   RenderMaterial::PASS_UNLIT);
			renderMeshes(m_visibleUnlitMeshes, RenderMaterial::PASS_UNLIT);
			renderDeferredLights();
		}
		else if(numLights > 0)
		{
			RENDERER_PERFZONE(Render_render_lit);
			bindAmbientState(m_ambientColor);
			bindViewProj(camera);
			RenderLight &light0 = *m_visibleLights[0];
			light0.bind();
			renderMeshes(m_visibleLitMeshes, light0.getPass());
			light0.m_renderer = 0;
			
			//bindAmbientState(Colour(0,0,0,1));
			beginMultiPass();
			for(uint32 i=1; i<numLights; i++)
			{
				RenderLight &light = *m_visibleLights[i];
				light.bind();
				renderMeshes(m_visibleLitMeshes, light.getPass());
				light.m_renderer = 0;
			}
			endMultiPass();
			renderMeshes(m_visibleUnlitMeshes, RenderMaterial::PASS_UNLIT);
		}
		else
		{
			RENDERER_PERFZONE(Render_render_unlit);
			bindAmbientState(Colour(0,0,0,1));
			bindViewProj(camera);
			renderMeshes(m_visibleLitMeshes,   RenderMaterial::PASS_UNLIT);
			renderMeshes(m_visibleUnlitMeshes, RenderMaterial::PASS_UNLIT);
		}
		endRender();
	}
	if(target) 
	{
		target->unbind();
	}
	m_visibleLitMeshes.Reset();
	m_visibleUnlitMeshes.Reset();
	m_visibleLights.Reset();
}