Exemple #1
0
void initScene() {
  mNormalMapShader = new Shader("shader/universalShader.vert", "shader/universalShader.frag");
  
  Material *mat;
  
  objLoader.loadObjFile("./meshes/sphere.obj", "sun", 2.0f);
  mat = new Material();
  mat->setShaderProgram(mNormalMapShader);
  mat->setEmissiveTexture("textures/sun.jpg");
  objLoader.getMeshObj("sun")->setMaterial(mat);
  
  objLoader.loadObjFile("./meshes/sphere.obj", "mars", 0.5f);
  mat = new Material();
  mat->setShaderProgram(mNormalMapShader);
  mat->setDiffuseTexture("textures/mars.png");
  mat->setNormalTexture("textures/mars_normal.png");
  mat->setAmbientColor(0.15, 0.15, 0.15);
  objLoader.getMeshObj("mars")->setMaterial(mat);
  
  objLoader.loadObjFile("./meshes/sphere.obj", "moon", 0.2f);
  mat = new Material();
  mat->setShaderProgram(mNormalMapShader);
  mat->setDiffuseTexture("textures/moon.png");
  mat->setNormalTexture("textures/moon_normal.png");
  mat->setAmbientColor(0.15, 0.15, 0.15);
  objLoader.getMeshObj("moon")->setMaterial(mat);
  
  
  // TODO: init you additional shaders here (you might want to use simple.vert as vertex shader) //
}
Exemple #2
0
void renderScene() {
  // light source //
  glEnable(GL_LIGHT0);
  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
  
  // TODO: render your scene using the material shaders to your FBO into the first color attachment //
  //       only render the sun a depth values before rendering the other planets fully colored      //
  //       use mPath and mTimer to compute the planet's positions                                   //

  // Sun at 0,0,0
  glLoadIdentity();
  objLoader.getMeshObj("sun")->render();

  // Get current time from timer
  double time = mTimer.getTime();

  // Get the way along the path for current time
  ControlPoint p1 = mPath.getPositionForTime(time);
  float mars_radius = 10.0;
  glTranslatef(p1.pos[0] *mars_radius, p1.pos[1] *mars_radius, p1.pos[2] *mars_radius);
  objLoader.getMeshObj("mars")->render();

  ControlPoint p2 = mPath.getPositionForTime(time *1.4f);
  float moon_radius = 3.0;
  glTranslatef(p2.pos[0] *moon_radius, p2.pos[1] *moon_radius, p2.pos[2] *moon_radius);
  objLoader.getMeshObj("moon")->render();
  
  // TODO: keep the current depth map and render the visible parts of sun to the second color attachment //
  
  // TODO: render blooming effect using a technique like in ex09 //
  
  // TODO: composite the final image by adding the first rendering and the bloom-filtered rendering //
  
  glDisable(GL_LIGHT0);
}
Exemple #3
0
// Done TODO: render the shadow volume here using the chosen shadow volume rendering technique //
void renderShadow() {
    glUniform1i(uniformLocations["drawShadows"], 1);

    // #INFO# init shadow volume if light source position has changed //
    if (lightSourcePosUpdate) {
        objLoader.getMeshObj("sceneObject")->initShadowVolume(light.position);
        lightSourcePosUpdate = false;
    }

    //Done TODO: disable drawing to screen (we just want to change the stencil buffer) //
    glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
    glDepthMask(GL_FALSE);
    //Done TODO: enable stencil test and face culling //
    // - we need face culling to separately render front facing and back facing triangles //
    glEnable(GL_STENCIL_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    //Done TODO: implement the shadow volume rendering //
    glStencilFunc(GL_ALWAYS, 1 , 0xFFFFFFFF);
    glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);

    glm_ModelViewMatrix.push(glm_ModelViewMatrix.top());
    glm_ModelViewMatrix.top() *= glm::scale(glm::vec3(10));
    glUniformMatrix4fv(uniformLocations["modelview"], 1, false, glm::value_ptr(glm_ModelViewMatrix.top()));
    glUniform1i(uniformLocations["drawShadows"], 1);
    

    MeshObj *mesh = objLoader.getMeshObj("sceneObject");
    mesh->renderShadowVolume();

    glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
    glCullFace(GL_FRONT);

    mesh->renderShadowVolume();

    // restore scene graph to previous state //
    glm_ModelViewMatrix.pop();
    //Done TODO: final render pass -> render screen quad with current stencil buffer //
    // - disable face culling and re-enable writing to color and depth buffer    //
    glDisable(GL_CULL_FACE);
    glColorMask(GL_TRUE,GL_TRUE, GL_TRUE,GL_TRUE);
    // - set stencil operation to only execute, when stencil buffer is not equal to zero //
    glStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFF);
    // OPTION: enable blend function to prevent shadows from being pitch black //
    // - uses alpha of color defined when rendering the screen filling quad    //
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    renderScreenFillingQuad();
    glDisable( GL_BLEND );


    //Done TODO: disable stencil testing for further rendering and restore original rendering state //
    glDisable(GL_STENCIL_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glDepthMask(GL_TRUE);
}
Exemple #4
0
void renderScene() {
  glm_ModelViewMatrix.push(glm_ModelViewMatrix.top());
  glm_ModelViewMatrix.top() *= glm::scale(glm::vec3(20.0));

  glUniformMatrix4fv(uniformLocations["modelview"], 1, false, glm::value_ptr(glm_ModelViewMatrix.top()));

  // TODO: upload the properties of the currently chosen light source here //
  // - ambient, diffuse and specular color
  // - position
  // - use glm::value_ptr() to get a proper reference when uploading the values as a data vector //
  glUniform3fv(uniformLocations["lightSource.ambient_color"], 1, glm::value_ptr(lights[lightIndex].ambient_color));
  glUniform3fv(uniformLocations["lightSource.diffuse_color"], 1, glm::value_ptr(lights[lightIndex].diffuse_color));
  glUniform3fv(uniformLocations["lightSource.specular_color"], 1, glm::value_ptr(lights[lightIndex].specular_color));
  glUniform3fv(uniformLocations["lightSource.position"], 1, glm::value_ptr(lights[lightIndex].position));

  // TODO: upload the chosen material properties here //
  // - upload ambient, diffuse and specular color as 3d-vector
  // - upload shininess exponent as simple float value

  glUniform3fv(uniformLocations["material.ambient_color"], 1, glm::value_ptr(materials[materialIndex].ambient_color));
  glUniform3fv(uniformLocations["material.diffuse_color"], 1, glm::value_ptr(materials[materialIndex].diffuse_color));
  glUniform3fv(uniformLocations["material.specular_color"], 1, glm::value_ptr(materials[materialIndex].specular_color));
  glUniform1f(uniformLocations["material.specular_shininess"], materials[materialIndex].specular_shininess);

  // render the actual object //
  objLoader.getMeshObj("bunny")->render();

  // restore scene graph to previous state //
  glm_ModelViewMatrix.pop();
}
Exemple #5
0
void renderScene() {
  // light source //
  glEnable(GL_LIGHT0);
  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
  
  // TODO: render your scene using the material shaders to your FBO into the first color attachment //
  //       only render the sun a depth values before rendering the other planets fully colored      //
  //       use mPath and mTimer to compute the planet's positions                                   //
  // Matrix zurück setzen, dann evtl Rotation und Sonne
//  glutSolidSphere(1,10,10);
//  glutWireSphere(1,10,10);
  objLoader.getMeshObj("sun")->render();
  // Rotation löschen, dafür Translation und Rotation um Sonne für Mars dann noch Mars rotieren
  double time = mTimer.getTime();
  std::cout << "Mars" << std::endl;
  ControlPoint cp = mPath.getPositionForTime(time/2);
  const float radius_mars = 2;
  glTranslatef(cp.pos[0] * radius_mars, cp.pos[1] * radius_mars, cp.pos[2] * radius_mars);
  objLoader.getMeshObj("mars")->render();
  // Letzte Rotation löschen und Translation und Rotation für Mond dann noch Mond rotieren
  std::cout << "Marsmond" << std::endl;
  cp = mPath.getPositionForTime(1.4*time/2);
  const float radius_moon = 0.3;
  glTranslatef(cp.pos[0] * radius_moon, cp.pos[1] * radius_moon, cp.pos[2] * radius_moon);
  objLoader.getMeshObj("moon")->render();

#if 0
#endif
  
  // TODO: keep the current depth map and render the visible parts of sun to the second color attachment //
  
  // TODO: render blooming effect using a technique like in ex09 //
  
  // TODO: composite the final image by adding the first rendering and the bloom-filtered rendering //
  
  glDisable(GL_LIGHT0);
}
Exemple #6
0
// #INFO#: this renders the scene object usign material and lighting //
void renderScene() {
    glUniform1i(uniformLocations["drawShadows"], 0);
    glm_ModelViewMatrix.push(glm_ModelViewMatrix.top());

    glm_ModelViewMatrix.top() *= glm::scale(glm::vec3(10));

    glUniformMatrix4fv(uniformLocations["modelview"], 1, false, glm::value_ptr(glm_ModelViewMatrix.top()));
    glUniform1i(uniformLocations["drawShadows"], 0);

    // setup light and material in shader //
    setupLightAndMaterial();

    // render the actual object //
    MeshObj *mesh = objLoader.getMeshObj("sceneObject");
    mesh->render();

    // restore scene graph to previous state //
    glm_ModelViewMatrix.pop();
}
Exemple #7
0
void renderScene() {
	glm_ModelViewMatrix.push(glm_ModelViewMatrix.top());

	glUniformMatrix4fv(uniformLocations["modelview"], 1, false, glm::value_ptr(glm_ModelViewMatrix.top()));

	// upload the properties of the currently active light sources here //
	int shaderLightIdx = 0;
	for (unsigned int i = 0; i < lightCount; ++i) {
		if (lights[i].enabled) {
			std::stringstream sstr("");
			sstr << "light_" << shaderLightIdx;
			UniformLocation_Light &light = uniformLocations_Lights[sstr.str()];
			glUniform3fv(light.position, 1, glm::value_ptr(lights[i].position));
			glUniform3fv(light.ambient_color, 1, glm::value_ptr(lights[i].ambient_color));
			glUniform3fv(light.diffuse_color, 1, glm::value_ptr(lights[i].diffuse_color));
			glUniform3fv(light.specular_color, 1, glm::value_ptr(lights[i].specular_color));
			++shaderLightIdx;
		}
	}
	glUniform1i(uniformLocations["usedLightCount"], shaderLightIdx);

	// upload the chosen material properties here //
	glUniform3fv(uniformLocations["material.ambient"], 1, glm::value_ptr(materials[materialIndex].ambient_color));
	glUniform3fv(uniformLocations["material.diffuse"], 1, glm::value_ptr(materials[materialIndex].diffuse_color));
	glUniform3fv(uniformLocations["material.specular"], 1, glm::value_ptr(materials[materialIndex].specular_color));
	glUniform1f(uniformLocations["material.shininess"], materials[materialIndex].specular_shininess);

	// upload texture to first texture unit //

	// bind the texture after activating the first texture unit
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, texture);

	// assign the currently active texture unit to the texture uniform of your shader
	glUniform1i(uniformLocations["tex"], 0);

	// render the actual object //
	objLoader.getMeshObj("sceneObject")->render();

	// restore scene graph to previous state //
	glm_ModelViewMatrix.pop();
}
Exemple #8
0
void updateGL() {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // projection matrix stays the same //
  glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "projection"), 1, false, glm::value_ptr(glm_ProjectionMatrix.top()));

  // init scene graph by cloning the top entry, which can now be manipulated //
  glm_ModelViewMatrix.push(glm_ModelViewMatrix.top());

  // TODO: create a rotating grid of rotating objects (5 x 5 grid)
  //  - alterately render a bunny and the loaded obj-File in this grid
  //    e.g.: B S B S B   (B: bunny.h, S: scene.obj)
  //          S B S B S
  //          B S B S B
  //          S B S B S
  //          B S B S B
  //  - rotate the grid clockwise about 'rotAngle'
  //  - rotate the bunnies counterclockwise about 'rotAngle'
  //  - use glm_ModelViewMatrix.push(...) and glm_ModelViewMatrix.pop()
  //  - apply new transformations by using: glm_ModelViewMatrix.top() *= glm::some_transformation(...);
  //  - right before rendering an object, upload the current state of the modelView matrix stack:
  //    glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "modelview"), 1, false, glm::value_ptr(glm_ModelViewMatrix.top()));

  // Variable sorgt für abwechselndes Zeichnen des Hasen und der Ringe
  bool bunny = true;

  // Wir wollen das gesamte Grid im Uhrzeigersinn um die z-Achse drehen. Diese
  // Transformation wird als "letztes" ausgeführt.
  glm_ModelViewMatrix.top() *= glm::rotate(-rotAngle, 0.f, 1.0f, 0.f);

  // Bestimmt den Abstand zwischen den Objekten
  float factor = 0.25f;

  // Zwei Schleifen, die ein 5x5-Grid erzeugen
  for(float x=-20.0f; x<30.0f; x+=1.0f) {
      for(float z=-20.0f; z<30.0f; z+=1.0f) {

          // Ab jetzt bekommt jedes Objekt eine eigene Matrix
          glm_ModelViewMatrix.push(glm_ModelViewMatrix.top());

          // Verschieben gemäß Position im Grid
          glm_ModelViewMatrix.top() *= glm::translate(factor*x, 0.0f, factor * z);

          if (bunny) {
              // Die Bunnys sollen sich GEGEN den Uhrzeigersinn um die y-Achse drehen
              glm_ModelViewMatrix.top() *= glm::rotate(rotAngle, 0.f, 1.0f, 0.f);
              // Die aktuell oberste Matrix möchten wir zur Transformation nutzen
              glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "modelview"), 1, false, glm::value_ptr(glm_ModelViewMatrix.top()));
              // Bunny zeichnen
              renderScene();
          } else {
              // Soll das andere Objekt gezeichnet werden, skaliere um Faktor 20 runter ...
              glm_ModelViewMatrix.top() *= glm::scale(1.0f/20.0f,1.0f/20.0f,1.0f/20.0f);
              glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "modelview"), 1, false, glm::value_ptr(glm_ModelViewMatrix.top()));
              // ... und zeichne das "scene"-Objekt
              objLoader.getMeshObj("scene")->render();
          }

          // Hase und Ringe wechseln sich ab
          bunny = !bunny;

          // Geh wieder einen Schritt im Szenegraph nach oben
          glm_ModelViewMatrix.pop();
      }
  }

  // restore scene graph to previous state //
  glm_ModelViewMatrix.pop();

  // increment rotation angle //
  rotAngle += 1.0f;
  if (rotAngle > 360.0f) rotAngle -= 360.0f;

  // swap renderbuffers for smooth rendering //

  glutSwapBuffers();
}