Ejemplo n.º 1
0
void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
{
    assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight());
    float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight();
    {
        auxiliary.Bind();
        glUseProgram(FullScreenShader::Gaussian6VBlurShader::Program);
        glBindVertexArray(FullScreenShader::Gaussian6VBlurShader::vao);

        glUniform2f(FullScreenShader::Gaussian6VBlurShader::uniform_pixel, inv_width, inv_height);

        setTexture(0, in_fbo.getRTT()[0], GL_LINEAR, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glUniform1i(FullScreenShader::Gaussian6VBlurShader::uniform_tex, 0);

        glDrawArrays(GL_TRIANGLES, 0, 3);
    }
    {
        in_fbo.Bind();
        glUseProgram(FullScreenShader::Gaussian6HBlurShader::Program);
        glBindVertexArray(FullScreenShader::Gaussian6HBlurShader::vao);

        glUniform2f(FullScreenShader::Gaussian6HBlurShader::uniform_pixel, inv_width, inv_height);

        setTexture(0, auxiliary.getRTT()[0], GL_LINEAR, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glUniform1i(FullScreenShader::Gaussian6HBlurShader::uniform_tex, 0);

        glDrawArrays(GL_TRIANGLES, 0, 3);
    }
}
Ejemplo n.º 2
0
	virtual void RenderFrame()
	{
		FBO.Bind();
		FBO.DrawFrameBuffer();

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, GetWindowWidth(), GetWindowHeight());

		float r = flow / 100.0f;
		ProgramRender["varyingcolor"] = glm::vec4(r, 0.0f, 1.0f, 1.0f);
		ProgramRender["MVP"] = FPSCamera.GetModelViewProjection();
		ProgramRender.Use();
		Plain.DrawMesh();

		FBO.UnBind();

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, GetWindowWidth(), GetWindowHeight());

		Text1.Activate();
		ProgramDraw.Use();
		glm::mat4 MVP = FPSCamera.GetModelViewProjection();
		ProgramDraw["transformMatrix"] = MVP;
		Android.DrawMesh();

		if (flow >= 100)
		{
			flow = 0;
		}
		flow++;
	}
Ejemplo n.º 3
0
void PostProcessing::renderMotionBlur(unsigned cam, FrameBuffer &in_fbo, FrameBuffer &out_fbo)
{
    MotionBlurProvider * const cb = (MotionBlurProvider *)irr_driver->
        getCallback(ES_MOTIONBLUR);

    scene::ICameraSceneNode * const camnode =
        Camera::getCamera(cam)->getCameraSceneNode();
    // Calculate the kart's Y position on screen
    const core::vector3df pos =
        Camera::getCamera(cam)->getKart()->getNode()->getPosition();
    float ndc[4];
    core::matrix4 trans = camnode->getProjectionMatrix();
    trans *= camnode->getViewMatrix();

    trans.transformVect(ndc, pos);
    const float karty = (ndc[1] / ndc[3]) * 0.5f + 0.5f;
    setMotionBlurCenterY(cam, karty);

    out_fbo.Bind();
    glClear(GL_COLOR_BUFFER_BIT);

    FullScreenShader::MotionBlurShader::getInstance()->SetTextureUnits(createVector<GLuint>(in_fbo.getRTT()[0], irr_driver->getDepthStencilTexture()));
    DrawFullScreenEffect<FullScreenShader::MotionBlurShader>(
                                  // Todo : use a previousPVMatrix per cam, not global
                                  irr_driver->getPreviousPVMatrix(),
                                  cb->getCenter(cam),
                                  cb->getBoostTime(0) * 10, // Todo : should be framerate dependent
                                  0.15f);
}
Ejemplo n.º 4
0
void PostProcessing::renderMotionBlur(unsigned cam, FrameBuffer &in_fbo, FrameBuffer &out_fbo)
{
    MotionBlurProvider * const cb = (MotionBlurProvider *)irr_driver->
        getCallback(ES_MOTIONBLUR);

    scene::ICameraSceneNode * const camnode =
        Camera::getCamera(cam)->getCameraSceneNode();
    // Calculate the kart's Y position on screen
    const core::vector3df pos =
        Camera::getCamera(cam)->getKart()->getNode()->getPosition();
    float ndc[4];
    core::matrix4 trans = camnode->getProjectionMatrix();
    trans *= camnode->getViewMatrix();

    trans.transformVect(ndc, pos);
    const float karty = (ndc[1] / ndc[3]) * 0.5f + 0.5f;
    setMotionBlurCenterY(cam, karty);

    out_fbo.Bind();
    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(FullScreenShader::MotionBlurShader::Program);
    glBindVertexArray(FullScreenShader::MotionBlurShader::vao);

    setTexture(0, in_fbo.getRTT()[0], GL_NEAREST, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    FullScreenShader::MotionBlurShader
                    ::setUniforms(cb->getBoostTime(cam), cb->getCenter(cam),
                                  cb->getDirection(cam), 0.15f,
                                  cb->getMaxHeight(cam) * 0.7f, 0);

    glDrawArrays(GL_TRIANGLES, 0, 3);
}
Ejemplo n.º 5
0
void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
{
    assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight());
    float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight();
    {
        auxiliary.Bind();

        FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(createVector<GLuint>(in_fbo.getRTT()[0]));
        DrawFullScreenEffect<FullScreenShader::Gaussian6VBlurShader>(core::vector2df(inv_width, inv_height));
    }
    {
        in_fbo.Bind();

        FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(createVector<GLuint>(auxiliary.getRTT()[0]));
        DrawFullScreenEffect<FullScreenShader::Gaussian6HBlurShader>(core::vector2df(inv_width, inv_height));
    }
}
Ejemplo n.º 6
0
void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
{
    assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight());
    if (CVS->supportsComputeShadersFiltering())
        glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT);
    float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight();
    {
        if (!CVS->supportsComputeShadersFiltering())
        {
            auxiliary.Bind();
            FullScreenShader::Gaussian17TapHShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0], irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0]);
            DrawFullScreenEffect<FullScreenShader::Gaussian17TapHShader>(core::vector2df(inv_width, inv_height));
        }
        else
        {
            glUseProgram(FullScreenShader::ComputeGaussian17TapHShader::getInstance()->Program);
            glBindSampler(FullScreenShader::ComputeGaussian17TapHShader::getInstance()->TU_dest, 0);
            FullScreenShader::ComputeGaussian17TapHShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0], irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0]);
            glBindImageTexture(FullScreenShader::ComputeGaussian17TapHShader::getInstance()->TU_dest, auxiliary.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
            FullScreenShader::ComputeGaussian17TapHShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height));
            glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1);
        }
    }
    if (CVS->supportsComputeShadersFiltering())
        glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
    {
        if (!CVS->supportsComputeShadersFiltering())
        {
            in_fbo.Bind();

            FullScreenShader::Gaussian17TapVShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0], irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0]);
            DrawFullScreenEffect<FullScreenShader::Gaussian17TapVShader>(core::vector2df(inv_width, inv_height));
        }
        else
        {
            glUseProgram(FullScreenShader::ComputeGaussian17TapVShader::getInstance()->Program);
            glBindSampler(FullScreenShader::ComputeGaussian17TapVShader::getInstance()->TU_dest, 0);
            FullScreenShader::ComputeGaussian17TapVShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0], irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0]);
            glBindImageTexture(FullScreenShader::ComputeGaussian17TapVShader::getInstance()->TU_dest, in_fbo.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
            FullScreenShader::ComputeGaussian17TapVShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height));
            glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1);
        }
    }
    if (CVS->supportsComputeShadersFiltering())
        glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
}
Ejemplo n.º 7
0
void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary, float sigmaV, float sigmaH)
{
    assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight());
    float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight();
    {
        if (!irr_driver->hasARBComputeShaders())
        {
            auxiliary.Bind();

            FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]);
            DrawFullScreenEffect<FullScreenShader::Gaussian6VBlurShader>(core::vector2df(inv_width, inv_height), sigmaV);
        }
        else
        {
            glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
            glUseProgram(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->Program);
            FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]);
            glBindSampler(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->TU_dest, 0);
            glBindImageTexture(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->TU_dest, auxiliary.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F);
            FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height), sigmaV);
            glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1);
        }
    }
    {
        if (!irr_driver->hasARBComputeShaders())
        {
            in_fbo.Bind();

            FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]);
            DrawFullScreenEffect<FullScreenShader::Gaussian6HBlurShader>(core::vector2df(inv_width, inv_height), sigmaH);
        }
        else
        {
            glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
            glUseProgram(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->Program);
            FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]);
            glBindSampler(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->TU_dest, 0);
            glBindImageTexture(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->TU_dest, in_fbo.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F);
            FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height), sigmaH);
            glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1);
            glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
        }
    }
}
Ejemplo n.º 8
0
static void renderDoF(FrameBuffer &fbo, GLuint rtt)
{
    fbo.Bind();
    glUseProgram(FullScreenShader::DepthOfFieldShader::Program);
    glBindVertexArray(FullScreenShader::DepthOfFieldShader::vao);
    setTexture(0, rtt, GL_LINEAR, GL_LINEAR);
    setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
    FullScreenShader::DepthOfFieldShader::setUniforms(0, 1);

    glDrawArrays(GL_TRIANGLES, 0, 3);
}
Ejemplo n.º 9
0
static void toneMap(FrameBuffer &fbo, GLuint rtt)
{
    fbo.Bind();
    glUseProgram(FullScreenShader::ToneMapShader::Program);
    glBindVertexArray(FullScreenShader::ToneMapShader::vao);
    setTexture(0, rtt, GL_NEAREST, GL_NEAREST);
    setTexture(1, irr_driver->getRenderTargetTexture(RTT_LOG_LUMINANCE), GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST);
    FullScreenShader::ToneMapShader::setUniforms(irr_driver->getExposure(), irr_driver->getLwhite(), 0, 1);

    glDrawArrays(GL_TRIANGLES, 0, 3);
}
Ejemplo n.º 10
0
void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
{
    assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight());
    float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight();
    {
        if (!irr_driver->hasARBComputeShaders())
        {
            auxiliary.Bind();
            FullScreenShader::Gaussian17TapHShader::getInstance()->SetTextureUnits(createVector<GLuint>(in_fbo.getRTT()[0], irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0]));
            DrawFullScreenEffect<FullScreenShader::Gaussian17TapHShader>(core::vector2df(inv_width, inv_height));
        }
        else
        {

            glUseProgram(FullScreenShader::ComputeGaussian17TapHShader::getInstance()->Program);
            glBindImageTexture(FullScreenShader::ComputeGaussian17TapHShader::getInstance()->TU_source, in_fbo.getRTT()[0], 0, false, 0, GL_READ_ONLY, GL_R16F);
            glBindImageTexture(FullScreenShader::ComputeGaussian17TapHShader::getInstance()->TU_depth, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], 1, false, 0, GL_READ_ONLY, GL_R32F);
            glBindImageTexture(FullScreenShader::ComputeGaussian17TapHShader::getInstance()->TU_dest, auxiliary.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
            FullScreenShader::ComputeGaussian17TapHShader::getInstance()->setUniforms();
            glDispatchCompute(in_fbo.getWidth() / 8, in_fbo.getHeight() / 8, 1);
        }
    }
    {
        if (!irr_driver->hasARBComputeShaders())
        {
            in_fbo.Bind();

            FullScreenShader::Gaussian17TapVShader::getInstance()->SetTextureUnits(createVector<GLuint>(auxiliary.getRTT()[0], irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0]));
            DrawFullScreenEffect<FullScreenShader::Gaussian17TapVShader>(core::vector2df(inv_width, inv_height));
        }
        else
        {
            glUseProgram(FullScreenShader::ComputeGaussian17TapVShader::getInstance()->Program);
            glBindImageTexture(FullScreenShader::ComputeGaussian17TapVShader::getInstance()->TU_source, auxiliary.getRTT()[0], 0, false, 0, GL_READ_ONLY, GL_R16F);
            glBindImageTexture(FullScreenShader::ComputeGaussian17TapVShader::getInstance()->TU_depth, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], 1, false, 0, GL_READ_ONLY, GL_R32F);
            glBindImageTexture(FullScreenShader::ComputeGaussian17TapVShader::getInstance()->TU_dest, in_fbo.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
            FullScreenShader::ComputeGaussian17TapVShader::getInstance()->setUniforms();
            glDispatchCompute(in_fbo.getWidth() / 8, in_fbo.getHeight() / 8, 1);
        }
    }
}
Ejemplo n.º 11
0
static void renderDoF(FrameBuffer &fbo, GLuint rtt)
{
    fbo.Bind();
    FullScreenShader::DepthOfFieldShader::getInstance()->SetTextureUnits(createVector<GLuint>(rtt, irr_driver->getDepthStencilTexture()));
    DrawFullScreenEffect<FullScreenShader::DepthOfFieldShader>();
}
Ejemplo n.º 12
0
static void toneMap(FrameBuffer &fbo, GLuint rtt)
{
    fbo.Bind();
    FullScreenShader::ToneMapShader::getInstance()->SetTextureUnits(createVector<GLuint>(rtt));
    DrawFullScreenEffect<FullScreenShader::ToneMapShader>();
}
Ejemplo n.º 13
0
void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
{
    assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight());
    float inv_width = 1.0f / in_fbo.getWidth(), inv_height = 1.0f / in_fbo.getHeight();
    {
#if WIN32
        if (irr_driver->getGLSLVersion() < 430)
#endif
        {
            auxiliary.Bind();
            glUseProgram(FullScreenShader::Gaussian17TapHShader::Program);
            glBindVertexArray(FullScreenShader::Gaussian17TapHShader::vao);

            glUniform2f(FullScreenShader::Gaussian17TapHShader::uniform_pixel, inv_width, inv_height);

            setTexture(0, in_fbo.getRTT()[0], GL_LINEAR, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
            setTexture(1, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], GL_LINEAR, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
            glUniform1i(FullScreenShader::Gaussian17TapHShader::uniform_tex, 0);
            glUniform1i(FullScreenShader::Gaussian17TapHShader::uniform_depth, 1);

            glDrawArrays(GL_TRIANGLES, 0, 3);
        }
#if WIN32
        else
        {

            glUseProgram(FullScreenShader::ComputeGaussian17TapHShader::Program);
            glBindImageTexture(0, in_fbo.getRTT()[0], 0, false, 0, GL_READ_ONLY, GL_R16F);
            glBindImageTexture(1, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], 1, false, 0, GL_READ_ONLY, GL_R32F);
            glBindImageTexture(2, auxiliary.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
            glUniform1i(FullScreenShader::ComputeGaussian17TapHShader::uniform_source, 0);
            glUniform1i(FullScreenShader::ComputeGaussian17TapHShader::uniform_depth, 1);
            glUniform1i(FullScreenShader::ComputeGaussian17TapHShader::uniform_dest, 2);
            glDispatchCompute(in_fbo.getWidth() / 8, in_fbo.getHeight() / 8, 1);
        }
#endif
    }
    {
#if WIN32
        if (irr_driver->getGLSLVersion() < 430)
#endif
        {
            in_fbo.Bind();
            glUseProgram(FullScreenShader::Gaussian17TapVShader::Program);
            glBindVertexArray(FullScreenShader::Gaussian17TapVShader::vao);

            glUniform2f(FullScreenShader::Gaussian17TapVShader::uniform_pixel, inv_width, inv_height);

            setTexture(0, auxiliary.getRTT()[0], GL_LINEAR, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
            setTexture(1, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], GL_LINEAR, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
            glUniform1i(FullScreenShader::Gaussian17TapVShader::uniform_tex, 0);
            glUniform1i(FullScreenShader::Gaussian17TapVShader::uniform_depth, 1);

            glDrawArrays(GL_TRIANGLES, 0, 3);
        }
#if WIN32
        else
        {
            glUseProgram(FullScreenShader::ComputeGaussian17TapVShader::Program);
            glBindImageTexture(0, auxiliary.getRTT()[0], 0, false, 0, GL_READ_ONLY, GL_R16F);
            glBindImageTexture(1, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], 1, false, 0, GL_READ_ONLY, GL_R32F);
            glBindImageTexture(2, in_fbo.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
            glUniform1i(FullScreenShader::ComputeGaussian17TapVShader::uniform_source, 0);
            glUniform1i(FullScreenShader::ComputeGaussian17TapVShader::uniform_depth, 1);
            glUniform1i(FullScreenShader::ComputeGaussian17TapVShader::uniform_dest, 2);
            glDispatchCompute(in_fbo.getWidth() / 8, in_fbo.getHeight() / 8, 1);
        }
#endif
    }
}
Ejemplo n.º 14
0
static void toneMap(FrameBuffer &fbo, GLuint rtt, float vignette_weight)
{
    fbo.Bind();
    FullScreenShader::ToneMapShader::getInstance()->SetTextureUnits(rtt);
    DrawFullScreenEffect<FullScreenShader::ToneMapShader>(vignette_weight);
}
Ejemplo n.º 15
0
  void draw_frame(Device *device) {
    SR_CHECK_ERROR("Begin RenderFrame");
    RenderState &render_state = device->render_state();
    vec4ub color(77, 77, 77, 255);
    render_state.ClearBuffer(true, true, false, color);

    //3d
    device->render_state().Set3D();

    depth_fbo.Bind();  //fbo로 그리기. deferred같은거 구현하기 위해서 임시로 시도함
    device->render_state().Set3D();
    render_state.ClearBuffer(true, true, false, color);

    VertexList vert_list;
    vert_list.push_back(CreateVertex(vec3(-0.5, -0.5, 0), vec2(0, 0)));
    vert_list.push_back(CreateVertex(vec3(0.5, -0.5, 0), vec2(1, 0)));
    vert_list.push_back(CreateVertex(vec3(0, 0.5, 0), vec2(0.5, 1)));

    //vbo, ibo 적절히 만들기
    if(vbo.Loaded() == false) {
      vbo.Init(vert_list);
    }
    if(wire_ibo.Loaded() == false) {
      IndexList index_list;
      index_list.push_back(0);
      index_list.push_back(1);
      index_list.push_back(1);
      index_list.push_back(2);
      index_list.push_back(2);
      index_list.push_back(0);
      wire_ibo.Init(index_list);
    }

    {
      //shader사용 선언이 가장 먼저
      device->render_state().UseShader(color_shader);
      SR_CHECK_ERROR("UseShader");

      mat4 mvp(1.0f);
      ShaderVariable mvp_var = color_shader.uniform_var(kMVPHandleName);
      SetUniformMatrix(mvp_var, mvp);

      vec4 color(1.0f);
      ShaderVariable const_color_var = color_shader.uniform_var(kConstColorHandleName);
      SetUniformVector(const_color_var, color);
      SR_CHECK_ERROR("SetVector");

      color_shader.SetVertexList(vert_list);
      color_shader.DrawArrays(kDrawTriangles, vert_list.size());

      color_shader.DrawArrays(kDrawTriangles, vbo);

      color_shader.DrawElements(kDrawLines, vbo, wire_ibo);
    }

    {
      //shader사용 선언이 가장 먼저
      device->render_state().UseShader(simple_shader);
      TexturePtr tex = device->tex_mgr()->Get("sora");
      device->render_state().UseTexture(*tex, 0);
      SR_CHECK_ERROR("UseShader");
      mat4 mvp(1.0f);
      mvp = glm::rotate(mvp, 10.0f, vec3(0, 0, 1));
      ShaderVariable mvp_var = simple_shader.uniform_var(kMVPHandleName);
      SetUniformMatrix(mvp_var, mvp);
      SR_CHECK_ERROR("SetMatrix");
      simple_shader.SetVertexList(vert_list);
      simple_shader.DrawArrays(kDrawTriangles, vert_list.size());
    }

    //일반 3d객체 그리기+카메라 회전 장착
    {
      //set camera + projection
      float win_width = (float)device->render_state().win_width();
      float win_height = (float)device->render_state().win_height();
      glm::mat4 projection = glm::perspective(45.0f, win_width / win_height, 0.1f, 100.0f);
      float radius = 4;
      float cam_x = radius * cos(SR_DEG_2_RAD(aptitude)) * sin(SR_DEG_2_RAD(latitude));
      float cam_y = radius * sin(SR_DEG_2_RAD(aptitude));
      float cam_z = radius * cos(SR_DEG_2_RAD(aptitude)) * cos(SR_DEG_2_RAD(latitude));
      vec3 eye(cam_x, cam_y, cam_z);
      vec3 center(0);
      vec3 up(0, 1, 0);
      glm::mat4 view = glm::lookAt(eye, center, up);

      glm::mat4 mvp(1.0f);
      mvp = projection * view;
      ShaderVariable mvp_var = simple_shader.uniform_var(kMVPHandleName);
      SetUniformMatrix(mvp_var, mvp);
      SR_CHECK_ERROR("SetMatrix");

      GeometricObject<Vertex> mesh;
      //mesh.PointTeapot(0.05f);
      //mesh.WireTeapot(0.05f);
      //mesh.SolidTeapot(0.05f);
      //mesh.WireShpere(1, 16, 16);
      //mesh.PointShpere(1, 16, 16);
      //mesh.SolidSphere(1, 16, 16);
      //mesh.SolidCube(1, 1, 1);
      //mesh.WireCube(1, 1, 1);
      mesh.PointCube(1, 1, 1);
      //mesh.PointCylinder(1, 1, 2, 8, 8);
      //mesh.WireCylinder(1, 1, 2, 8, 8);
      mesh.SolidCylinder(1, 1, 2, 8, 8);
      //mesh.WireAxis(5);
      //mesh.SolidPlane(3);
      //mesh.WirePlane(3, 0.1f);
      //mesh.SolidTorus(1, 0.1);
      //mesh.SolidCone(2, 2);
      auto it = mesh.Begin();
      auto endit = mesh.End();
      for( ; it != endit ; ++it) {
        const DrawCmdData<Vertex> &cmd = *it;
        //앞면 뒷면 그리기를 허용/불가능 정보까지 내장해야
        //뚜껑없는 원통 그리기가 편하다
        if(cmd.disable_cull_face == true) {
          glDisable(GL_CULL_FACE);
        }
        simple_shader.SetVertexList(cmd.vertex_list);
        if(cmd.index_list.empty()) {
          simple_shader.DrawArrays(cmd.draw_mode, cmd.vertex_list.size());
        } else {
          simple_shader.DrawElements(cmd.draw_mode, cmd.index_list);
        }
        if(cmd.disable_cull_face == true) {
          glEnable(GL_CULL_FACE);
        }
      }
    }
    depth_fbo.Unbind();

    /*
    //fbo에 있는 내용을 적절히 그리기
    {
    device->render_state().Set2D();
    device->render_state().UseShader(simple_shader);
    ShaderVariable mvp_var = simple_shader.uniform_var(kMVPHandleName);
    mat4 world_mat(1.0f);
    SetUniformMatrix(mvp_var, world_mat);

    //device->render_state().UseTexture(depth_fbo.color_tex());
    device->render_state().UseTexture(depth_fbo.depth_tex());

    Vertex2DList vert_list;
    vert_list.push_back(CreateVertex2D(-1, -1, 0, 0));
    vert_list.push_back(CreateVertex2D(1, -1, 1, 0));
    vert_list.push_back(CreateVertex2D(1, 1, 1, 1));
    vert_list.push_back(CreateVertex2D(-1, 1, 0, 1));
    simple_shader.SetVertexList(vert_list);
    simple_shader.DrawArrays(kDrawTriangleFan, vert_list.size());
    }
    */
    null_post_effect.DrawScissor(depth_fbo.color_tex(), 0, 0, 320, 480);
    grayscale_post_effect.DrawScissor(depth_fbo.color_tex(), 320, 0, 320, 480);
    grayscale_post_effect.Draw(depth_fbo.color_tex(), 100, 100, 100, 100);

    SR_CHECK_ERROR("End RenderFrame");
  }