Ejemplo n.º 1
0
void Renderer::renderDeferredShading()
{
  if (!m_shaderDSLighting || !m_shaderDSCompositing)
    init(m_windowWidth, m_windowHeight);

  if (!m_dsLightColor || !m_dsLightRootNode)
    throw std::string("Error in renderDeferredShading - Light Color or Light Root Node was not set");

  FBO *a = new FBO(m_windowWidth,m_windowHeight,3,false,false);

  a->bind();

  glCullFace(GL_FRONT);
  glEnable(GL_CULL_FACE);
  glDisable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ONE);
  glClearColor(0, 0, 0, 0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  m_shaderDSLighting->bind();

  m_shaderDSLighting->sendMat4("viewMatrix", m_currentViewMatrix);
  m_shaderDSLighting->sendMat4("projectionMatrix", m_currentProjectionMatrix);

  m_shaderDSLighting->sendSampler2D("positionMap", m_gBuffer->getColorTexture(0), 0);
  m_shaderDSLighting->sendSampler2D("normalMap", m_gBuffer->getColorTexture(1), 1);

  m_shaderDSLighting->sendInt("windowWidth", m_windowWidth);
  m_shaderDSLighting->sendInt("windowHeight", m_windowHeight);

  m_shaderDSLighting->sendVec3("lightColor", *m_dsLightColor);

  m_dsLightRootNode->render(*m_shaderDSLighting);

  glDisable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glDisable(GL_BLEND);
  glClearColor(1.0, 1.0, 1.0, 0.0);
  m_shaderDSLighting->unbind();
  a->unbind();

  //COMPOSITING TEIL ===============================
  bindFBO();
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  m_shaderDSCompositing->bind();

  m_shaderDSCompositing->sendSampler2D("colorMap", getLastFBO()->getColorTexture(2), 0);
  m_shaderDSCompositing->sendSampler2D("lightMap", a->getColorTexture(2), 1);

  m_sfq.renderGeometry();

  m_shaderDSCompositing->unbind();
  unbindFBO();

  delete a;
}
Ejemplo n.º 2
0
 void onFrame(){
   
   model = glm::mat4(1.0);
   
   vec3 totals = rotateBehavior.tick(now()).totals();
   model = glm::rotate(model, totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, totals.z, vec3(0.0f,0.0f,1.0f));
   
   
   //draw cube 1 into an offscreen texture
   fbo.bind(); {
     glViewport(0, 0, fbo.width, fbo.height);
     glClearColor(0.1,0.1,0.1,1.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     draw(model, cubeMeshBuffer1, texture, textureProgram);
     
   } fbo.unbind();
   
   
   //draw cube 2 with the offscreen texture using phong shading
   glViewport(0, 0, width, height);
   glClearColor(0.0,0.0,0.0,1.0);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
   model = glm::mat4(1.0);
   
   model = glm::translate(model, vec3(1.0,0.0,0.0));
   model = glm::rotate(model, totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, totals.z, vec3(0.0f,0.0f,1.0f));
   
   draw(model, cubeMeshBuffer2, fbo.texture, phongProgram);
   
   
   
   //draw cube 3 - a colored cube
   
   model = mat4(1.0);
   model = glm::translate(model, vec3(-1.0,0.0,0.0));
   
   model = glm::rotate(model, -totals.x, vec3(1.0f,0.0f,0.0f));
   model = glm::rotate(model, -totals.y, vec3(0.0f,1.0f,0.0f));
   model = glm::rotate(model, -totals.z, vec3(0.0f,0.0f,1.0f));
   
   programColor.bind(); {
     glUniformMatrix4fv(programColor.uniform("model"), 1, 0, ptr(model));
     glUniformMatrix4fv(programColor.uniform("view"), 1, 0, ptr(view));
     glUniformMatrix4fv(programColor.uniform("proj"), 1, 0, ptr(proj));
     
     cubeMeshBuffer3.draw();
     
   } programColor.unbind();
   
 }
	void onDraw(Graphics& g){

		// To render our scene to the FBO, we must first bind it
		fbo.bind();
			// Clear FBO
			g.clear(Graphics::COLOR_BUFFER_BIT | Graphics::DEPTH_BUFFER_BIT);

			// Render our scene as we normally would
			g.draw(mesh);

		// When done rendering our scene to the FBO, we must unbind it
		fbo.unbind();

		// To prove that this all worked, we render the FBO's color texture
		tex.quadViewport(g);
	}
Ejemplo n.º 4
0
void Renderer::renderSSAO()
{
  if (!m_shaderSSAOcalc || !m_shaderSSAOblur || !m_shaderSSAOfinal)
    init(m_windowWidth, m_windowHeight);

  FBO *a = new FBO(m_windowWidth, m_windowHeight, 3, false, false);
  FBO *b = new FBO(m_windowWidth, m_windowHeight, 3, false, false);

  a->bind();
  glClearColor(1, 1, 1, 1);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  m_shaderSSAOcalc->bind();

  m_shaderSSAOcalc->sendSampler2D("positionMap", m_gBuffer->getColorTexture(0), 0);
  m_shaderSSAOcalc->sendSampler2D("normalMap", m_gBuffer->getColorTexture(1), 1);
  m_shaderSSAOcalc->sendMat4("sceneProjectionMatrix", m_currentProjectionMatrix);
  m_shaderSSAOcalc->sendFloat("radius", *m_ssaoRadius);
  m_shaderSSAOcalc->sendFloat("quality", *m_ssaoQuality);

  m_sfq.renderGeometry();

  m_shaderSSAOcalc->unbind();
  a->unbind();



  //Blur #1 SSAO calculation
  b->bind();

  //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  m_shaderSSAOblur->bind();
  m_shaderSSAOblur->sendSampler2D("colortexture", a->getColorTexture(2), 0);
  m_shaderSSAOblur->sendInt("secondPass", 0);
  m_sfq.renderGeometry();

  m_shaderSSAOblur->unbind();
  b->unbind();



  //Blur #2 SSAO calculation
  a->bind();
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  m_shaderSSAOblur->bind();
  m_shaderSSAOblur->sendSampler2D("colortexture", b->getColorTexture(2), 0);
  m_shaderSSAOblur->sendFloat("secondPass", 1);
  m_sfq.renderGeometry();

  m_shaderSSAOblur->unbind();
  a->unbind();

  glClearColor(0, 0, 0, 0);


  //COLOR COMPOSITING
  bindFBO();
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  m_shaderSSAOfinal->bind();
  m_shaderSSAOfinal->sendSampler2D("colorMap", getLastFBO()->getColorTexture(2), 0);
  m_shaderSSAOfinal->sendSampler2D("ssaoMap", a->getColorTexture(2), 1);
  m_sfq.renderGeometry();
  m_shaderSSAOfinal->unbind();
  unbindFBO();

  delete a;
  delete b;
}