Beispiel #1
0
void MyGLWidget::carregaShaders()
{
  // Creem els shaders per al fragment shader i el vertex shader
  QOpenGLShader fs (QOpenGLShader::Fragment, this);
  QOpenGLShader vs (QOpenGLShader::Vertex, this);
  // Carreguem el codi dels fitxers i els compilem
  fs.compileSourceFile("shaders/fragshad.frag");
  vs.compileSourceFile("shaders/vertshad.vert");
  // Creem el program
  program = new QOpenGLShaderProgram(this);
  // Li afegim els shaders corresponents
  program->addShader(&fs);
  program->addShader(&vs);
  // Linkem el program
  program->link();
  // Indiquem que aquest és el program que volem usar
  program->bind();

  // Obtenim identificador per a l'atribut “vertex” del vertex shader
  vertexLoc = glGetAttribLocation (program->programId(), "vertex");
  // Obtenim identificador per a l'atribut “normal” del vertex shader
  normalLoc = glGetAttribLocation (program->programId(), "normal");
  // Obtenim identificador per a l'atribut “matamb” del vertex shader
  matambLoc = glGetAttribLocation (program->programId(), "matamb");
  // Obtenim identificador per a l'atribut “matdiff” del vertex shader
  matdiffLoc = glGetAttribLocation (program->programId(), "matdiff");
  // Obtenim identificador per a l'atribut “matspec” del vertex shader
  matspecLoc = glGetAttribLocation (program->programId(), "matspec");
  // Obtenim identificador per a l'atribut “matshin” del vertex shader
  matshinLoc = glGetAttribLocation (program->programId(), "matshin");

  // Demanem identificadors per als uniforms del vertex shader
  transLoc = glGetUniformLocation (program->programId(), "TG");
  projLoc = glGetUniformLocation (program->programId(), "proj");
  viewLoc = glGetUniformLocation (program->programId(), "view");

  //COLOR
  posFocus = glGetUniformLocation (program->programId(), "posFocus");
  colFocus = glGetUniformLocation (program->programId(), "colFocus");
  llumAmbient = glGetUniformLocation (program->programId(), "llumAmbient");

  franges = glGetUniformLocation (program->programId(), "franges");

}
Beispiel #2
0
void MyGLWidget::carregaShaders()
{

  // Creem els shaders per al fragment shader i el vertex shader
  QOpenGLShader fs (QOpenGLShader::Fragment, this);
  QOpenGLShader vs (QOpenGLShader::Vertex, this);
  // Carreguem el codi dels fitxers i els compilem
  fs.compileSourceFile("shaders/fragshad.frag");
  vs.compileSourceFile("shaders/vertshad.vert");
  // Creem el program
  program = new QOpenGLShaderProgram(this);
  // Li afegim els shaders corresponents
  program->addShader(&fs);
  program->addShader(&vs);
  // Linkem el program
  program->link();
  // Indiquem que aquest és el program que volem usar
  program->bind();

  // Obtenim identificador per a l'atribut “vertex” del vertex shader
  vertexLoc = glGetAttribLocation (program->programId(), "vertex");

  // Obtenim identificador per a l'atribut “color” del vertex shader
  colorLoc = glGetAttribLocation (program->programId(), "color");

  // Uniform locations
  transLoc = glGetUniformLocation(program->programId(), "TG");

  //Uniform projection
  projLoc = glGetUniformLocation(program->programId(), "proj");

  //Uniform view
  viewLoc = glGetUniformLocation(program->programId(), "view");

  glEnable(GL_DEPTH_TEST);


}
Beispiel #3
0
void GLWidget::initializeGL()
{
    initializeOpenGLFunctions();
    glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
    makeCurrent();
    qglClearColor(QColor::fromCmykF(0.79, 0.79, 0.79, 0.0).dark());


    glEnable(GL_DEPTH_TEST);
    glEnable(GL_MULTISAMPLE);
    glEnable(GL_DEPTH_TEST);


    qDebug() << "Loading quad (vertex shader)";
    QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
    vshader->compileSourceFile(":/resources/plane.vert");
    if (!vshader->log().isEmpty()) qDebug() << vshader->log();
    else qDebug() << "done";

    qDebug() << "Loading quad (fragment shader)";
    QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
    fshader->compileSourceFile(":/resources/plane.frag");
    if (!fshader->log().isEmpty()) qDebug() << fshader->log();
    else qDebug() << "done";

    qDebug() << "Loading quad (tessellation control shader)";
    QOpenGLShader *tcshader = new QOpenGLShader(QOpenGLShader::TessellationControl, this);
    tcshader->compileSourceFile(":/resources/plane.tcs.vert");
    if (!tcshader->log().isEmpty()) qDebug() << tcshader->log();
    else qDebug() << "done";

    qDebug() << "Loading quad (tessellation evaluation shader)";
    QOpenGLShader *teshader = new QOpenGLShader(QOpenGLShader::TessellationEvaluation, this);
    teshader->compileSourceFile(":/resources/plane.tes.vert");
    if (!teshader->log().isEmpty()) qDebug() << teshader->log();
    else qDebug() << "done";

    qDebug() << "Loading quad (geometry shader)";
    QOpenGLShader *gshader = new QOpenGLShader(QOpenGLShader::Geometry, this);
    QFile gFile(":/resources/plane.geom");
    gFile.open(QFile::ReadOnly);
    qDebug() << gFile.isOpen() << " File";

    QTextStream in(&gFile);
    QString preambule = "#version 400 core\n"
                        "layout(triangle_strip, max_vertices = 3) out;\n" ;
    QString shaderCode = in.readAll();
    gshader->compileSourceCode(preambule+shaderCode);
    //gshader->compileSourceFile(in.readAll());
    if (!gshader->log().isEmpty()) qDebug() << gshader->log();
    else qDebug() << "done";

    program = new QOpenGLShaderProgram(this);
    program->addShader(vshader);
    program->addShader(fshader);
    program->addShader(tcshader);
    program->addShader(teshader);
    program->addShader(gshader);
    program->bindAttributeLocation("FragColor",0);
    program->bindAttributeLocation("FragNormal",1);
    program->bindAttributeLocation("FragGlowColor",2);
    program->bindAttributeLocation("FragPosition",3);
    GLCHK(program->link());

    GLCHK(program->bind());
    program->setUniformValue("texDiffuse"  , 0);
    program->setUniformValue("texNormal"   , 1);
    program->setUniformValue("texSpecular" , 2);
    program->setUniformValue("texHeight"   , 3);
    program->setUniformValue("texSSAO"     , 4);
    program->setUniformValue("texRoughness", 5);
    program->setUniformValue("texMetallic",  6);
    program->setUniformValue("texMaterial",  7);

    program->setUniformValue("texDiffuseEnvMap", 8);
    program->setUniformValue("texEnvMap"       , 9);

    // lines shader
    qDebug() << "Compiling lines program...";
    preambule = QString("#version 400 core\n")+
                        "layout(line_strip, max_vertices = 3) out;\n" ;
    gshader->compileSourceCode(preambule+shaderCode);

    line_program = new QOpenGLShaderProgram(this);
    line_program->addShader(vshader);
    line_program->addShader(fshader);
    line_program->addShader(tcshader);
    line_program->addShader(teshader);
    line_program->addShader(gshader);
    line_program->bindAttributeLocation("FragColor",0);
    line_program->bindAttributeLocation("FragNormal",1);
    line_program->bindAttributeLocation("FragGlowColor",2);
    line_program->bindAttributeLocation("FragPosition",3);
    GLCHK(line_program->link());

    GLCHK(line_program->bind());
    line_program->setUniformValue("texDiffuse"  , 0);
    line_program->setUniformValue("texNormal"   , 1);
    line_program->setUniformValue("texSpecular" , 2);
    line_program->setUniformValue("texHeight"   , 3);
    line_program->setUniformValue("texSSAO"     , 4);
    line_program->setUniformValue("texRoughness", 5);
    line_program->setUniformValue("texMetallic",  6);
    line_program->setUniformValue("texMaterial",  7);

    line_program->setUniformValue("texDiffuseEnvMap", 8);
    line_program->setUniformValue("texEnvMap"       , 9);


    delete vshader;
    delete fshader;
    delete tcshader;
    delete teshader;
    delete gshader;


    // loading sky box shader
    qDebug() << "Loading skybox shader (vertex shader)";
    vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
    vshader->compileSourceFile(":/resources/skybox.vert.glsl");
    if (!vshader->log().isEmpty()) qDebug() << vshader->log();
    else qDebug() << "done";

    qDebug() << "Loading skybox shader (fragment shader)";
    fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
    fshader->compileSourceFile(":/resources/skybox.frag.glsl");
    if (!fshader->log().isEmpty()) qDebug() << fshader->log();
    else qDebug() << "done";

    skybox_program = new QOpenGLShaderProgram(this);
    skybox_program->addShader(vshader);
    skybox_program->addShader(fshader);
    skybox_program->bindAttributeLocation("FragColor",0);
    skybox_program->bindAttributeLocation("FragNormal",1);
    skybox_program->bindAttributeLocation("FragGlowColor",2);
    skybox_program->bindAttributeLocation("FragPosition",3);
    GLCHK(skybox_program->link());
    GLCHK(skybox_program->bind());
    skybox_program->setUniformValue("texEnv" , 0);


    // loading enviromental shader
    qDebug() << "Loading enviromental shader (vertex shader)";
    vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
    vshader->compileSourceFile(":/resources/env.vert");
    if (!vshader->log().isEmpty()) qDebug() << vshader->log();
    else qDebug() << "done";

    qDebug() << "Loading enviromental shader (geometry shader)";
    gshader = new QOpenGLShader(QOpenGLShader::Geometry, this);
    gshader->compileSourceFile(":/resources/env.geom");
    if (!gshader->log().isEmpty()) qDebug() << gshader->log();
    else qDebug() << "done";

    qDebug() << "Loading enviromental shader (fragment shader)";
    fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
    fshader->compileSourceFile(":/resources/env.frag");
    if (!fshader->log().isEmpty()) qDebug() << fshader->log();
    else qDebug() << "done";

    env_program = new QOpenGLShaderProgram(this);
    env_program->addShader(vshader);
    env_program->addShader(gshader);
    env_program->addShader(fshader);

    GLCHK(env_program->link());
    GLCHK(env_program->bind());
    env_program->setUniformValue("texEnv" , 0);

    delete vshader;
    delete fshader;
    delete gshader;


    // -------------------------------------------------
    // Loading post processing filters
    // -------------------------------------------------

    qDebug() << "Loading post-processing shader (vertex shader)";
    vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
    vshader->compileSourceFile(":/resources/filters_3d.vert");
    if (!vshader->log().isEmpty()) qDebug() << vshader->log();
    else qDebug() << "done";


    qDebug() << "Loading post-processing shader (fragment shader)";
    fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
    fshader->compileSourceFile(":/resources/filters_3d.frag");
    if (!fshader->log().isEmpty()) qDebug() << fshader->log();
    else qDebug() << "done";

    filters_program = new QOpenGLShaderProgram(this);
    filters_program->addShader(vshader);
    filters_program->addShader(fshader);
    filters_program->bindAttributeLocation("positionIn", 0);
    GLCHK( filters_program->link() );

    GLCHK( filters_program->bind() );
    GLCHK( filters_program->setUniformValue("layerA" , 0) );
    GLCHK( filters_program->setUniformValue("layerB" , 1) );
    GLCHK( filters_program->setUniformValue("layerC" , 2) );
    GLCHK( filters_program->setUniformValue("layerD" , 3) );
    GLCHK( filters_program->setUniformValue("layerE" , 4) );
    GLCHK( filters_program->setUniformValue("layerF" , 5) );
    GLCHK( filters_program->setUniformValue("layerG" , 6) );

    GLCHK( subroutines["mode_normal_filter"]  = glGetSubroutineIndex(filters_program->programId(),GL_FRAGMENT_SHADER,"mode_normal_filter") );
    GLCHK( subroutines["mode_gauss_filter"]   = glGetSubroutineIndex(filters_program->programId(),GL_FRAGMENT_SHADER,"mode_gauss_filter") );
    GLCHK( subroutines["mode_bloom_filter"]   = glGetSubroutineIndex(filters_program->programId(),GL_FRAGMENT_SHADER,"mode_bloom_filter") );
    GLCHK( subroutines["mode_dof_filter"]     = glGetSubroutineIndex(filters_program->programId(),GL_FRAGMENT_SHADER,"mode_dof_filter") );


    GLCHK( filters_program->release());
    delete vshader;
    delete fshader;




    camera.position.setZ( -0 );
    camera.toggleFreeCamera(false);
    newCamera.toggleFreeCamera(false);

    lightDirection.position.setZ(0);
    lightDirection.toggleFreeCamera(false);
    lightDirection.radius = 1;

    mesh        = new Mesh("Core/3D/","Cube.obj");
    skybox_mesh = new Mesh("Core/3D/","sky_cube.obj");
    env_mesh    = new Mesh("Core/3D/","sky_cube_env.obj");
    quad_mesh   = new Mesh("Core/3D/","quad.obj");

    m_prefiltered_env_map = new GLTextureCube(512);

    resizeFBOs();
    emit readyGL();
}