Exemplo n.º 1
0
void CProcessIA4::Render(CRenderManager* rm) 
{
  //eje principal
  Mat44f matWorld;
  matWorld.SetIdentity();
  rm->SetTransform(matWorld);
  rm->DrawAxis(5);

  //mueve eje de IA
  RenderMovIA(rm);

// m_SceneEffectManager->ActivateRenderSceneEffects();

  CEffectManager *l_EffectManager=CORE->GetEffectManager();
  l_EffectManager->SetAnimatedModelTechnique(NULL);
  l_EffectManager->SetStaticMeshTechnique(NULL);
  
  //m_SceneEffectManager->PreRender(rm,this);
  //Renderizamos la escena
  RenderScene(rm);
  CORE->GetPhysicsManager()->DebugRender(rm);
  
/*  m_SceneEffectManager->CaptureFrameBuffers(rm);
  m_SceneEffectManager->PostRender(rm);
  m_SceneEffectManager->CaptureFrameBuffersAfterPostRender(rm);
*/

  RenderDebugInfo(); 
}
Exemplo n.º 2
0
void SphereCapLight::getIrradianceSamples(Vec3f point, const Scene* scene, vector<LightRay>& result, float time) {
	// Calculate cap heigth
	float connectionSq = (point - location).length2();
	float connection = sqrt(connectionSq);
	float tangentSq = connectionSq - radius*radius;
	float heightToPoint = tangentSq / connection;
	auto sphereWarping = std::unique_ptr<Warping>(new UniformSphereCapWarping((radius - (connection-heightToPoint)) / radius));

	// Calculate rotation
	Vec3f dir = (point - location).normalized();
	Mat44f rotation = Mat44f(1);
	rotation.rotateTo(Vec3f(0,0,1), dir);

	// Draw new samples
	std::vector<Vec2f> drawnPoints(nSamples);
	randomSampler->generateSamples(nSamplesSqrt, drawnPoints);
	
	Color3f sum = Color3f(0);
	for (unsigned int i = 0; i < nSamples; i++) {
		// Warp and rotate samples
		if (point.x < 0 && point.y > 0)
			int a = 0;
		Vec3f warpedPoint = rotation * sphereWarping->warp(drawnPoints[i]);
		Vec3f spherePoint = warpedPoint * radius;

		Vec3f difference = point - (spherePoint + location);
		float distance = difference.length();

		LightRay lr;
		Ray r;
		lr.direction = difference / distance;
		r.d = lr.direction;
		r.o = spherePoint + location;
		r.tMax = distance - r.tMin;
		r.time = time;

		// Check for intersection
		for (unsigned int k = 0; k < scene->shapes.size(); k++) {
			scene->shapes[k]->intersect(&r);
		}

		//if ray hit something then it does not contribute
		if (r.hit.shape == 0) {
			float pdf = sphereWarping->pdf(drawnPoints[i]);
			//lr.radiance = power * dot(lr.direction, warpedPoint) / (sphereWarping->pdf(drawnPoints[i]) * 4*PI * pow(distance+radius, 2));
			float a = 1/(sphereWarping->pdf(drawnPoints[i]) * 4*PI);
			lr.radiance = radiance * 4 * pow(radius,2) * std::max(0.f,dot(lr.direction, warpedPoint)) / (sphereWarping->pdf(drawnPoints[i]) * 4*PI * pow(distance, 2));
		}
		else {
			lr.radiance = Color3f(0);
		}
		result.push_back(lr);
	}
}
Exemplo n.º 3
0
void CObject3D::SetMat44(Mat44f _vMat44) 
{
  m_vMat44 = _vMat44;
  //m_fPitch = _vMat44.GetPitch();
  //m_fYaw = -_vMat44.GetYaw();
  //m_fRoll = _vMat44.GetRoll();
  m_fPitch =  _vMat44.GetAngleZ();
  m_fYaw   = _vMat44.GetAngleY();
  m_fRoll  =  _vMat44.GetAngleX();
  m_vPosition = _vMat44.GetPos();
}
Exemplo n.º 4
0
void CInstanceMesh::Render(CRenderManager *RM)
{
	if(GetVisible())
	{
		/*OJUCUIDAO*/ //Exportem els vertex dels objectes en un espai real, per tant si els transformem amb pos rot i scale es lia
					  //Exportamos los vertices de los objetos en espacio real, asi que al aplicarles la transformada con pos rot y scale, se lia parda
		//RM->GetContextManager()->SetWorldMatrix(GetTransform());
		Mat44f world;
		world.SetIdentity();
		RM->GetContextManager()->SetWorldMatrix(world);
		m_StaticMesh->Render(RM);
	}
}
Exemplo n.º 5
0
TracePhoton RectangularLight::samplePhoton() {
	std::vector<Vec2f> samples(2);
	randomSampler->generateSamples(2, samples);

	Mat44f rot = Mat44f::I();
	rot.rotateTo(Vec3f(0,0,1), Vec3f(0,-1,0));
	
	Vec3f warpedPoint = Vec3f(size.x*samples[0].x + minPosition.x, minPosition.y, size.y*samples[0].y + minPosition.z);
	Vec3f warpedDirection = rot * cosineWarping->warp(samples[1]);

	TracePhoton photon = TracePhoton(warpedPoint, warpedDirection, power);

	return photon;
}
Exemplo n.º 6
0
void CSpirit::Render(CRenderManager* rm)
{
  CRenderableObject* player = CORE->GetRenderableObjectsManager()->GetInstance("mi_amigo");

  Vect3f a(player->GetPosition().x,player->GetPosition().y,player->GetPosition().z); 

  Mat44f vecOptimo;
  vecOptimo.SetIdentity();
  rm->SetTransform(vecOptimo);

  rm->DrawLine(a,a+ m_vecPlayer,colWHITE);
  rm->DrawLine(a, a +m_vecSpirit,colRED);

}
Exemplo n.º 7
0
void CPhysXProcess::RenderPhysX(CRenderManager* _pRM, CRenderableObject* _pRO, Mat44f _mMatTransf)
{
    //_pRO->GetBoundingBox()->GetMiddlePoint();
   Mat44f t;
   t.SetIdentity();

   t.Translate(Vect3f(0.0f,-_pRO->GetBoundingBox()->GetMiddlePoint().y,0.0f));
   _pRM->SetTransform(_mMatTransf*t);
   //(StaticMesh*)
   

   CInstanceMesh* l_pInstanceMesh = (CInstanceMesh*)_pRO;
   //l_pInstanceMesh->RenderRenderableObject(_pRM);
  // _pRM->RenderBoundingBox(l_pInstanceMesh->GetBoundingBox());
}
Color3f AmbientOcclusionShader::shade(const HitInfo & hit, const Scene* scene, stack<float>& refractionIndices) const {
	// Draw new samples
	std::vector<Vec2f> drawnPoints(nSamples);
	currentSampler->generateSamples(nSamplesSqrt, drawnPoints);
	
	// Calculate rotation
	Mat44f rotation = Mat44f(1);
	rotation.rotateTo(Vec3f(0,0,1), hit.N);

	Color3f sum = Color3f(0);
	for (size_t i = 0; i < nSamples; i++) {
		Vec3f warpedPoint;
		// Include the environment Map weighting
		if (environmentMapWeighted) {
			warpedPoint = scene->background->importanceSample(drawnPoints[i]);
			while (dot(warpedPoint, hit.N) < 0) {
				std::vector<Vec2f> sample(1);
				currentSampler->generateSamples(1, sample);
				warpedPoint = scene->background->importanceSample(sample.front());
			}
		}
		else {
			// Warp and rotate samples
			warpedPoint = rotation * currentWarping->warp(drawnPoints[i]);
		}
		Ray r(hit.P, warpedPoint);
		r.time = hit.time;

		// Check for intersection
		for (unsigned int k = 0; k < scene->shapes.size(); k++) {
			scene->shapes[k]->intersect(&r);
		}

		//if ray hit something then it does not contribute
		if (r.hit.shape == 0) {
			if (cosineWeighted)
				sum += Vec3f(scene->background->getBackground(r.d).toArray());
			else
				sum += Vec3f(scene->background->getBackground(r.d).toArray()) * dot(warpedPoint, hit.N);
		}
	}

	if (!cosineWeighted)
		sum *= 2;

	return sum / static_cast<float>(nSamples);
}
Exemplo n.º 9
0
void CEffect::SetValue(const string& _szParameterName,Mat44f _matValue)
{
  D3DXHANDLE l_pParameter = 0;
  l_pParameter = m_pD3DEffect->GetParameterBySemantic(NULL,_szParameterName.c_str());

  if(l_pParameter)
  {
    m_pD3DEffect->SetMatrix(l_pParameter,&(_matValue.GetD3DXMatrix()));
  }
}
Exemplo n.º 10
0
CBoundingBox CPhysxSkeleton::ComputeBoundingBox()
{
  vector<CPhysxBone*>::iterator l_it  = m_vBones.begin();
  vector<CPhysxBone*>::iterator l_end = m_vBones.end();
  Mat44f m;
  bool m_bFirst = true;
  Vect3f v, min, max;

  for(; l_it != l_end; ++l_it)
  {
    CPhysicActor* l_pPA = (*l_it)->GetPhysxActor();
    if(l_pPA)
    {
      l_pPA->GetMat44(m);
      v = m.GetTranslationVector();
      v += (*l_it)->GetMiddlePoint();
      if(m_bFirst)
      {
        min = max = v;
        m_bFirst = false;
      }
      else
      {
        min.x = (min.x < v.x) ? min.x : v.x;
        min.y = (min.y < v.y) ? min.y : v.y;
        min.z = (min.z < v.z) ? min.z : v.z;

        max.x = (max.x > v.x) ? max.x : v.x;
        max.y = (max.y > v.y) ? max.y : v.y;
        max.z = (max.z > v.z) ? max.z : v.z;
      }
    }
  }

  CBoundingBox l_BB;
  l_BB.Init(min, max);

  return l_BB;
}
Exemplo n.º 11
0
void CPhysXProcess::RenderImpacts(CRenderManager* _pRM)
{
  Mat44f t;  
  for (int i=0;i<(int)g_vCollisions.size();++i)
  {

      t.SetIdentity();
      t.Translate(g_vCollisions[i].m_CollisionPoint);
      _pRM->SetTransform(t);
      if (i==8)
      {
        _pRM->DrawSphere(0.015f,colRED,5);
      }
      else
      {
        _pRM->DrawSphere(0.01f,colYELLOW,5);
      }
      _pRM->DrawLine(v3fZERO,g_vCollisions[i].m_Normal*0.5f,colGREEN);
  }


}
Exemplo n.º 12
0
SrtTransform::SrtTransform(const Mat44f& m)
	:
	translation(m.translation())
{
	scale.x = Vec3f(m.m00, m.m10, m.m20).length();
	scale.y = Vec3f(m.m01, m.m11, m.m21).length();
	scale.z = Vec3f(m.m02, m.m12, m.m22).length();

	// Undo the effect of scaling on the 3x3 matrix
//	rotation = m.mat33();
//	for(size_t i=0; i<3; ++i) for(size_t j=0; j<3; ++j)
//		rotation[i][j] /= scale[j];
}
Exemplo n.º 13
0
void CWayPointManager::DebugRender()
{
	CORE->GetRenderManager()->SetTransform(m44fIDENTITY);

	WayPointGroupMapIt itMap = m_WPGroups.begin();
	WayPointGroupMapIt itMapEnd = m_WPGroups.end();

	for (; itMap != itMapEnd; ++itMap)
	{
		WayPointListIt it = itMap->second.begin();
		WayPointListIt itEnd = itMap->second.end();

		for (; it != itEnd; ++it)
		{
			CWayPoint *wp = (*it);

			Mat44f trans = m44fIDENTITY;
			trans.Translate((*it)->GetPosition());
			CORE->GetRenderManager()->SetTransform(trans);

			CORE->GetRenderManager()->DrawCube(Vect3f(2.0f, 2.0f, 2.0f), colRED);

			WayPointList& bros = wp->GetBrothers();

			WayPointListIt broIt = bros.begin();
			WayPointListIt broItEnd = bros.end();

			trans = m44fIDENTITY;
			CORE->GetRenderManager()->SetTransform(trans);

			for (; broIt != broItEnd; ++broIt)
			{
				CORE->GetRenderManager()->DrawLine(wp->GetPosition(), (*broIt)->GetPosition(), colRED);
			}
		}
	}
}
Exemplo n.º 14
0
void Feature_FBO_MRT::createSecondPass()
{
  // Geometry

  GeometryDataSharedPtr geoDataScreenQuad = createQuad( AttributeID::POSITION | AttributeID::TEXCOORD0, math::Vec3f(-m_aspectRatio, -1.0f, 0.0f), math::Vec3f(m_aspectRatio, -1.0f, 0.0f), math::Vec3f(-m_aspectRatio, 1.0f, 0.0f) );
  GeometrySharedHandle geoScreenQuad = rix::util::generateGeometry(geoDataScreenQuad, m_rix);

  // Shader Code

  const char * vertexShader = ""
    "#version 400\n"
    "layout(location=0) in vec3 Position;\n"
    "layout(location=8) in vec2 TexCoord;\n\n"

    "uniform mat4 world2clip;\n\n"

    "out vec2 vTexCoord;\n"

    "void main(void)\n"
    "{\n"
    "  vTexCoord     = TexCoord;\n"
    "  gl_Position   = world2clip * vec4( Position, 1.0 );\n"
    "}\n";

  ProgramShaderCode vertShader( vertexShader, ShaderType::VERTEX_SHADER );


  const char * fragmentShader = ""
    "#version 400\n"
    "uniform sampler2D FBOTex0;\n"
    "uniform sampler2D FBOTex1;\n"
    "uniform float myWeights[7] = float[](4.0f, 6.0f, 3.5f, 2.0f, 1.5f, 1.0f, 0.0f);\n"
    "uniform float divideBySum = 1.0f/18.0f;\n\n"

    "in vec2 vTexCoord;\n"
    "layout(location = 0, index = 0) out vec4 Color;\n\n"

    "void main(void)\n"
    "{\n"
    "  vec3 curSample = texture(FBOTex0, vTexCoord).xyz;\n"
    "  float objSample = textureLod(FBOTex1, vTexCoord, 0.0f).x;\n"
    "  float glowAccum = 0.0f;\n"
    "  if( objSample > 0.0f )\n"
    "  {\n"
    "    Color = vec4( curSample, 1.0f );\n"
    "    return;\n"
    "  }\n"
    "  \n"
    "  for(int i = 1; i < 8; ++i)\n"
    "  {\n"
    "    glowAccum += myWeights[i - 1]*textureLod(FBOTex1, vTexCoord, float(i)).x;\n"
    "  }\n"
    "  glowAccum *= divideBySum;\n"
    "  Color = vec4( glowAccum, glowAccum, glowAccum, 1.0f ) + vec4( curSample, 0.0f );\n"
    "}\n";

  ProgramShaderCode fragShader( fragmentShader, ShaderType::FRAGMENT_SHADER );

  // Program Parameters

  ProgramParameter vertexProgramParameters[] = {
    ProgramParameter("world2clip", ContainerParameterType::MAT4X4)
  };

  ProgramParameter fragmentProgramParameters[] = {
    ProgramParameter("FBOTex0", ContainerParameterType::SAMPLER),
    ProgramParameter("FBOTex1", ContainerParameterType::SAMPLER)
  };

  // Container Descriptors

  ////Descriptors
  //DP_ASSERT(m_vertConstContainerDescriptor);

  ContainerDescriptorSharedHandle vertContainerDescriptor =
    m_rix->containerDescriptorCreate( ProgramParameterDescriptorCommon( vertexProgramParameters,
    sizeof testfw::core::array(vertexProgramParameters) ) );

  ContainerDescriptorSharedHandle fragContainerDescriptor =
    m_rix->containerDescriptorCreate( ProgramParameterDescriptorCommon( fragmentProgramParameters,
    sizeof testfw::core::array(fragmentProgramParameters) ) );

  ////Per Shader Stage Arrays
  ContainerDescriptorSharedHandle vertContainerDescriptors[] = { vertContainerDescriptor };
  ContainerDescriptorSharedHandle fragContainerDescriptors[] = { fragContainerDescriptor };

  // Container Entries

  //// Global
  m_containerEntryFBOTexture0 = m_rix->containerDescriptorGetEntry( fragContainerDescriptor, "FBOTex0" );
  m_containerEntryFBOTexture1 = m_rix->containerDescriptorGetEntry( fragContainerDescriptor, "FBOTex1" );

  //// Local
  ContainerEntry containerEntryScreenProj = m_rix->containerDescriptorGetEntry( vertContainerDescriptor, "world2clip" );

  // Program Descriptors

  ProgramDescription vertProgramDescription( vertShader, vertContainerDescriptors, sizeof testfw::core::array(vertContainerDescriptors) );
  ProgramDescription fragmentProgramDescription( fragShader, fragContainerDescriptors, sizeof testfw::core::array(fragContainerDescriptors) );

  // Programs

  ProgramSharedHandle vertProgram = m_rix->programCreate( vertProgramDescription );
  ProgramSharedHandle fragProgram = m_rix->programCreate( fragmentProgramDescription );

  // Program Pipeline

  ProgramSharedHandle programs[] = {vertProgram, fragProgram};
  ProgramPipelineSharedHandle programPipeline = m_rix->programPipelineCreate( programs, sizeof testfw::core::array(programs) );

  // Containers

  //// Global
  m_fragContainerScreenPass = m_rix->containerCreate( fragContainerDescriptor );

  //// Local
  ContainerSharedHandle vertContainerScreenPass  = m_rix->containerCreate( vertContainerDescriptor );

  // Data

  //// Global
  m_fbo = static_cast<test::framework::RiXBackend*>(&(*m_backend))->createAuxiliaryRenderTarget(m_width, m_height);

  //// Local

  //Make a native GL texture for our FBO attachment
  TextureSharedHandle textureFBO0;
  TextureSharedHandle textureFBO1;
  {
    TextureDescription textureDescription0( TextureType::_2D, InternalTextureFormat::RGBA32F, dp::PixelFormat::RGBA, dp::DataType::FLOAT_32, m_width, m_height );
    TextureDescription textureDescription1( TextureType::_2D, InternalTextureFormat::R32F, dp::PixelFormat::R, dp::DataType::FLOAT_32, m_width, m_height, 0, 0, true );
    textureFBO0 = m_rix->textureCreate( textureDescription0 );
    textureFBO1 = m_rix->textureCreate( textureDescription1 );


    m_colorBuf = gl::Texture2D::create( GL_RGBA32F, GL_RGBA, GL_UNSIGNED_BYTE, m_width, m_height );
    m_depthBuf = gl::Texture2D::create( GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, m_width, m_height );

    m_colorGlowBuf = gl::Texture2D::create( GL_R32F, GL_RGBA, GL_UNSIGNED_BYTE, 2*m_width, 2*m_height );

    m_fbo.inplaceCast<dp::gl::RenderTargetFBO>()->setAttachment( gl::RenderTargetFBO::AttachmentTarget::COLOR0, m_colorBuf );
    m_fbo.inplaceCast<dp::gl::RenderTargetFBO>()->setAttachment( gl::RenderTargetFBO::AttachmentTarget::COLOR1, m_colorGlowBuf );
    m_fbo.inplaceCast<dp::gl::RenderTargetFBO>()->setAttachment( gl::RenderTargetFBO::AttachmentTarget::DEPTH, m_depthBuf );

    rix::gl::TextureDataGLTexture textureDataGLTexture0( m_colorBuf );
    m_rix->textureSetData( textureFBO0, textureDataGLTexture0 );

    rix::gl::TextureDataGLTexture textureDataGLTexture1( m_colorGlowBuf );
    m_rix->textureSetData( textureFBO1, textureDataGLTexture1 );
  }

  Trafo model2worldScreen;
  model2worldScreen.setTranslation( Vec3f(0.0f, 0.0f, 0.0f) );
  Mat44f model2worldScreenIT = ~model2worldScreen.getInverse();

  Mat44f world2ViewI = m_world2View;
  world2ViewI.invert();

  Mat44f viewOrtho = makeOrtho( -m_aspectRatio, m_aspectRatio, -1.0f, 1.0f, -1.0f, 1.0f);
  Mat44f modelOrtho = cIdentity44f;
  Mat44f modelClip = model2worldScreen.getMatrix() * viewOrtho;

  // Set Container Data

  SamplerStateSharedHandle samplerStateHandle0 = m_rix->samplerStateCreate( SamplerStateDataCommon( SamplerStateFilterMode::NEAREST, SamplerStateFilterMode::NEAREST ) );
  SamplerStateSharedHandle samplerStateHandle1 = m_rix->samplerStateCreate( SamplerStateDataCommon( SamplerStateFilterMode::LINEAR_MIPMAP_NEAREST, SamplerStateFilterMode::NEAREST ) );

  rix::core::SamplerSharedHandle samplerFBO0 = m_rix->samplerCreate();
  m_rix->samplerSetTexture( samplerFBO0, textureFBO0 );
  m_rix->samplerSetSamplerState( samplerFBO0, samplerStateHandle0 );

  rix::core::SamplerSharedHandle samplerFBO1 = m_rix->samplerCreate();
  m_rix->samplerSetTexture( samplerFBO1, textureFBO1 );
  m_rix->samplerSetSamplerState( samplerFBO1, samplerStateHandle1 );

  m_rix->containerSetData( vertContainerScreenPass, containerEntryScreenProj, ContainerDataRaw( 0, modelClip.getPtr(),  16*sizeof(float) ) );
  m_rix->containerSetData( m_fragContainerScreenPass, m_containerEntryFBOTexture0, ContainerDataSampler( samplerFBO0 ) );
  m_rix->containerSetData( m_fragContainerScreenPass, m_containerEntryFBOTexture1, ContainerDataSampler( samplerFBO1 ) );

  // Geometry Instances

  GeometryInstanceSharedHandle geometryInstanceScreen = m_rix->geometryInstanceCreate();
  m_rix->geometryInstanceSetGeometry( geometryInstanceScreen, geoScreenQuad );
  m_rix->geometryInstanceSetProgramPipeline( geometryInstanceScreen, programPipeline );
  m_rix->geometryInstanceUseContainer( geometryInstanceScreen, vertContainerScreenPass );
  m_rix->geometryInstanceUseContainer( geometryInstanceScreen, m_fragContainerScreenPass );

  // Render Group

  m_renderGroupSecondPass = m_rix->renderGroupCreate();
  m_renderData->setRenderGroup(m_renderGroupSecondPass);
  m_rix->renderGroupAddGeometryInstance( m_renderGroupSecondPass, geometryInstanceScreen );
}
Exemplo n.º 15
0
void FpsControllerComponent::update(float dt)
{
	if(!inputComponent || !target)
		return;

	// Make a short-cut first
	Mat44f localTransform = target->localTransform;

	{	// Handling rotation
		Vec2f currentMouseAxis = Vec2f(inputComponent->getAxis("mouse x"), inputComponent->getAxis("mouse y"));

		if(inputComponent->getMouseButton(0))
		{
			Vec2f delta = currentMouseAxis - mLastMouseAxis;
			delta *= -mouseSensitivity;
			mAccumulateMouseDelta += delta;

			Mat44f horizontalRotation = Mat44f::makeAxisRotation(Vec3f(0, 1, 0), mAccumulateMouseDelta.x);
			Mat44f verticalRotation = Mat44f::makeAxisRotation(horizontalRotation.xBiasVector(), mAccumulateMouseDelta.y);

			Vec3f backupTranslation = localTransform.translation();
			localTransform = verticalRotation * horizontalRotation;
			localTransform.translateBy(backupTranslation);
		}
		mLastMouseAxis = currentMouseAxis;
	}

	{	// Handling translation
		Vec3f translation = Vec3f::cZero;

		if(inputComponent->getButton("s"))
			  translation += localTransform.zBiasVector();
		if(inputComponent->getButton("w"))
			  translation -= localTransform.zBiasVector();
		if(inputComponent->getButton("d"))
			  translation += localTransform.xBiasVector();
		if(inputComponent->getButton("a"))
			  translation -= localTransform.xBiasVector();
		if(inputComponent->getButton("PageUp"))
			  translation += localTransform.yBiasVector();
		if(inputComponent->getButton("PageDown"))
			  translation -= localTransform.yBiasVector();

		translation *= dt * translationSpeed;
		localTransform.translateBy(translation);
	}

/*	{	// Handle mouse wheel
		float z = inputComponent->getAxisDelta("mouse z");
		float newFov = fov * (1 - z / 20);
		if(newFov < 140)
			fov = newFov;
	}*/

	target->localTransform = localTransform;
}
Exemplo n.º 16
0
	Mat44f Trafo::getInverse () const { Mat44f ivMat = m_matrix; ivMat.invert (); return ivMat;}