Beispiel #1
0
void PMirror::initialize()
{
    m_reflectionCamera = PNEW(PCamera("reflection", this));
    m_reflectionCamera->setFixed(true);

    // Framebuffer
    PResourceManager *resMgr = scene()->context()->module<PResourceManager>("resource-manager");
    
    const puint32 *rect = scene()->context()->rect();
    m_reflectionFB = resMgr->createFrameBuffer(P_NULL,
                                               rect[2],
                                               rect[3],
                                               P_GLTEXTURE_FORMAT_RGBA8888,
                                               P_GLTEXTURE_FORMAT_DEPTH_COMPONENT16);
    m_reflectionFB->retain();

    // Geometry and material
    setGeometry(PNEW(PGeometryPlane(resMgr)));
    setMaterial(PNEW(PMaterial("reflection.pmt", resMgr)));

    material()->parameter("texture")      = m_reflectionFB->colorBuffer();
    material()->parameter("inv-viewport") = pVector2(1.0f / (pfloat32)rect[2], 1.0f / (pfloat32)rect[3]);
    material()->parameter("color")        = pVector3(0.0f, 0.0f, 1.0f);
    material()->parameter("blend")        = 0.7f;

	// Render pass
    m_reflectionPass = PNEW(PRenderPass("reflection", scene())); 

}
void PRenderer::render(PRenderState *renderState)
{
    PASSERT(m_scene->mainCamera() != P_NULL);

    // Create a default render pass if none exists
    if (m_renderPassArray.isEmpty())
    {
        PRenderPass *renderPass = PNEW(PRenderPass("default", m_scene));
        renderPass->setCamera(m_scene->mainCamera());
        renderPass->queue()->addNodes(m_scene->root());
        renderPass->target()->setColorClearValue(m_backgroundColor);

        PShadowPass *shadowPass = PNEW(PShadowPass("shadow", m_scene));
        
        addRenderPass(shadowPass);
        addRenderPass(renderPass);
    }

    if (m_renderPassArray.isEmpty())
    {
        PLOG_WARNING("There is no valid render pass existing.");
        return ;
    }

    for (puint32 i = 0; i < m_renderPassArray.size(); ++i)
    {
        m_renderPassArray[i]->render(renderState);
    }
}