Exemplo n.º 1
0
uint32 Scene::fillPointLightsUniformGrid(float unitGridSize, float radius, Float3 offset)
{
	Float3 diff = Float3(_sceneWSAABB_staticObj.Max) - Float3(_sceneWSAABB_staticObj.Min);
	Float3 lightNumAxis = diff / (float)unitGridSize;
	uint32 xnum = (uint32)floorf(Max(lightNumAxis.x, 1.0f));
	uint32 ynum = (uint32)floorf(Max(lightNumAxis.y, 1.0f));
	uint32 znum = (uint32)floorf(Max(lightNumAxis.z, 1.0f));

	Float3 inv_scale = diff / Float3((float)xnum, (float)ynum, (float)znum);

	uint32 lightNum = 0;
	for (uint32 z = 0; z < znum; z++)
	{
		for (uint32 y = 0; y < ynum; y++)
		{
			for (uint32 x = 0; x < xnum; x++)
			{
				PointLight *pl = addPointLight();
				if (pl == NULL) return lightNum; // reached maximum
				pl->cRadius = radius;
				pl->cColor = Float3((float)x / xnum, (float)y / ynum, (float)z / znum);
				pl->cPos = Float3((float)x, (float)y, (float)z) * inv_scale + Float3(_sceneWSAABB_staticObj.Min) + offset;
				lightNum++;
			}
		}
	}

	return lightNum;
}
Exemplo n.º 2
0
	void PointLightComponent::init()
	{
		auto manager = entity->getScene()->getInstance<DRBLightElementManager>();
		_graphicHandle = manager->addPointLight();

		entity->getLink().pushAnObject(_graphicHandle);

		_graphicHandle.getPtr<DRBPointLight>()->setRange(glm::vec4(range.x, range.y, range.z, 1.0f));
		setColor(color);
	}
Exemplo n.º 3
0
void TestScene::load()
{
	//load skybox
	TextureCB* skybox = dynamic_cast<TextureCB*>(DDSLoader::loadDDSTex(	"Assets\\skybox\\sbrightmip.dds",
																		"Assets\\skybox\\sbleftmip.dds",
																		"Assets\\skybox\\sbupmip.dds",
																		"Assets\\skybox\\sbdownmip.dds",
																		"Assets\\skybox\\sbbackmip.dds",
																		"Assets\\skybox\\sbfrontmip.dds"));
	if (skybox != nullptr)
		addCubeMap(skybox);

	//load testmodel "uglypot"
	std::list<Model*> models = OBJLoader::loadOBJ("Assets\\Models\\uglypot.obj");
	Texture2D* wooddiff = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\wooddiff_RGBA32UI.dds"));
	Texture2D* woodspec = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodspec_RGBA32UI.dds"));
	Texture2D* woodgloss = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodgloss_RGBA32UI.dds"));
	Texture2D* woodnormal = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodnormal_RGBA32UI.dds"));
	Texture2D* woodheight = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodheight_RGBA32UI.dds"));
	Texture2D* metaldiff = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metaldiff_RGBA32UI.dds"));
	Texture2D* metalspec = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalspec_RGBA32UI.dds"));
	Texture2D* metalgloss = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalgloss_RGBA32UI.dds"));
	Texture2D* metalnormal = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalnormal_RGBA32UI.dds"));
	Texture2D* metalheight = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalheight_RGBA32UI.dds"));
	//this thing will be forward shaded
	ForwardShader* forward = new ForwardShader();
	forward->load("BaseVertex.vert", "BaseFrag.frag");
	addShader(forward);



	addTexture(wooddiff);
	addTexture(woodspec);
	addTexture(woodgloss);
	addTexture(woodnormal);
	addTexture(woodheight);
	addTexture(metaldiff);
	addTexture(metalspec);
	addTexture(metalgloss);
	addTexture(metalnormal);
	addTexture(metalheight);

	//load wood and metal material
	Material* wood = new Material();
	wood->addTexture(wooddiff);
	wood->addTexture(woodspec);
	wood->addTexture(woodgloss);
	wood->addTexture(woodnormal);
	wood->addTexture(woodheight);
	wood->setShader(forward);
	Material* metal = new Material();
	metal->addTexture(metaldiff);
	metal->addTexture(metalspec);
	metal->addTexture(metalgloss);
	metal->addTexture(metalnormal);
	metal->addTexture(metalheight);
	metal->setShader(forward);

	addMaterial(wood);
	addMaterial(metal);
	std::list<Model*>::iterator moit = models.begin();
	std::vector<Mesh*>::iterator mshit = (*moit)->getMeshes().begin();

	//2 submeshes
	(*mshit++)->setMaterial(wood);
	(*mshit)->setMaterial(metal);

	m_models.splice(end(m_models), models);
	//create an instance of this model and add it to the scene gameobjects
	RenderableGameObject* go = new RenderableGameObject();
	go->setModel(*moit);
	go->getTransform().setTranslate(glm::vec3(0.0f, 0.0f, -2.0f));
	addRenderable(go);

	//create a directional light
	DirectionalLight* dirlight = new DirectionalLight(glm::vec3(1.0f, -1.0f, -1.0f), Transform(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), glm::vec4(1.0f, 1.0f, 0.8f, 1.0f));
	addDirectionalLight(dirlight);

	PointLight* pointlight = new PointLight(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), Transform(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), 1.0f, 0.7f, 1.8f, 7.0f);
	addPointLight(pointlight);
	//create a flycam
	FPSCamera* cam = new FPSCamera(45.0f, 800, 600, 0.1f, 100.0f, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f));
	cam->Fly(true);
	cam->recalcProj();
	m_camera = cam;

	int dummy = 0;
}