Esempio n. 1
0
void PostProcessSample::update(float elapsedTime)
{
    _modelNode->rotateY(elapsedTime * MATH_DEG_TO_RAD(0.25f));

    // Only the last sample will check live updating of material parameters
    if (_compositorIndex == _compositors.size() - 1)
    {
        Compositor* compositor = _compositors[_compositorIndex];
        MaterialParameter* elapsedParam  = compositor->getMaterial()->getParameter("u_elapsedTime");
        if (elapsedParam)
            elapsedParam->setValue(elapsedTime);
        MaterialParameter* randomParam = compositor->getMaterial()->getParameter("u_random");
        if (randomParam)
            randomParam->setValue(MATH_RANDOM_0_1());
    }
}
Esempio n. 2
0
void PostProcessSample::initialize()
{
    _font = Font::create("res/ui/arial.gpb");

    // Load game scene from file
    _scene = Scene::load("res/common/duck.gpb");
    _scene->getActiveCamera()->setAspectRatio(getAspectRatio());

    // Initialize box model
    _modelNode = _scene->findNode("duck");
    Model* model = dynamic_cast<Model*>(_modelNode->getDrawable());
    Material* material = model->setMaterial("res/common/duck.material");
    // Get light node
    Node* lightNode = _scene->findNode("directionalLight1");
    Light* light = lightNode->getLight();
    material->getParameter("u_directionalLightColor[0]")->setValue(light->getColor());
    material->getParameter("u_directionalLightDirection[0]")->setValue(lightNode->getForwardVectorView());

    // Create one frame buffer for the full screen compositerss.
    _frameBuffer = FrameBuffer::create("PostProcessSample", FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT);
    DepthStencilTarget* dst = DepthStencilTarget::create("PostProcessSample", DepthStencilTarget::DEPTH_STENCIL, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT);
    _frameBuffer->setDepthStencilTarget(dst);
    SAFE_RELEASE(dst);

    // Create our compositors that all output to the default framebuffer.
    Compositor* compositor = NULL;

    compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Passthrough");
    _compositors.push_back(compositor);

    compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Grayscale");
    _compositors.push_back(compositor);

    compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Sepia");
    _compositors.push_back(compositor);

    compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Pixelate");
    _compositors.push_back(compositor);

    compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Sobel Edge");
    _compositors.push_back(compositor);
    compositor->getMaterial()->getParameter("u_width")->setValue((float)FRAMEBUFFER_WIDTH / 2.0f);
    compositor->getMaterial()->getParameter("u_height")->setValue((float)FRAMEBUFFER_HEIGHT / 2.0f);

    compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Gaussian Blur");
    _compositors.push_back(compositor);
    compositor->getMaterial()->getParameter("u_length")->setValue(1.0f / ((float)FRAMEBUFFER_WIDTH / 2.0f));

    compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Old Film");
    _compositors.push_back(compositor);
    compositor->getMaterial()->getParameter("u_sepiaValue")->setValue(0.8f);
    compositor->getMaterial()->getParameter("u_noiseValue")->setValue(0.4f);
    compositor->getMaterial()->getParameter("u_scratchValue")->setValue(0.4f);
    compositor->getMaterial()->getParameter("u_innerVignetting")->setValue(0.9f);
    compositor->getMaterial()->getParameter("u_outerVignetting")->setValue(0.9f);
}