Exemple #1
0
void Scene::pointLightPass(RenderTarget *target)
{
    if(!this->pointLights.empty ())
    {
        for(int i =0;i<pointLights.size ();i++)
        {
            ShaderProgram * shader = ShaderPool::getInstance ()->get("point_light_pass");
            shader->use ();
            PointLight * light = this->pointLights[i];
            light->apply (shader,0);

            m_quad->setShaderProgram (shader);
            QMatrix4x4 m;
            m.setToIdentity ();
            auto camera = target->camera ();
            shader->setUniformMat4v ("g_MVP_matrix",m.data ());
            shader->setUniform2Float ("g_screen_size",1024,768);
            shader->setUniformInteger ("g_color_map",0);
            shader->setUniformInteger ("g_position_map",1);
            shader->setUniformInteger ("g_normal_map",2);
            shader->setUniform3Float ("g_eye_position",
                                      camera->pos ().x(),
                                      camera->pos ().y(),
                                      camera->pos ().z());
            m_quad->draw (true);
        }
    }
}
Exemple #2
0
void Scene::spotLightPass(RenderTarget * target)
{
    if(!this->spotLights.empty ())
    {
        for(int i =0;i<spotLights.size ();i++)
        {
            PointLight * light = this->spotLights[i];
            light->shadowFBO ()->BindForReading(GL_TEXTURE3);
            ShaderProgram * shader = ShaderPool::getInstance ()->get("spot_light_pass");
            shader->use ();
            light->shadowFBO ()->applyShadowMapTexture (shader,3);

            light->apply (shader,0);
            m_quad->setShaderProgram (shader);
            QMatrix4x4 m;
            m.setToIdentity ();
            auto camera = target->camera ();
            shader->setUniformMat4v ("g_MVP_matrix",m.data ());
            shader->setUniform2Float ("g_screen_size",1024,768);
            shader->setUniformInteger ("g_color_map",0);
            shader->setUniformInteger ("g_position_map",1);
            shader->setUniformInteger ("g_normal_map",2);
            shader->setUniform3Float ("g_eye_position",
                                      camera->pos ().x(),
                                      camera->pos ().y(),
                                      camera->pos ().z());
            QMatrix4x4 lightView;
            lightView.setToIdentity();
            lightView.lookAt(spotLights[0]->getPos(),this->spotLights[0]->getPos()+this->spotLights[0]->getDirection(),QVector3D(0,1,0));
            QMatrix4x4 light_vp;
            light_vp = camera->getProjection () * lightView ;
            shader->setUniformMat4v ("g_light_vp_matrix",light_vp.data ());
            m_quad->draw (true);
        }
    }
}