Esempio n. 1
0
void PruebaVentana::init_light()
{
	Light light;
	Material material;

	light.Type = LightType_Spot;
	light.Diffuse = ColorValue(0.5f, 0.5f, 0.5f, 1.0f);
	light.Direction = Vector3(0.0f, 0.0f, -1.0f);
	light.Position = Vector3(-12.0f, 0.0f, 30.0f);
    light.Range = 100.0f;  
    light.Attenuation0 = 0.0f;
    light.Attenuation1 = 0.125f;
    light.Attenuation2 = 0.0f;  
	light.Phi = D3DXToRadian(40.0f);
    light.Theta = D3DXToRadian(20.0f);
    light.Falloff = 1.0f;  

	m_d3ddevice.SetLight(0,light);
	m_d3ddevice.LightEnable(0,true);

	material.Diffuse = ColorValue(1.0f,1.0f,1.0f,1.0f);
	material.Ambient = ColorValue(1.0f,1.0f,1.0f,1.0f);

	m_d3ddevice.material = material;

}
Esempio n. 2
0
void GroundEyeshot::drawTileLine()
{
	int nViewTopX = m_Eyeshot.getViewTopX();
	int nViewTopY = m_Eyeshot.getViewTopY();
	xs::Point ktl(nViewTopX / 64,nViewTopY / 32);

	int col = m_Eyeshot.getViewWidth() / 64 + 2;
	int row = m_Eyeshot.getViewHeight() / 32 + 2;
	int w =  col * 64;
	int h = col * 32;

	IRenderEngine *pRenderEngine = getRenderEngine();
	IRenderSystem *pRenderSystem = pRenderEngine->getRenderSystem();
	ColorValue color = pRenderSystem->getColor();
	pRenderSystem->beginPrimitive(PT_LINES);
	// 绿色
	pRenderSystem->setColor(ColorValue(0,0.48f,0));

	int x = -(nViewTopX - ktl.x * 64);
	int y = -(nViewTopY - ktl.y * 32) - h + 16;
	for(int i = 0; i < col; i++)
	{
		xs::Point ptFrom (x,y);
		xs::Point ptTo (x + w, y + h);
		pRenderSystem->sendVertex(Vector3(ptFrom.x,ptFrom.y,-0.998));
		pRenderSystem->sendVertex(Vector3(ptTo.x,ptTo.y,-0.998));
		y += 32;
	}

	for(int i = 0; i < row; i++)
	{
		xs::Point ptFrom (x,y);
		xs::Point ptTo (x + w, y + h);

		pRenderSystem->sendVertex(Vector3(ptFrom.x,ptFrom.y,-0.998));
		pRenderSystem->sendVertex(Vector3(ptTo.x,ptTo.y,-0.998));
		ptFrom.x = x; ptFrom.y = y;
		ptTo.x = x + w; ptTo.y = y - h;

		pRenderSystem->sendVertex(Vector3(ptFrom.x,ptFrom.y,-0.998));
		pRenderSystem->sendVertex(Vector3(ptTo.x,ptTo.y,-0.998));

		y += 32;
	}

	for(int i = 0; i < col; i++)
	{
		xs::Point ptFrom (x,y);
		xs::Point ptTo (x + w, y - h);

		pRenderSystem->sendVertex(Vector3(ptFrom.x,ptFrom.y,-0.998));
		pRenderSystem->sendVertex(Vector3(ptTo.x,ptTo.y,-0.998));

		y += 32;
	}
	pRenderSystem->endPrimitive();
	pRenderSystem->setColor(color);
}
Esempio n. 3
0
void
Material::Clear()
{
	Ka       = ColorValue();
	Kd       = ColorValue();
	Ks       = ColorValue();
	Ke       = ColorValue();

	power    = 1.0f;
	bump     = 0.0f;
	blend    = MTL_SOLID;
	shadow   = true;

	tex_diffuse    = 0;
	tex_specular   = 0;
	tex_bumpmap    = 0;
	tex_emissive   = 0;
	tex_alternate  = 0;
	tex_detail     = 0;
}
Esempio n. 4
0
bool OpenGLSWFrameBuffer::Wiper_Crossfade::Run(int ticks, OpenGLSWFrameBuffer *fb)
{
	Clock += ticks;

	// Put the initial screen back to the buffer.
	DrawScreen(fb, fb->InitialWipeScreen);

	// Draw the new screen on top of it.
	DrawScreen(fb, fb->FinalWipeScreen, GL_FUNC_ADD, ColorValue(0,0,0,Clock / 32.f), ColorRGBA(255,255,255,0));

	return Clock >= 32;
}
Esempio n. 5
0
SceneGraphWidget::SceneGraphWidget(const std::string& name, Xml::TiXmlElement* xe)
	: GUI::Widget(name, xe)
	, _scene(new Scene())
{
	// Добавить в сцену камеру
	CameraNode::HardPtr pCameraNode = _scene->AddCamera(Camera::HardPtr(new Camera()));
	// ...и сделать эту камеру активной
	pCameraNode->SetActive();
	
	// Добавить в сцену направленный сверху источник света
	Light::HardPtr pLight = DirectionalLight::Create(math::Vector3(math::PI * 0.5f, 0, 0));
	pLight->SetDiffuseColor(ColorValue(1.0f, 1.0f, 1.0f));
	pLight->SetAmbientColor(ColorValue(0.4f, 0.4f, 0.4f));
	_scene->AddLight(pLight);
	
	// Сдвинуть всю сцену вдаль на 500 единиц
	_scene->GetRootNode()->SetRelativeTransform(math::Matrix4::Translation(0, 0, 500));
	
	// Загрузить модель из файла
	ModelNode::HardPtr pModel = _scene->LoadModel("models\\fish_01.xml");
	if (pModel) {
		// Добавить модель в сцену
		_scene->AddSceneNode(pModel, math::Vector3(150, 0, 0), math::Vector3(0, math::PI * 0.5f, 0));
		
		// Добавить пользовательскую анимацию к модели
		Animation::HardPtr pCustomAnim(new Animation("Custom Animation"));
		AnimationChannel::HardPtr pCirclePathAnim(
			new CirclePathAnimationChannel(math::Vector3(0, 0, 0), math::Vector3(0, 1, 0), -0.25f));
		pCustomAnim->AddChannel(pModel, pCirclePathAnim);
		pModel->AddAnimation(pCustomAnim);
		//pCustomAnim->Play();
		
		// Запустить все анимации
		const ModelNode::Animations& animations = pModel->GetAnimations();
		for (ModelNode::Animations::const_iterator it = animations.begin(); it != animations.end(); ++it) {
			(*it).second->Play();
		}
	}
}
TerrainPatch::TerrainPatch(Terrain* terr,const Bitmap* patch, const Rect& r,
const Point&  p1,    const Point& p2)
: ndetail(0), terrain(terr), rect(r), water(0), min_height(1e9), max_height(-1e9)
{
	luminous   = true;   // we will do our own lighting
	own_model  = false;  // manage the model lifetimes in this derived class

	max_detail = Terrain::DetailLevel();
	scale      = fabs(p1.x - p2.x) / (PATCH_SIZE-1);
	mtnscale   = p2.y - p1.y;
	base       = p1.y;
	size       = p2.x - p1.x;

	ZeroMemory(detail_levels, sizeof(detail_levels));

	terrain_width = patch->Width();

	loc   = (p1 + p2) * 0.5;
	loc.y = base;

	radius    = (float) (size * 0.75);
	heights   = new(__FILE__,__LINE__) float[MAX_VERTS];

	float* pHeight = heights;
	int    tscale  = rect.w / (PATCH_SIZE-1);
	int    i, j;

	for (i = 0; i < PATCH_SIZE; i++) {
		int ty = rect.y + i * tscale;

		if (ty < 0)
		ty = 0;

		if (ty > patch->Height()-1)
		ty = patch->Height()-1;

		for (j = 0; j < PATCH_SIZE; j++) {
			int tx = rect.x + (PATCH_SIZE-1 - j) * tscale;

			if (tx < 0)
			tx = 0;

			if (tx > patch->Width()-1)
			tx = patch->Width()-1;

			int   red = patch->GetColor(tx,ty).Red();
			float alt = (float) (red * mtnscale);

			if (alt < min_height)
			min_height = alt;
			if (alt > max_height)
			max_height = alt;

			if (terrain->WaterTexture() && red < 2)
			alt = -5000.0f;

			*pHeight++ = alt;
		}
	}

	Material* mtl = new(__FILE__,__LINE__) Material;
	mtl->Ka = ColorValue(0.5f, 0.5f, 0.5f);
	mtl->Kd = ColorValue(0.3f, 0.6f, 0.2f);
	mtl->Ks = Color::Black;

	mtl->tex_diffuse = terrain->Texture();

	materials.append(mtl);

	List<TerrainLayer>& layers = terrain->GetLayers();
	for (i = 0; i < layers.size(); i++) {
		Bitmap* tex0 = layers.at(i)->GetTileTexture();
		Bitmap* tex1 = 0;
		Bitmap* texd = layers.at(i)->GetDetailTexture();

		if (i < layers.size()-1)
		tex1 = layers.at(i+1)->GetTileTexture();

		if (!texd)
		texd = terrain->DetailTexture(0);

		mtl = new(__FILE__,__LINE__) Material;
		mtl->Ka = ColorValue(0.5f, 0.5f, 0.5f);
		mtl->Kd = ColorValue(0.3f, 0.6f, 0.2f);
		mtl->Ks = Color::Black;

		if ((i & 1) != 0) {
			mtl->tex_diffuse     = tex1;
			mtl->tex_alternate   = tex0;
		}
		else {
			mtl->tex_diffuse     = tex0;
			mtl->tex_alternate   = tex1;
		}

		mtl->tex_detail         = texd;

		materials.append(mtl);
	}

	for (i = 0; i <= max_detail; i++)
	BuildDetailLevel(i);

	model = detail_levels[1];
}
#include "g3dColorValue.h"


const ColorValue ColorValue::ZERO = ColorValue(0.0,0.0,0.0,0.0);
const ColorValue ColorValue::Black = ColorValue(0.0,0.0,0.0);
const ColorValue ColorValue::White = ColorValue(1.0,1.0,1.0);
const ColorValue ColorValue::Red = ColorValue(1.0,0.0,0.0);
const ColorValue ColorValue::Green = ColorValue(0.0,1.0,0.0);
const ColorValue ColorValue::Blue = ColorValue(0.0,0.0,1.0);

ColorValue::~ColorValue(void)
{
}

bool ColorValue::operator==(const ColorValue& rhs) const
{
	return (r == rhs.r &&
		g == rhs.g &&
		b == rhs.b &&
		a == rhs.a);
}
//---------------------------------------------------------------------
bool ColorValue::operator!=(const ColorValue& rhs) const
{
	return !(*this == rhs);
}
HueOutputLightRGB::HueOutputLightRGB(Params &p):
    OutputLightRGB(p)
{
    ioDoc->friendlyNameSet("HueOutputLightRGB");
    ioDoc->descriptionSet(_("RGB Light dimmer using a Philips Hue"));
    ioDoc->linkAdd("Meet Hue", _("http://www.meethue.com"));
    ioDoc->paramAdd("host", _("Hue bridge IP address"), IODoc::TYPE_STRING, true);
    ioDoc->paramAdd("api", _("API key return by Hue bridge when assciation has been made. Use Hue Wizard in calaos_installer to get this value automatically."), IODoc::TYPE_STRING, true);
    ioDoc->paramAdd("id_hue", _("Unique ID describing the Hue Light. This value is returned by the Hue Wizard."), IODoc::TYPE_STRING, true);

    m_host = get_param("host");
    m_api = get_param("api");
    m_idHue = get_param("id_hue");

    m_timer = new EcoreTimer(2.0,[=](){
        std::string url = "http://" + m_host + "/api/" + m_api + "/lights/" + m_idHue;
        UrlDownloader *dl = new UrlDownloader(url, true);
        dl->m_signalCompleteData.connect([&](Eina_Binbuf *downloadedData, int status)
    {
         if (status)
         {
              json_error_t error;
              const unsigned char* c = eina_binbuf_string_get(downloadedData);
              json_t *root = json_loads((const char*)eina_binbuf_string_get(downloadedData), 0, &error);
              if (!root)
              {
                   cErrorDom("hue") << "Json received malformed : " << error.source
                                    << " " << error.text << " (" << Utils::to_string(error.line) << " )";
                   return;
              }
              if (!json_is_object(root))
              {
                   cErrorDom("hue") << "Protocol changed ? date received : " << eina_binbuf_string_get(downloadedData);
                   return;
              }

              json_t *tstate = json_object_get(root, "state");
              if (!tstate || !json_is_object(tstate))
              {
                   cErrorDom("hue") << "Protocol changed ? date received : " << eina_binbuf_string_get(downloadedData);
                   return;
              }

              int sat, bri, hue;
              bool on, reachable;

              sat = json_integer_value(json_object_get(tstate, "sat"));
              bri = json_integer_value(json_object_get(tstate, "bri"));
              hue = json_integer_value(json_object_get(tstate, "hue"));
              on = jansson_bool_get(tstate, "on");
              reachable = jansson_bool_get(tstate, "reachable");

              cDebugDom("hue") << "State: " << on << " Hue : " << hue << " Bri: " << bri << " Hue : " << hue << "Data : " << c;

              if (reachable)
                   stateUpdated(ColorValue::fromHsl((int)(hue * 360.0 / 65535.0),
                                                    (int)(sat * 100.0 / 255.0),
                                                    (int)(bri * 100.0 / 255.0)), on);
              else
                   stateUpdated(ColorValue(0,0,0), reachable);

              json_decref(root);
         }
         else
         {
              stateUpdated(ColorValue(0,0,0), false);
         }
    });

        if (!dl->httpGet())
             delete dl;
         });
}
Esempio n. 9
0
/**
* renderlmpl for edge hight light and blur
* @ param IRenderSystem for set render state or texture.., SceneManger for ger render queue and so on
* @ return null
* @ flow: render target-> render state->setupStream-> setTexture-> setTechnique->begin pass->end pass
* @ author Milong.Wu 
*/
void EdgeblurPostEffect::renderImpl( IRenderSystem* pRenderSys, SceneManager* scene )
{
	if(!postEffect) 
		return;

	SceneManager * scenemgr = SUBSYSTEMX(SceneManager,ISceneManager);
	SceneRender * scenerender = scenemgr->getSceneRender(); 
	StagedForwardSceneRender *Stagescenerender=(StagedForwardSceneRender*)scenerender ;

	const RenderQueue::RenderableList& highItems =(*Stagescenerender).specialRenderQueue.getRenderableList((RenderQueueOrder)StagedForwardSceneRender::RENDER_QUEUE_HIGHLIGHT);
	if (highItems.size() <= 0)
		return ;

	uint blurRTT1 = scene->currentView->getFullRGBRTT1();
	uint blurRTT2 = scene->currentView->getFullRGBRTT2();
	float viewSizeFactor = 0.5f;

	if(blurRTT1 == 0 || blurRTT2 == 0)
		return;
	int numRendered = 0;

	uint oldTarget = pRenderSys->getCurrentRenderTarget();

	pRenderSys->setCurrentRenderTarget(blurRTT1);
    // so the unsee part can't be hightlihght
	pRenderSys->setDepthBufferCheckEnabled(true);
	pRenderSys->setDepthBufferFunction(CMP_LESSEQUAL);
	pRenderSys->setDepthBufferWriteEnabled(false);
	pRenderSys->setCullingMode(CULL_NONE);
	//setup common rendering state
	pRenderSys->clearFrameBuffer(ColorValue(0,0,0,0), 1.0f);

	setupRenderingState(pRenderSys);
	//get highlight queue
	
	int colorID = 0;
	int idCount = 0;
	FillMode oldFillMode = pRenderSys->getFillMode();
	bool highlight = false;

	for(size_t qi = 0; qi <highItems.size()  && colorID <Stagescenerender->highLights.num(); ++qi)
	{
		highlight = true;
		IRenderable *renderable = highItems[qi];
		const Appearance& appear = renderable->getAppearance();
		Appearance::Geometry  geo = appear.geometry;
		geo.indexBuffer =  appear.geometry.indexBuffer;     
		if(appear.material[eMaterial_0].renderOrder < RENDER_QUEUE_BLEND && geo.indexBuffer)
		{
			appear.geometry.setupStream(pRenderSys);
			//edgeColor and rimback_biggerFactor  are uniform values defined in this pass of edgeblur.fx (../date/shader) file
			postEffect->setupAutoParameters(renderable);
			postEffect->setVector4("edgeColor", (Vector4*)(&Stagescenerender->highLights(colorID).color));  
			ColorValue *ed = (ColorValue*)(&Stagescenerender->highLights(colorID).color);
			setupRenderingState(pRenderSys);  

			if(appear.material[eMaterial_0].numTextureUnit)
				appear.material[eMaterial_0].setTextureUnit(pRenderSys,0);
			else
				pRenderSys->setTexture(0, 0); 

			//postEffect->setupAutoParameters(renderable);
			uint iPass;
			//"Rimback" is defined in edgeblur.fx (../date/shader) file
			int macAcount=0;
			const EffectMacro *mac = postEffect->getMacros(macAcount);

			// for the weapon can not be paint, as no maco, so use a special technique
			if(geo.isSkinning())
			{
				postEffect->setTechnique("Rimback");
			}
			else{
				postEffect->setTechnique("RimbackNomaco");
			}
			postEffect->begin(&iPass);
			postEffect->beginPass(0);
			pRenderSys->drawRangeIndexedPrimitive(PT_TRIANGLES, geo.indexBuffer->getType(),geo.indexStart,geo.indexCount,geo.vertexStart,geo.vertexEnd);
			postEffect->endPass();
			postEffect->end();
			appear.geometry.resetStream(pRenderSys);
		}
		idCount++;
		if(idCount >= Stagescenerender->highLights(colorID).numRenderable)
		{
			colorID++;
			idCount = 0;
		}
	}

	if(highlight)
	{
		pRenderSys->setCurrentRenderTarget(blurRTT2);
		pRenderSys->clearFrameBuffer(ColorValue(0,0,0,0), 1.0f);
		// use texture in prerender
		pRenderSys->setTexture(0, (ITexture*)pRenderSys->getRenderTargetTexture(blurRTT1));
		//"Edgeblur" is defined in edgeblur.fx (../date/shader) file
		postEffect->setTechnique("pengzhang");
		// set uniform value
		int l,t, w, h;
		pRenderSys->getViewport(l, t, w, h);
		Vector4 viewport_inv_sizeex(1.0f /w, 1.0f /h, 0, 0);
		postEffect->setVector4("viewport_inv_size", &viewport_inv_sizeex);

		renderQuad(pRenderSys, postEffect);
		// for inflation may add a  border line around, so reset the color 
		pRenderSys->setTextureBorderColor(0,ColorValue(0,0,0,0));
		//set new target
		pRenderSys->setCurrentRenderTarget(blurRTT1);
		//be similar to outline color, for scene blend
		pRenderSys->clearFrameBuffer(ColorValue(0,0,0,0), 1.0f);
		// use texture in prerender
		pRenderSys->setTexture(0, (ITexture*)pRenderSys->getRenderTargetTexture(blurRTT2));


		//"Edgeblur" is defined in edgeblur.fx (../date/shader) file
		postEffect->setTechnique("Edgeblur");

		pRenderSys->getViewport(l, t, w, h);
		Vector4 viewport_inv_size(1.0f / w, 1.0f / h, 0, 0);
		postEffect->setVector4("viewport_inv_size", &viewport_inv_size);

		renderQuad(pRenderSys, postEffect);
	}

	// final pass
	pRenderSys->setCurrentRenderTarget(oldTarget);

	pRenderSys->setTexture(0, (ITexture*)pRenderSys->getRenderTargetTexture(blurRTT1));

	postEffect->setTechnique("FinalBlend");
	
	//pRenderSys->setSceneBlending(quadSrcFactor, quadDestFactor);
	renderQuad(pRenderSys, postEffect);

    //reset
	//pRenderSys->setDepthBufferFunction(CMP_GREATEREQUAL);
}
Esempio n. 10
0
DWORD
Material::GetThumbColor(int i, int j, int size)
{
	Color    result = Color::LightGray;

	double   x = i   - size/2;
	double   y = j   - size/2;
	double   r = 0.9 * size/2;
	double   d = sqrt(x*x + y*y);

	if (d <= r) {
		double z = sqrt(r*r - x*x - y*y);

		Point  loc(x,y,z);
		Point  nrm = loc;       nrm.Normalize();
		Point  light(1,-1,1);   light.Normalize();
		Point  eye(0,0,1);

		ColorValue c = Ka * ColorValue(0.25f, 0.25f, 0.25f);  // ambient light
		ColorValue white(1,1,1);

		double diffuse = nrm*light;
		double v       = 1 - (acos(nrm.y)/PI);
		double u       = asin(nrm.x / sin(acos(nrm.y))) / PI + 0.5;

		ColorValue cd  = Kd;
		ColorValue cs  = Ks;
		ColorValue ce  = Ke;

		if (tex_diffuse) {
			int   tu = (int) (u * tex_diffuse->Width());
			int   tv = (int) (v * tex_diffuse->Height());
			cd = Kd * tex_diffuse->GetColor(tu,tv);
		}

		if (tex_emissive) {
			int   tu = (int) (u * tex_emissive->Width());
			int   tv = (int) (v * tex_emissive->Height());
			ce = Ke * tex_emissive->GetColor(tu,tv);
		}

		if (tex_bumpmap && bump != 0 && nrm.z > 0) {
			// compute derivatives B(u,v)
			int   tu = (int) (u * tex_bumpmap->Width());
			int   tv = (int) (v * tex_bumpmap->Height());

			double   du1 = tex_bumpmap->GetColor(tu,tv).Red() - 
			tex_bumpmap->GetColor(tu-1,tv).Red();
			double   du2 = tex_bumpmap->GetColor(tu+1,tv).Red() - 
			tex_bumpmap->GetColor(tu,tv).Red();

			double   dv1 = tex_bumpmap->GetColor(tu,tv).Red() - 
			tex_bumpmap->GetColor(tu,tv-1).Red();
			double   dv2 = tex_bumpmap->GetColor(tu,tv+1).Red() - 
			tex_bumpmap->GetColor(tu,tv).Red();

			double   du  = (du1 + du2) / 512 * 1e-8;
			double   dv  = (dv1 + dv2) / 512 * 1e-8;

			if (du || dv) {
				Point    Nu  = nrm.cross(Point(0,-1,0));  Nu.Normalize();
				Point    Nv  = nrm.cross(Point(1, 0,0));  Nv.Normalize();

				nrm += (Nu*du*bump);
				nrm += (Nv*dv*bump);
				nrm.Normalize();

				diffuse  = nrm*light;
				v        = 1 - (acos(nrm.y)/PI);
				u        = asin(nrm.x / sin(acos(nrm.y))) / PI + 0.5;
			}
		}

		if (tex_specular) {
			int   tu = (int) (u * tex_specular->Width());
			int   tv = (int) (v * tex_specular->Height());
			cs = Ks * tex_specular->GetColor(tu,tv);
		}

		// anisotropic diffuse lighting
		if (brilliance >= 0) {
			diffuse = pow(diffuse, (double)brilliance);
		}

		// forward lighting
		if (diffuse > 0) {
			// diffuse
			c += cd * (white * diffuse);

			// specular
			if (power > 0) {
				double spec = ((nrm * 2*(nrm*light) - light) * eye);
				if (spec > 0.01) {
					spec = pow(spec, (double)power);
					c += cs * (white * spec);
				}
			}
		}

		// back lighting
		else {
			diffuse *= -0.5;
			c += cd * (white * diffuse);

			// specular
			if (power > 0) {
				light *= -1;

				double spec = ((nrm * 2*(nrm*light) - light) * eye);
				if (spec > 0.01) {
					spec = pow(spec, (double)power);
					c += cs * (white * spec) * 0.7;
				}
			}
		}

		c += ce;

		result = c.ToColor();
	}

	return result.Value();
}