Ejemplo n.º 1
0
  void 
  RLight::pickingRender(const magnet::GL::Camera& cam, 
			const uint32_t offset)
  {
    if (!_visible) return;
    
    using namespace magnet::GL;

    magnet::math::Vector loc = getEyeLocationObjSpace();
    GLfloat pos[3] = {loc[0], loc[1], loc[2]};
    std::vector<GLfloat> position(pos, pos + 3);
    _glposition.init(position);
    
    _context->cleanupAttributeArrays();
    //Set the normals to zero so it is fully illuminated
    _context->setAttribute(Context::instanceScaleAttrIndex, 0.05, 0.05, 0.05, 1);
    
    _context->setAttribute(Context::vertexColorAttrIndex, 
			   (offset % 256) / 255.0, 
			   ((offset / 256) % 256) / 255.0, 
			   (((offset / 256) / 256) % 256) / 255.0, 
			   ((((offset / 256) / 256) / 256) % 256) / 255.0);
    
    _sphereShader.attach();
    _sphereShader["ProjectionMatrix"] = cam.getProjectionMatrix();
    _sphereShader["ViewMatrix"] = cam.getViewMatrix();
    _sphereShader["global_scale"] = GLfloat(1.0);
    _glposition.drawArray(magnet::GL::element_type::POINTS, 3);
    _sphereShader.detach();
  }
Ejemplo n.º 2
0
    inline virtual void invoke(GLint colorTextureUnit, size_t width, size_t height,
			       const magnet::GL::Camera& vp)
    { 
      _filter.attach();
      _filter["u_Texture0"] = colorTextureUnit;
      _filter["u_Texture1"] = 0;
      _filter["u_Texture2"] = 2;
      _filter["nearDist"] = vp.getZNear();
      _filter["farDist"] = vp.getZFar();
      _filter["focalDistance"] = _focalLength;
      _filter["focalRange"] = _focalWidth;
      _filter.invoke();
      _filter.detach();
    }
Ejemplo n.º 3
0
    /*! \brief Returns a projected light position.
     */
    magnet::math::Vector getEyespacePosition(const magnet::GL::Camera& camera) const
    {
      magnet::math::Vector vec = getPosition();
      std::tr1::array<GLfloat, 4> lightPos = {{GLfloat(vec[0]), GLfloat(vec[1]), GLfloat(vec[2]), 1.0f}};
      std::tr1::array<GLfloat, 4> lightPos_eyespace
	= camera.getViewMatrix() * lightPos;
      return magnet::math::Vector(lightPos_eyespace[0], lightPos_eyespace[1], 
				  lightPos_eyespace[2]);
    }
Ejemplo n.º 4
0
  void 
  RLight::glRender(const magnet::GL::Camera& cam, 
		   RenderMode mode)
  {
    if (!_visible) return;
    
    using namespace magnet::GL;

    if (mode & RenderObj::COLOR)
      {
	magnet::math::Vector loc = getEyeLocationObjSpace();
	GLfloat pos[3] = {loc[0], loc[1], loc[2]};
	std::vector<GLfloat> position(pos, pos + 3);
	_glposition.init(position);

	_context->cleanupAttributeArrays();
	//Set the normals to zero so it is fully illuminated
	_context->setAttribute(Context::instanceScaleAttrIndex, 0.05, 0.05, 0.05, 1);
	_context->setAttribute(Context::vertexColorAttrIndex, 1, 1, 1, 1);
	
	if (_context->testExtension("GL_ARB_sample_shading"))
	  {
#ifndef GL_SAMPLE_SHADING
# define GL_SAMPLE_SHADING GL_SAMPLE_SHADING_ARB
#endif
	    glEnable(GL_SAMPLE_SHADING);
	    glMinSampleShadingARB(1.0);
	  }

	_sphereShader.attach();
	_sphereShader["ProjectionMatrix"] = cam.getProjectionMatrix();
	_sphereShader["ViewMatrix"] = cam.getViewMatrix();
	_sphereShader["global_scale"] = GLfloat(1.0);
	_glposition.drawArray(magnet::GL::element_type::POINTS, 3);
	_sphereShader.detach();

	if (_context->testExtension("GL_ARB_sample_shading"))
	  glDisable(GL_SAMPLE_SHADING);
      }
  }
Ejemplo n.º 5
0
  void SSAOWrapper::invoke(GLint colorTextureUnit, 
			   size_t width, size_t height,
			   const magnet::GL::Camera& vp)
  {
    glActiveTextureARB(GL_TEXTURE7);
    glBindTexture(GL_TEXTURE_2D, _randomTexture);

    _filter.attach();

    _filter["radius"] = _radius;
    _filter["totStrength"] = _totStrength;
    _filter["depthDropoff"] = _dropoff;
    _filter["offset"] = GLfloat(std::max(width, height)) / _randomTextureSize;
    _filter["NormalsTex"] = 1;
    _filter["EyePosTex"] = 2;
    _filter["rnm"] = 7;
    _filter["ProjectionMatrix"] = vp.getProjectionMatrix();
    _filter["ViewMatrix"] = vp.getViewMatrix();

    _filter.invoke();
    _filter.detach();
  }
Ejemplo n.º 6
0
  void 
  RTSpheres::sortTick(const magnet::GL::Camera& camera)
  {
    cl_float4 campos = getclVec(camera.getEyeLocation());
    cl_float4 camdir = getclVec(camera.getCameraDirection());
    cl_float4 camup = getclVec(camera.getCameraUp());
  
    //Generate the sort data
    _sortDataKernelFunc(_spherePositions, _sortKeys, _sortData,
			campos, camdir, camup,
			(cl_float)camera.getAspectRatio(),
			(cl_float)camera.getZNear(),
			(cl_float)camera.getFOVY(),
			_N);
  
    if ((_renderDetailLevels.size() > 2) 
	|| (_renderDetailLevels.front()._nSpheres != _N))
      sortFunctor(_sortKeys, _sortData);
  
    recolor();
  }
Ejemplo n.º 7
0
  void 
  Console::interfaceRender(const magnet::GL::Camera& camera)
  {
    //Only draw if the console has something in it or if it's visible
    if (_consoleEntries.empty() || !_visible) return;

    //Disable anything that might affect the rastering 
    glDisable(GL_DEPTH_TEST);

    using namespace magnet::GL;
    Context& context = _axis.getContext();
    //Draw the console in orthograpic projection
    context.cleanupAttributeArrays();

//    if (_showConsole->get_active())
//      {
//	float lineHeight = _consoleFont->FaceSize() / (0.5f * _viewPort->getHeight());
//	float consoleHeight = 1.0f - lineHeight;
//	
//	//Calculate how long since the last redraw
//	int tdelta = glutGet(GLUT_ELAPSED_TIME) - _glutLastTime;
//	_glutLastTime = glutGet(GLUT_ELAPSED_TIME);
//	
//	glColor3f(_consoleTextColor[0], _consoleTextColor[1], 
//		  _consoleTextColor[2]);
//	
//	glRasterPos3f(-1.0, consoleHeight, 0);
//	_consoleLayout->Render(_consoleEntries.front().second.c_str());
//	consoleHeight -= lineHeight;
//	
//	for (std::list<consoleEntry>::iterator iPtr = ++_consoleEntries.begin();
//	     iPtr != _consoleEntries.end();)
//	  {
//	    //Fade the color based on it's time in the queue
//	    glColor4f(_consoleTextColor[0], _consoleTextColor[1], 
//		      _consoleTextColor[2], 1.0f - iPtr->first / 1000.0f);
//	    glRasterPos3f(-1, consoleHeight, 0);
//	    _consoleLayout->Render(iPtr->second.c_str());
//	    iPtr->first += tdelta;
//	    consoleHeight -= lineHeight;
//	    
//	    std::list<consoleEntry>::iterator prev = iPtr++;
//	    //If this element is invisible, erase it
//	    if (prev->first > 1000) _consoleEntries.erase(prev);
//	  }
//      }

    if (_showAxis->get_active())
      {
	/////////////////RENDER THE AXIS//////////////////////////////////////////////

	const GLdouble nearPlane = 0.1,
	  axisScale = 0.09;
    
	//The axis is in a little 100x100 pixel area in the lower left
	std::tr1::array<GLint, 4> oldviewport = context.getViewport();
	context.setViewport(0,0,100,100);
    
	std::tr1::array<GLfloat, 16> oldproj 
	  = context.getAttachedShader()["ProjectionMatrix"].as<std::tr1::array<GLfloat, 16> >();
	std::tr1::array<GLfloat, 16> oldview 
	  = context.getAttachedShader()["ViewMatrix"].as<std::tr1::array<GLfloat, 16> >();
	
	GLMatrix viewMatrix 
	  = GLMatrix::translate(0, 0, -(nearPlane + axisScale))
	  * GLMatrix::rotate(camera.getTilt(), Vector(1, 0, 0))
	  * GLMatrix::rotate(camera.getPan(), Vector(0, 1, 0))
	  * GLMatrix::scale(axisScale, axisScale, axisScale);

	GLMatrix projectionMatrix
	  = GLMatrix::perspective(45, 1, nearPlane, 1000);

	context.getAttachedShader()["ViewMatrix"]  = viewMatrix;
	context.getAttachedShader()["ProjectionMatrix"] = projectionMatrix;

	context.color(0.5f,0.5f,0.5f,0.8f);
	_axis.glRender();

	_cairoOverlay.glRender(projectionMatrix * viewMatrix);

	context.setViewport(oldviewport);
	context.getAttachedShader()["ProjectionMatrix"] = oldproj;
	context.getAttachedShader()["ViewMatrix"] = oldview;
      }    

    //Restore GL state
    glEnable(GL_DEPTH_TEST);
  }
Ejemplo n.º 8
0
  void Console::glRender(magnet::GL::FBO&, const magnet::GL::Camera& camera, RenderMode mode)
  {

    if (_showGrid->get_active())
      {
	using namespace magnet::GL;
	Context& context = _axis.getContext();

	GLMatrix old_model_view
	  = context.getAttachedShader()["ViewMatrix"].as<std::tr1::array<GLfloat, 16> >();

	context.getAttachedShader()["ViewMatrix"]
	  = old_model_view
	  * GLMatrix::translate(camera.getViewPlanePosition())
	  * GLMatrix::rotate(-camera.getPan(), Vector(0, 1, 0))
	  * GLMatrix::rotate(-camera.getTilt(), Vector(1, 0, 0));

	context.color(1,1,1,1);
	//Back face
	context.setAttribute(Context::instanceOriginAttrIndex, 0, 0, -camera.getScreenPlaneWidth(), 0);
	context.setAttribute(Context::instanceScaleAttrIndex,
			     camera.getScreenPlaneWidth(),
			     camera.getScreenPlaneHeight(), 1);
	_grid.glRender();

	//Sides
	context.setAttribute(Context::instanceOriginAttrIndex, 
			     0.5 * camera.getScreenPlaneWidth(), 0, 
			     -0.5 * camera.getScreenPlaneWidth(), 0);
	context.rotation(M_PI / 2, Vector(0, 1, 0));
  	_grid.glRender(); //Right side
	context.setAttribute(Context::instanceOriginAttrIndex, 
			     -0.5 * camera.getScreenPlaneWidth(), 0, 
			     -0.5 * camera.getScreenPlaneWidth(), 0);
  	_grid.glRender(); //Left side

	//Top and bottom
	context.rotation(M_PI / 2, Vector(1, 0, 0));
	context.setAttribute(Context::instanceScaleAttrIndex,
			     camera.getScreenPlaneWidth(),
			     camera.getScreenPlaneWidth(), 1);
	context.setAttribute(Context::instanceOriginAttrIndex, 0,
			     -0.5 * camera.getScreenPlaneHeight(), 
			     -0.5 * camera.getScreenPlaneWidth(), 0);
	_grid.glRender();//bottom
	context.setAttribute(Context::instanceOriginAttrIndex, 0,
			     0.5 * camera.getScreenPlaneHeight(), 
			     -0.5 * camera.getScreenPlaneWidth(), 0);
	_grid.glRender();//top
	context.getAttachedShader()["ViewMatrix"] = old_model_view;
      }
  }