Esempio n. 1
0
	void Rendering::Update(GameObject* obj)
	{
		Camera* camera = obj->GetCamera();
		if( camera != 0 && camera->isEnabled() )
		{
			cameras.insert( camera );
			camera->containingSet = &cameras;
		}

		IRenderer* renderer = obj->GetRenderer();
		if( renderer != 0 )
		{
			renderer->ClearLights();

			if( renderer->renderableTreeLeaf == 0 )
			{
				renderer->renderableTreeLeaf = renderableTree.Insert(renderer);
				renderer->containingTree = &renderableTree;
			}
			else
				renderableTree.Update( renderer->renderableTreeLeaf );
		}
		
		ILight* light = obj->GetLight();
		if( light != 0 )
		{
			light->Update();
					
			if( light->GetLightType() != ILight::DIRECTIONAL )
			{
				IPointLight* pointlight = (IPointLight*)light;
						
				if( pointlight->lightTreeLeaf == 0 )
				{
					pointlight->lightTreeLeaf = lightTree.Insert(pointlight);
					pointlight->containingTree = &lightTree;
				}
				else
					lightTree.Update( pointlight->lightTreeLeaf );
			}
			else
			{
				IDirectionalLight* directionalLight = (IDirectionalLight*)light;

				directionalLightList.push_back( directionalLight );
				directionalLight->containingList = &directionalLightList;
			}
		}
	}
Esempio n. 2
0
	bool OnSetupSample()
	{
		mainLight = mMainScene->createLight( nullptr );
		mainLight->setName( "mainLight" );
		mainLight->translate( CFTO_LOCAL , Vector3(0,0,20) );
		mainLight->setLightColor( ColorKey(1,1,1) );

		sprite = mMainScene->createSprite( nullptr );
		sprite->setRectArea( nullptr , 64 , 64  , "Spell_Fire_FlameShock" , 0 , nullptr , false , 0 , 0 , 0 , CF_FILTER_POINT );
		sprite->setRectPosition( Vector3(0,0,0) );

		sprite->setRenderOption( CFRO_ALPHA_BLENGING , TRUE );
		sprite->setRenderOption( CFRO_SRC_BLEND , CF_BLEND_SRC_ALPHA );
		sprite->setRenderOption( CFRO_DEST_BLEND , CF_BLEND_INV_SRC_ALPHA );
		return true; 
	}
Esempio n. 3
0
	void OnUpdate( long time )
	{
		static float angle = 0.0f;

		SampleBase::OnUpdate( time );
		mainLight->setLocalPosition( 
			Vector3( 50 * Math::Cos( angle ) , 50 * Math::Sin( angle ) , 50 ) );


		angle += 0.001 * time;
	}
Esempio n. 4
0
vec4 VolumeTracer::shade(Ray ray, IAccDataStruct::IntersectionData idata,
                         float attenuation, unsigned short depth, int thread_id) {

  vec4 base_color = StandardTracer::shade(ray, idata, attenuation, depth, thread_id);
  vec4 color = base_color;

  std::vector<IVolume*> volumes = scene->getVolumes();
  float step_size = scene->getSettings()->step_size;

  vec3 step = ray.getDirection() * step_size / length(ray.getDirection());

  // For each volume
  for(unsigned int i = 0; i < volumes.size(); i++) {

    IVolume* volume = volumes[i];

    Interval inter = getInterval(ray, volume, idata.interPoint);
    if(!inter.intersected)
      continue;
    vec3 min = inter.min;
    vec3 max = inter.max;

    float dist = glm::distance(min, max);

    // Add base color:
    float resulting_attenuation = glm::exp(-volume->getTau(min, max));
    color.r *= resulting_attenuation;
    color.g *= resulting_attenuation;
    color.b *= resulting_attenuation;

    int nr_steps = dist / step_size;
    // Beam transmittance
    float trans = 1.0f;
    for(int i = 0; i < nr_steps; ++i) {
      vec3 pos = min + (i+0.5f)*step;

      trans *= glm::exp(-volume->getTau(min + float(i)*step, min + (i+1.0f)*step));

      // Emission
      float Lve = volume->getEmission(pos, -step);
      float resulting_emission = trans * Lve * step_size;;
      color.r += resulting_emission;
      color.g += resulting_emission;
      color.b += resulting_emission;

      // Single-scattering
      float scattering = volume->getScattering();

      std::vector<ILight*>* lights = scene->getLightVector();

      float in_scattered = 0.0f;
      vec3 test = vec3(0.0f);
      vec3 c_test = vec3(1.0f);
      for(unsigned int j = 0; j < lights->size(); j++) {
        ILight* light = lights->at(j);
        vec3 light_pos = light->getPosition();
        vec3 w_in = normalize(pos - light_pos);
        vec3 w_out = normalize(-ray.getDirection());
        float p = volume->getPhase(w_in, w_out);

        float Ld = getIndividualLight(pos, light, thread_id);
        Ld = attenuateLight(Ld, pos, light);
        //float Ld = light->calcLight(datastruct, pos, thread_id);


        in_scattered += p * Ld * step_size;
      }

      float resulting_scattering = trans * scattering * in_scattered;
      color.r += resulting_scattering;
      color.g += resulting_scattering;
      color.b += resulting_scattering;
    }

  }

  return color;
}
Esempio n. 5
0
void ZTransform::Update()
{


	this->ComputeWorldMatrix();
	// --


	// compute world bounding sphere

	if (mSpatialEntity.ptr())
	{
		// bounds computation
		ZBoundingVolume tmpb; // mesh
		//tmpb.SetBoxMinMax(tvector3(-1,-1,-1), tvector3(1,1,1));
		if (mSpatialEntity->GetClassID() == ClassIDZMeshInstance)
		{
			ZMeshInstance *pmi = (ZMeshInstance*)mSpatialEntity->QueryInstance();
			ZMesh *pMesh = pmi->GetMesh();
			tmpb = pMesh->GetBVolume();
			if (pmi->GetPhysicTriMeshInstance())
			{
				pmi->GetPhysicTriMeshInstance()->SetMatrix(mWorldMatrix);
			}
		}
		else if (mSpatialEntity->GetClassID() == ClassIDZTrigger)
		{
			tmpb = ((ZTrigger*)mSpatialEntity->QueryInstance())->GetOriginVolume();
		}
#if 0
		else if (mSpatialEntity->GetClassID() == ClassIDZOccluderBox)
		{
			tmpb.SetBoxMinMax(tvector3(-1,-1,-1), tvector3(1,1,1));
			tmpb.ComputeBSphereFromBoxMinMax();
		}
		else if (mSpatialEntity->GetClassID() == ClassIDZLight)
		{
			ILight *pLight = (ILight*)mSpatialEntity->QueryInstance();
			if ( pLight->GetLightType() == LT_POINTLIGHT)
			{
				tmpb.SetBoxMinMax(tvector3(-0.5f,-0.5f,-0.5f)*pLight->GetRadius(), tvector3(0.5f,0.5f,0.5f)*pLight->GetRadius());
				tmpb.mBSphere = vector4(0,0,0, pLight->GetRadius());
			}
			else
			{
				float valsp1 = pLight->GetLength()*pLight->GetSpotAngle2();
				//float spng = pLight->GetSpotAngle2();
				tmpb.SetBoxMinMax(tvector3(-0.5f,-0.5f,0)*valsp1, tvector3(0.5f*valsp1,0.5f*valsp1,pLight->GetLength()));
				tmpb.ComputeBSphereFromBoxMinMax();
			}
		}
#endif
		tvector3 mBounds[8];
		tmpb.Build8CornersBox(mBounds);
		for (int i=0;i<8;i++)
			mBounds[i].TransformPoint(mWorldMatrix);

		tmpb.SetMinMaxFromCorners((unsigned char*)mBounds, sizeof(tvector3), 8);
		//tmpb.ComputeBSphereFromBoxMinMax();
		tmpb.TransformBSphere(tmpb.GetBSphere(), mWorldMatrix);
		mSpatialEntity->GetBVolume() = tmpb;

		//mSpatialEntity->SetWorldBSphere(tvector4(mWorldMatrix.position, 1));

	}
	// update childs
	if (mSpatialEntity.ptr())
	{
		if (mScene)
		{
			if (!mScene->ClearAsked())
				mScene->AddSEJobChangeMatrix(mSpatialEntity, mWorldMatrix);
		}
		else
		{
			if (!GScene->ClearAsked())
				GScene->AddSEJobChangeMatrixNoSceneInsertion(mSpatialEntity, mWorldMatrix);
		}
	}

	// update childs
	std::list<smartptr<ZTransform> >::iterator iter = mChilds.begin();
	for (; iter != mChilds.end(); ++iter)
	{
		(*iter)->Update();
	}
}