Beispiel #1
0
Texture::Pointer TextureFactory::genNoiseTexture(const vec2i& size, bool norm, const std::string& id)
{
	DataStorage<vec4ub> randata(size.square());
	for (size_t i = 0; i < randata.size(); ++i)
	{
		vec4 rand_f = vec4(randomFloat(-1.0f, 1.0f), randomFloat(-1.0f, 1.0f),
			randomFloat(-1.0f, 1.0f), randomFloat(-1.0f, 1.0f));
		
		if (norm)
			rand_f.xyz().normalize();
		
		randata[i].x = static_cast<unsigned char>(255.0f * clamp(0.5f + 0.5f * rand_f.x, 0.0f, 1.0f));
		randata[i].y = static_cast<unsigned char>(255.0f * clamp(0.5f + 0.5f * rand_f.y, 0.0f, 1.0f));
		randata[i].z = static_cast<unsigned char>(255.0f * clamp(0.5f + 0.5f * rand_f.z, 0.0f, 1.0f));
		randata[i].w = static_cast<unsigned char>(255.0f * clamp(0.5f + 0.5f * rand_f.w, 0.0f, 1.0f));
	}

	TextureDescription::Pointer desc = TextureDescription::Pointer::create();
	desc->data = BinaryDataStorage(4 * size.square());
	desc->target = TextureTarget::Texture_2D;
	desc->internalformat = TextureFormat::RGBA;
	desc->format = TextureFormat::RGBA;
	desc->type = DataType::UnsignedChar;
	desc->size = size;
	desc->mipMapCount = 1;
	desc->layersCount = 1;
    desc->bitsPerPixel = 32;
    
	etCopyMemory(desc->data.data(), randata.data(), randata.dataSize());

	return Texture::Pointer::create(renderContext(), desc, id, false);
}
Beispiel #2
0
Texture TextureFactory::genNoiseTexture(const vec2i& size, bool norm, const std::string& id)
{
	DataStorage<vec4ub> randata(size.square());
	for (size_t i = 0; i < randata.size(); ++i)
	{
		vec4 rand_f = vec4(randomFloat(-1.0f, 1.0f), randomFloat(-1.0f, 1.0f),
			randomFloat(-1.0f, 1.0f), randomFloat(-1.0f, 1.0f));
		
		randata[i] = vec4f_to_4ub(norm ? vec4(rand_f.xyz().normalize(), rand_f.w) : rand_f);
	}

	TextureDescription::Pointer desc(new TextureDescription);
	desc->data = BinaryDataStorage(4 * size.square());
	desc->target = GL_TEXTURE_2D;
	desc->format = GL_RGBA;
	desc->internalformat = GL_RGBA;
	desc->type = GL_UNSIGNED_BYTE;
	desc->size = size;
	desc->mipMapCount = 1;
	desc->layersCount = 1;
    desc->bitsPerPixel = 32;
    
	etCopyMemory(desc->data.data(), randata.data(), randata.dataSize());

	return Texture(new TextureData(renderContext(), desc, id, false));
}
Beispiel #3
0
void Renderer::readFramebufferData(const vec2i& size, TextureFormat format, DataType dataType, BinaryDataStorage& data)
{
	ET_ASSERT((8 * data.size()) >= (size.square() * bitsPerPixelForTextureFormat(format, dataType)));
	
	glReadPixels(0, 0, size.x, size.y, textureFormatValue(format), dataTypeValue(dataType), data.data());
	checkOpenGLError("glReadPixels");
}
Beispiel #4
0
void MainController::applicationDidLoad(et::RenderContext* rc)
{
#if (ET_PLATFORM_WIN)
	application().pushSearchPath("..\\Data");
	application().pushSearchPath("Q:\\SDK\\");
	application().pushSearchPath("Q:\\SDK\\Models");
	application().pushSearchPath("Q:\\SDK\\Textures");
#elif (ET_PLATFORM_MAC)
	application().pushSearchPath("/Volumes/Development/SDK");
	application().pushSearchPath("/Volumes/Development/SDK/Models");
	application().pushSearchPath("/Volumes/Development/SDK/Textures");
#endif
	
	_scene.options.bounces = _productionBounces;
	_scene.options.samples = _productionSamples;
	_scene.options.exposure = 1.0f;
	updateTitle();
	
	rc->renderState().setDepthMask(false);
	rc->renderState().setDepthTest(false);
	
	_scene.load(rc);
	
	_textureData.resize(frameSize.square());
	_textureData.fill(255);
	
	_outputFunction = [this](const vec2i& pixel, const vec4& color) mutable
	{
		size_t index = pixel.x + pixel.y * frameSize.x;
		_textureData[index].x = static_cast<unsigned char>(255.0f * clamp(color.x, 0.0f, 1.0f));
		_textureData[index].y = static_cast<unsigned char>(255.0f * clamp(color.y, 0.0f, 1.0f));
		_textureData[index].z = static_cast<unsigned char>(255.0f * clamp(color.z, 0.0f, 1.0f));
	};
	
	BinaryDataStorage textureData(reinterpret_cast<unsigned char*>(_textureData.binary()), _textureData.dataSize());
	_result = rc->textureFactory().genTexture(TextureTarget::Texture_2D, TextureFormat::RGBA, frameSize,
		TextureFormat::RGBA, DataType::UnsignedChar, textureData, "result-texture");
	
	_cameraAngles.setValue(cameraInitialAngles);
	_cameraAngles.setTargetValue(cameraInitialAngles);
	_cameraAngles.finishInterpolation();
	
	_cameraAngles.updated.connect([this]()
	{
		updateCamera();
		startRender(true);
	});
	
	updateCamera();
	_cameraAngles.run();
	
	_gestures.pointerPressed.connect([this](et::PointerInputInfo)
		{ startRender(true); });

	_gestures.pointerReleased.connect([this](et::PointerInputInfo)
		{ startRender(false); });
	
	_gestures.drag.connect([this](et::vector2<float> d, unsigned long)
	{
		_cameraAngles.addTargetValue(0.1f * vec2(d.x, -d.y));
		_cameraAngles.finishInterpolation();
	});
	
	for (size_t i = 0; i < numThreads; ++i)
		_threads.push_back(sharedObjectFactory().createObject<RaytraceThread>(this));
		
	Invocation([this](){ startRender(false); }).invokeInMainRunLoop();
}
Beispiel #5
0
BinaryDataStorage Renderer::readFramebufferData(const vec2i& size, TextureFormat format, DataType dataType)
{
	BinaryDataStorage result(size.square() * bitsPerPixelForTextureFormat(format, dataType));
	readFramebufferData(size, format, dataType, result);
	return result;
}