Ejemplo n.º 1
0
void StaticEntity::DrawFirstPass()
{
    GLuint shad;
    glm::vec3 minBBoxPoint;
    glm::vec3 distVec;

    if(visible)
    {
        glPushMatrix();
        glMultMatrixf(&matrix[0][0]);
        glScalef(scale,scale,scale);

        for(unsigned int i=0; i<meshObj->mesh.size(); i++)
        {
            if(meshObj->mesh.at(i))
            {
                if(meshObj->material.at(i))
                {
                    //minBBoxPoint = ClosestMeshBBoxPoint(i);
                    //distVec = minBBoxPoint - Camera::getActiveCamera()->pos;
                    //std::cout<<"dist "<<glm::dot(distVec,distVec)<<std::endl;
                    //shad = SceneHandler::shaderLib.GetShaderFromDistance(meshObj->material.at(i)->type,glm::dot(distVec,distVec));
                    shad=SceneHandler::shaderLib.GetShaderFromType(meshObj->material.at(i)->type);

                    glActiveTexture( GL_TEXTURE0 );
                    glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->diffuseMap);
                    setUniform1i(shad,0,"diffuseMap");

                    glActiveTexture( GL_TEXTURE1 );
                    glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->normalMap);
                    setUniform1i(shad,1,"normalMap");

                    glActiveTexture( GL_TEXTURE2 );
                    glBindTexture(GL_TEXTURE_2D, meshObj->material.at(i)->specularMap);
                    setUniform1i(shad,2,"specularMap");

                    setAttributeTangent(shad, meshObj->mesh.at(i)->tangent, "tangent");

                    setUniform2f(shad,SceneHandler::near,SceneHandler::far,"cameraRange");

                    Camera *cam = Camera::getActiveCamera();
                    setUniform3f(shad,cam->pos.x,cam->pos.y,cam->pos.z,"cameraPos");
                    setUniform3f(shad,cam->dir.x,cam->dir.y,cam->dir.z,"cameraDir");

                    glMaterialfv(GL_FRONT, GL_DIFFUSE, meshObj->material.at(i)->diffuse);
                    glMaterialfv(GL_FRONT, GL_AMBIENT, meshObj->material.at(i)->ambient);
                    glMaterialfv(GL_FRONT, GL_SPECULAR, meshObj->material.at(i)->specular);
                    glMaterialfv(GL_FRONT, GL_SHININESS, meshObj->material.at(i)->shininess);

                    glUseProgram( shad );
                    meshObj->mesh.at(i)->draw();
                    glUseProgram( 0 );
                }
            }
        }
        glPopMatrix();
    }
}
Ejemplo n.º 2
0
void setupLights(GLuint programId, bool directionalLightEnabled, bool pointLightEnabled, bool spotLightEnabled) {
    {
        glm::vec3 direction = glm::normalize(glm::vec3(0.0f, -1.0f, 1.0f));

        setUniform3f(programId, "directionalLight.direction", direction.x, direction.y, direction.z);
        setUniform3f(programId, "directionalLight.color", 1.0f, 1.0f, 1.0f);
        setUniform1f(programId, "directionalLight.ambientIntensity", float(directionalLightEnabled)*0.1f);
        setUniform1f(programId, "directionalLight.diffuseIntensity", float(directionalLightEnabled)*0.1f);
        setUniform1f(programId, "directionalLight.specularIntensity", float(directionalLightEnabled)*1.0f);
    }

    {
        setUniform3f(programId, "pointLight.position", pointLightPos.x, pointLightPos.y, pointLightPos.z);
        setUniform3f(programId, "pointLight.color", 1.0f, 0.0f, 0.0f);
        setUniform1f(programId, "pointLight.ambientIntensity", float(pointLightEnabled) * 0.1f);
        setUniform1f(programId, "pointLight.diffuseIntensity", float(pointLightEnabled) * 1.0f);
        setUniform1f(programId, "pointLight.specularIntensity", float(pointLightEnabled) * 1.0f);
    }

    {
        glm::vec3 direction = glm::normalize(glm::vec3(-0.5f, -1.0f, 0.0f));

        setUniform3f(programId, "spotLight.direction", direction.x, direction.y, direction.z);
        setUniform3f(programId, "spotLight.position", spotLightPos.x, spotLightPos.y, spotLightPos.z);
        setUniform1f(programId, "spotLight.cutoff", glm::cos(glm::radians(15.0f)));
        setUniform3f(programId, "spotLight.color", 0.0f, 0.0f, 1.0f);
        setUniform1f(programId, "spotLight.ambientIntensity", float(spotLightEnabled)*0.1f);
        setUniform1f(programId, "spotLight.diffuseIntensity", float(spotLightEnabled)*20.0f);
        setUniform1f(programId, "spotLight.specularIntensity", float(spotLightEnabled)*1.0f);
    }
}
Ejemplo n.º 3
0
void opengl::ShaderUniforms::setUniform3f(const SCP_string &name, const float x, const float y, const float z)
{
	vec3d temp;

	temp.xyz.x = x;
	temp.xyz.y = y;
	temp.xyz.z = z;

	setUniform3f(name, temp);
}
Ejemplo n.º 4
0
//--------------------------------------------------------------
void ofShader::setUniforms(const ofParameterGroup & parameters) const{
	for(int i=0;i<parameters.size();i++){
		if(parameters[i].type()==typeid(ofParameter<int>).name()){
			setUniform1i(parameters[i].getEscapedName(),parameters[i].cast<int>());
		}else if(parameters[i].type()==typeid(ofParameter<float>).name()){
			setUniform1f(parameters[i].getEscapedName(),parameters[i].cast<float>());
		}else if(parameters[i].type()==typeid(ofParameter<ofVec2f>).name()){
			setUniform2f(parameters[i].getEscapedName(),parameters[i].cast<ofVec2f>());
		}else if(parameters[i].type()==typeid(ofParameter<ofVec3f>).name()){
			setUniform3f(parameters[i].getEscapedName(),parameters[i].cast<ofVec3f>());
		}else if(parameters[i].type()==typeid(ofParameter<ofVec4f>).name()){
			setUniform4f(parameters[i].getEscapedName(),parameters[i].cast<ofVec4f>());
		}else if(parameters[i].type()==typeid(ofParameterGroup).name()){
			setUniforms((ofParameterGroup&)parameters[i]);
		}
	}
}
Ejemplo n.º 5
0
void Shader::updateCommonUniforms(const Camera* camera, const Matrix& modelMatrix) const
{
	//// update fog attributes
	//float	m_fogStart = 20.0f, m_fogLength = 20.0f;
	//vec3	m_fogColor(0.5f);
	//if ((uniformLoc = glGetUniformLocation(m_shaderProg, "u_fogStart")) != -1)
	//	glUniform1f(uniformLoc, m_fogStart);
	//if ((uniformLoc = glGetUniformLocation(m_shaderProg, "u_fogLength")) != -1)
	//	glUniform1f(uniformLoc, m_fogLength);
	//if ((uniformLoc = glGetUniformLocation(m_shaderProg, "u_fogColor")) != -1)
	//	glUniform3f(uniformLoc, m_fogColor.x, m_fogColor.y, m_fogColor.z);

	setUniform3f("u_eyePositionW", camera->getPos());

	setUniform1i("u_elapsedTime", glutGet(GLUT_ELAPSED_TIME));
	setUniform1i("u_techniqueMax", Shader::ms_maxShaderQuality);

	setUniformMatrix("u_M_Mat", modelMatrix.getArray());

	// ModelView
	Matrix	modelViewMatrix;
	Matrix modelViewProjectionMatrix;
	if (m_uniforms.at("u_MV_Mat") != -1)
	{
		modelViewMatrix = camera->getViewMatrix() * modelMatrix;
		setUniformMatrix("u_MV_Mat", modelViewMatrix.getArray());

		modelViewProjectionMatrix = camera->getProjMatrix() * modelViewMatrix;
	}
	else
	{
		modelViewProjectionMatrix = camera->getProjMatrix() * camera->getViewMatrix() * modelMatrix;
	}
	setUniformMatrix("u_MVP_Mat", modelViewProjectionMatrix.getArray());

	// Normal
	Matrix normalMatrix = modelMatrix;
	normalMatrix.setTranslation(vec3(0.0f));

	setUniformMatrix("u_N_Mat", normalMatrix.getArray());
}
Ejemplo n.º 6
0
void UIShader::begin(){
    if (bEnable){
        checkShaderFile();
        
        ofShader::begin();
        
        for (int i = 0; i < uniforms.size(); i++){
            
            if (uniforms[i]->type == UNIFORM_FLOAT){
                
                if (uniforms[i]->name == "time"){
                    setUniform1f(uniforms[i]->name.c_str(), ofGetElapsedTimef());
                } else {
                    setUniform1f(uniforms[i]->name.c_str(), uniforms[i]->value.x );
                }
               
            } else if (uniforms[i]->type == UNIFORM_VEC2){
                
                if (uniforms[i]->name == "mouse"){
                    setUniform2f(uniforms[i]->name.c_str(), ofGetMouseX(), ofGetMouseY() );
                } else if (uniforms[i]->name == "screen"){
                    setUniform2f(uniforms[i]->name.c_str(), ofGetScreenWidth(), ofGetScreenHeight() );
                } else if (uniforms[i]->name == "windows" || uniforms[i]->name == "resolution" ){
                    setUniform2f(uniforms[i]->name.c_str(), ofGetWidth(), ofGetHeight() );
                } else {
                    setUniform2f(uniforms[i]->name.c_str(), uniforms[i]->value.x, uniforms[i]->value.y );
                }
                
            } else if (uniforms[i]->type == UNIFORM_VEC3){
                
                setUniform3f(uniforms[i]->name.c_str(), uniforms[i]->value.x, uniforms[i]->value.y, uniforms[i]->value.z );
                
            }
        }
    }
}
Ejemplo n.º 7
0
//--------------------------------------------------------------
void ofShader::setUniform3f(const string & name, const ofVec3f & v) const{
	setUniform3f(name,v.x,v.y,v.z);
}
Ejemplo n.º 8
0
void PerlinWavesShader::setUniformKs(float in1, float in2, float in3) const{
  setUniform3f("Ks", in1, in2, in3);
}
 void setUniform(const fvec3& value)  { setUniform3f(1, value.ptr()); }
 void setUniform(int count, const fvec3* value)  { setUniform3f(count, value->ptr()); }
Ejemplo n.º 11
0
int ShaderProgram::setUniform(const std::string &uniformName, Vec3 & value)
{
    addUniform( uniformName );
    setUniform3f( uniformName, value);
}
Ejemplo n.º 12
0
void begin()
{
    

    // old-BATB didn't like to be initialized more than once :(
    // hence, ignore re-init for specified parts, and continue with previous state
    static bool empty = true;
    
    // clear exit, making possible to start over again
    //do_exit = false;

        // copied from old::main:
        //MainWindow::winPosX = 100;
        //MainWindow::winPosY = 100;
        //MainWindow::winWidth = 640;
        //MainWindow::winHeight = 480;

        // init glut
        //glutInitWindowPosition(MainWindow::winPosX, MainWindow::winPosY);
        //glutInitWindowSize    (MainWindow::winWidth, MainWindow::winHeight);
        //glutInit              (&argc, argv);
        //glutInitDisplayMode   (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
        //MainWindow::main_window = glutCreateWindow("Beat About the Bush");
        MainWindow::enableDisplayFunc();

        // implemented as GLFW:

        GLFWwindow* win = glfwGetCurrentContext();
        glfwSetKeyCallback( win, MainWindow::glfwKey  );                  //glutKeyboardFunc      (MainWindow::keyDownFn); 
                                                                                          //glutSpecialFunc       (MainWindow::specialDownFn);
                                                                                          ////glutKeyboardUpFunc    (MainWindow::keyUpFn);
                                                                                          ////glutSpecialUpFunc     (MainWindow::specialUpFn);
        glfwSetCursorPosCallback( win, MainWindow::glfwCursorPos );       //glutMouseFunc         (MainWindow::mousefn); 
        glfwSetMouseButtonCallback( win, MainWindow::glfwMouseButton);    //glutMotionFunc        (MainWindow::motionfn);
                                                                                          
        glfwSetWindowSizeCallback( win, MainWindow::glfwWindowSize );     //glutReshapeFunc       (MainWindow::reshapefn);
        glfwSetWindowFocusCallback( win, MainWindow::glfwWindowFocus );   //glutVisibilityFunc    (MainWindow::visibility);
        
        
        
        
    if ( empty )
    {

        // init plib, with no GLUT-binding!
        puInitOLD();

        puSetDefaultStyle        ( PUSTYLE_SMALL_SHADED );
        puSetDefaultColourScheme ( 0.3f, 0.4f, 0.6f, 1.0f);

        // Initialize the "OpenGL Extension Wrangler" library
        //glewInit();
    }

        mainWindow.initLights();

    if ( empty )
    {
        mainWindow.init();
        printVersions();

        // Make sure that OpenGL 2.0 is supported by the driver
        int gl_major, gl_minor;
        getGlVersion(&gl_major, &gl_minor);
        printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);

        if (gl_major < 2)
        {
            printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);
            printf("Support for OpenGL 2.0 is required for this demo...exiting\n");
            //exit(1);
            old::exit(1);
            return;
        }

        // init shaders
        GLchar *dayVSSource, *dayFSSource;
        readShaderSource( old::file("shader/day").c_str(), &dayVSSource, &dayFSSource);
        dayShader = installShaders(dayVSSource, dayFSSource);
        float forestGreen[] = {34.0/255, 139.0/255, 34.0/255};
        //float auburn[] = {113.0/255, 47.0/255, 38.0/255};
        float grey[] = {0.5, 0.5, 0.5};
        //float sepia[] = {112.0/255, 66.0/255, 20.0/255};

        setUniform3f(dayShader, "GrassColor", forestGreen[0], forestGreen[1], forestGreen[2]);
        setUniform3f(dayShader, "RockColor", grey[0], grey[1], grey[2]);
        //setUniform3f(dayShader, "DirtColor", sepia[0], sepia[1], sepia[2]);
        //setUniform4f(dayShader, "LightPos", 0.0, 0.0, 100.0, 1.0);
        setUniform1f(dayShader, "Scale", 1.0);
        setUniform1f(dayShader, "TerrainHigh", 0.1);
        setUniform1f(dayShader, "TerrainLow", 0.1);
        setUniform1i(dayShader, "Trees", 0); // sampler
        setUniform1i(dayShader, "AltGrad", 1); // sampler
        setUniform1i(dayShader, "Noise", 2); // sampler

        GLchar *nightVSSource, *nightFSSource;
        readShaderSource( old::file("shader/night3").c_str(), &nightVSSource, &nightFSSource);
        nightShader = installShaders(nightVSSource, nightFSSource);
        setUniform3f(nightShader, "BrickColor", 1.0, 0.3, 0.2);
        setUniform3f(nightShader, "MortarColor", 0.85, 0.86, 0.84);
        setUniform2f(nightShader, "BrickSize", 0.30, 0.15);
        setUniform2f(nightShader, "BrickPct", 0.90, 0.85);
        setUniform1i(nightShader, "numEnabledLights", 2);

        setUniform3f(nightShader, "GrassColor", forestGreen[0], forestGreen[1], forestGreen[2]);
        setUniform3f(nightShader, "RockColor", grey[0], grey[1], grey[2]);
        setUniform1f(nightShader, "Scale", 1.0);
        setUniform1f(nightShader, "TerrainHigh", 0.1);
        setUniform1f(nightShader, "TerrainLow", 0.1);
        setUniform1i(nightShader, "Trees", 0); // sampler
        setUniform1i(nightShader, "AltGrad", 1); // sampler
        setUniform1i(nightShader, "Noise", 2); // sampler

        GLchar *nightTreeVS, *nightTreeFS;
        readShaderSource( old::file("shader/nightTree").c_str(), &nightTreeVS, &nightTreeFS);
        nightTrees = installShaders(nightTreeVS, nightTreeFS);
        setUniform1i(nightTrees, "Trees", 0); // sampler

        // BUGFIX:
        free( dayVSSource );
        free( dayFSSource );
        free( nightVSSource );
        free( nightFSSource );
        free( nightTreeVS );
        free( nightTreeFS );
    }

        // enter main loop
        //if (dayShader && nightShader)
        //    glutMainLoop();

        //return 0;

    empty = false;

}
Ejemplo n.º 13
0
void ParallaxShader::setUniformKd(float in1, float in2, float in3) const{
  setUniform3f("Kd", in1, in2, in3);
}