Esempio n. 1
0
bool ATOM_Blur::drawHBlur7x7 (ATOM_RenderDevice *device, ATOM_Texture *sourceTexture, float blurScale)
{
	ATOM_STACK_TRACE(ATOM_Blur::drawHBlur7x7);

	if (!blurMaterialsInitialized)
	{
		initializeBlurMaterials ();
	}

	if (!_hBlurMaterial7x7)
	{
		return false;
	}

	float w = 1.f / sourceTexture->getWidth ();
	float weights[7] = { 0.143f, 0.143f, 0.143f, 0.143f, 0.143f, 0.143f, 0.143f };
	float offsets[7] = { -3.f * w * blurScale, -2.f * w * blurScale, -1.f * w * blurScale, 0.f, 1.f * w * blurScale, 2.f * w * blurScale, 3.f * w * blurScale };

	_hBlurMaterial7x7->getParameterTable()->setFloatArray ("offsets", offsets, 7);
	_hBlurMaterial7x7->getParameterTable()->setFloatArray ("weights", weights, 7);
	_hBlurMaterial7x7->getParameterTable()->setTexture ("inputTexture", sourceTexture);

	unsigned numPasses = _hBlurMaterial7x7->begin (device);
	for (unsigned pass = 0; pass < numPasses; ++pass)
	{
		if (_hBlurMaterial7x7->beginPass (device, pass))
		{
			drawScreenQuad (device, sourceTexture->getWidth(), sourceTexture->getHeight());
			_hBlurMaterial7x7->endPass (device, pass);
		}
	}
	_hBlurMaterial7x7->end (device);

	return true;
}
Esempio n. 2
0
bool ATOM_Blur::drawHBlur3x3 (ATOM_RenderDevice *device, ATOM_Texture *sourceTexture, float blurScale)
{
	ATOM_STACK_TRACE(ATOM_Blur::drawHBlur3x3);

	if (!blurMaterialsInitialized)
	{
		initializeBlurMaterials ();
	}

	if (!_hBlurMaterial3x3)
	{
		return false;
	}

	float w = 1.f / sourceTexture->getWidth ();
	float weights[3] = { 0.25f, 0.5f, 0.25f };
	float offsets[3] = { -w * blurScale, 0.f, w * blurScale };

	_hBlurMaterial3x3->getParameterTable()->setVector ("offsets", ATOM_Vector4f(offsets[0], offsets[1], offsets[2], 0.f));
	_hBlurMaterial3x3->getParameterTable()->setVector ("weights", ATOM_Vector4f(weights[0], weights[1], weights[2], 0.f));
	_hBlurMaterial3x3->getParameterTable()->setTexture ("inputTexture", sourceTexture);

	unsigned numPasses = _hBlurMaterial3x3->begin (device);
	for (unsigned pass = 0; pass < numPasses; ++pass)
	{
		if (_hBlurMaterial3x3->beginPass (device, pass))
		{
			drawScreenQuad (device, sourceTexture->getWidth(), sourceTexture->getHeight());
			_hBlurMaterial3x3->endPass (device, pass);
		}
	}
	_hBlurMaterial3x3->end (device);

	return true;
}
Esempio n. 3
0
void nRenderer::clearBuffers() {
	/*nFrameBuffer *fb = nFrameBuffer::getActiveFrameBuffer();

	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	if(fb)
		fb->bind();*/

	#ifdef CUSTOM_CLEAR
	clear->bind();
	drawScreenQuad();
	clear->unbind();
	#else
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	#endif
}
Esempio n. 4
0
void Scene::Render()
{
	//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//draw mesh
	glBindFramebuffer(GL_FRAMEBUFFER,_fbos[0]);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	Shader * curShader = shaders[0];
	curShader->TurnOn();
	initUniformVal(curShader);
	glm::mat4 model;
	// Floor cube
	model = glm::translate(model, glm::vec3(0.0, -1.0f, 0.0f));
	model = glm::scale(model, glm::vec3(20.0f, 1.0f, 20.0f));
	int modelId = curShader->GetVariable("model");
	curShader->SetMatrix4(modelId,1,false,glm::value_ptr(model));
	drawCub(cub);

	model = glm::mat4();
	model = glm::translate(model, glm::vec3(0.0f, 0.0f, 5.0));
	model = glm::rotate(model, -90.0f, glm::vec3(1.0, 0.0, 0.0));
	model = glm::scale(model, glm::vec3(0.5f));
	modelId = curShader->GetVariable("model");
	curShader->SetMatrix4(modelId,1,false,glm::value_ptr(model));
	_modes[0]->drawNode(curShader);

	curShader->TurnOff();
	glBindFramebuffer(GL_FRAMEBUFFER,0);

	//ssao shader
	glBindFramebuffer(GL_FRAMEBUFFER,_fbos[1]);
	glClear(GL_COLOR_BUFFER_BIT);
	curShader = shaders[1];
	curShader->TurnOn();
	initUniformVal(curShader);

	GLint location;
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,_textures[0]);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D,_textures[1]);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D,noiseTexture);
	for (GLuint i = 0; i < 64; ++i)
		glUniform3fv(glGetUniformLocation(curShader->getShaderId(), ("samples[" + std::to_string((long long)(i)) + "]").c_str()), 1, &ssaoKernel[i][0]);

	drawScreenQuad(screenQuatID);

	curShader->TurnOff();
	glBindFramebuffer(GL_FRAMEBUFFER,0);
	
	if(useBlur)
	{
		//Blur SSAO 
		glBindFramebuffer(GL_FRAMEBUFFER,_fbos[2]);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		curShader = shaders[2];
		curShader->TurnOn();
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D,_textures[3]);
		drawScreenQuad(screenQuatID);
		curShader->TurnOff();
		glBindFramebuffer(GL_FRAMEBUFFER,0);
	}
	
 
	//light 
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	curShader = shaders[3];
	curShader->TurnOn();

	location = shaders[3]->GetVariable("draw_mode");
	shaders[3]->SetInt(location,draw_mode);
	location = shaders[3]->GetVariable("gPositionDepth");
	shaders[3]->SetInt(location,0);
	location = shaders[3]->GetVariable("gNormal");
	shaders[3]->SetInt(location,1);
	location = shaders[3]->GetVariable("gAlbedo");
	shaders[3]->SetInt(location,2);
	location = shaders[3]->GetVariable("ssao");
	shaders[3]->SetInt(location,3);
	location = shaders[3]->GetVariable("light.Position");
	glm::vec3 lightPosView = glm::vec3(camera->GetViewMatrix() * glm::vec4(lightPos, 1.0));
	shaders[3]->SetFloat3V(location,1,glm::value_ptr(lightPosView));
	location = shaders[3]->GetVariable("light.Color");
	shaders[3]->SetFloat3V(location,1,glm::value_ptr(lightColor));
	location = shaders[3]->GetVariable("light.Linear");
	shaders[3]->SetFloat(location,0.09);
	location = shaders[3]->GetVariable("light.Quadratic");
	shaders[3]->SetFloat(location,0.032);
	location = shaders[3]->GetVariable("useSSAO");
	shaders[3]->SetInt(location,useSSAO);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,_textures[0]);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D,_textures[1]);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D,_textures[2]);
	glActiveTexture(GL_TEXTURE3);
	if(useBlur)
	{
		glBindTexture(GL_TEXTURE_2D,_textures[4]);
	}
	else
	{
		glBindTexture(GL_TEXTURE_2D,_textures[3]);
	}

	drawScreenQuad(screenQuatID);
	curShader->TurnOff();

}