Ejemplo n.º 1
0
		GLuint LoadImage(std::string name, const int min, const int mag, const int wrapx, const int wrapy)
		{
			ILuint ImageName;
			if((ImageName=ImagePrivate::DevilLoadImage(name))==0)
				return 0;
			unsigned int  width,height,bpp;
			width = ilGetInteger(IL_IMAGE_WIDTH);
			height = ilGetInteger(IL_IMAGE_HEIGHT);
			bpp = ilGetInteger(IL_IMAGE_BPP);
			unsigned char* data=NULL;
			data = new unsigned char [width*height*bpp];
			memcpy(data,ilGetData(),width*height*bpp);
			ilDeleteImages(1, &ImageName);
			unsigned int ID=0;
			glEnable(GL_TEXTURE_2D);
			glGenTextures(1,&ID);
			glBindTexture(GL_TEXTURE_2D, ID);
			TextureFilter(min,mag);
			TextureWrap(wrapx,wrapy);
			switch(bpp)
			{
			case 3:
				glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,data);
				break;
			case 4:
				glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
				break;
			default:
				glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,data);
				break;
			}
			glDisable(GL_TEXTURE_2D);
			delete data;
			return ID;
		}
Ejemplo n.º 2
0
	void Blur::BlurX(
		const Ptr<ShaderResourceView> & src,
		const Ptr<RenderTargetView> & dst,
		int32_t numSamples,
		float blurRadius,
		const std::vector<float> & weights)
	{
		auto srcTex = src->GetResource()->Cast<Texture>();

		auto & mipSize = srcTex->GetMipSize(src->Cast<TextureShaderResourceView>()->firstMip);
		float2 texelSize = 1.0f / float2((float)mipSize.x(), (float)mipSize.y());

		float offsetStep = 0.0f;
		float offsetStart = 0.0f;
		if (numSamples > 0)
		{
			offsetStep = blurRadius / (float)(numSamples - 1);
			offsetStart = -blurRadius * 0.5f;
		}

		std::vector<float2> offsets;
		for (int32_t i = 0; i < numSamples; ++i)
			offsets.push_back(float2((offsetStart + (float)i * offsetStep)  * texelSize.x(), 0.0f));

		TextureFilter(src, dst, offsets, weights);
	}
Ejemplo n.º 3
0
	PooledRenderResourceReference<Texture> ToneMapping::BloomDownSample(const Ptr<Texture> & inTex)
	{
		auto texDesc = inTex->GetDesc();
		texDesc.mipLevels = 1;
		texDesc.width = std::max<int32_t>(1, texDesc.width / 2);
		texDesc.height = std::max<int32_t>(1, texDesc.height / 2);
		auto resultTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, texDesc });

		float4 inTexSize = inTex->GetTexSize();
		std::vector<float2> offsets;
		offsets.push_back(float2(-1.0f, -1.0f) * float2(inTexSize.z(), inTexSize.w()));
		offsets.push_back(float2( 1.0f, -1.0f) * float2(inTexSize.z(), inTexSize.w()));
		offsets.push_back(float2(-1.0f,  1.0f) * float2(inTexSize.z(), inTexSize.w()));
		offsets.push_back(float2( 1.0f,  1.0f) * float2(inTexSize.z(), inTexSize.w()));

		TextureFilter(
			inTex->GetShaderResourceView(), 
			resultTexRef->Get()->Cast<Texture>()->GetRenderTargetView(0, 0, 1), 
			offsets, 
			std::vector<float>(4, 0.25f));

		return resultTexRef;
	}
Ejemplo n.º 4
0
	void ToneMapping::BloomBlur(const Ptr<Texture> & inTex, float blurRadius)
	{
		TextureDesc texDesc = inTex->GetDesc();
		auto tmpTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, texDesc });
		auto tmpTex = tmpTexRef->Get()->Cast<Texture>();

		{
			int32_t tableSize = (int32_t)blurRadius * 2 + 1;
			auto & gaussTable = GetGaussTable(tableSize);
			int32_t sampleIndex = 0;
			float weightSum = 0.0f;
			std::vector<float2> offsets;
			std::vector<float> weights;
			for (; sampleIndex < tableSize - 1; sampleIndex += 2)
			{
				float offsetStart = (float)sampleIndex - blurRadius;

				float weight0 = gaussTable[sampleIndex];
				float weight1 = gaussTable[sampleIndex + 1];
				weights.push_back(weight0 + weight1);
				offsets.push_back(float2(1.0f, 0.0f) * (offsetStart + weight1 / weights.back()));
				weightSum += weights.back();
			}
			weights.push_back(gaussTable.back());
			offsets.push_back(float2(1.0f, 0.0f) * blurRadius);

			for (auto & w : weights)
				w /= weightSum;
			for (auto & offset : offsets)
				offset /= float2((float)inTex->GetDesc().width, (float)inTex->GetDesc().height);

			TextureFilter(inTex->GetShaderResourceView(), tmpTex->GetRenderTargetView(0, 0, 1), offsets, weights, SamplerTemplate<FILTER_MIN_MAG_MIP_LINEAR>::Get());
		}

		{
			int32_t tableSize = (int32_t)blurRadius * 2 + 1;
			auto & gaussTable = GetGaussTable(tableSize);
			int32_t sampleIndex = 0;
			float weightSum = 0.0f;
			std::vector<float2> offsets;
			std::vector<float> weights;
			for (; sampleIndex < tableSize - 1; sampleIndex += 2)
			{
				float offsetStart = (float)sampleIndex - blurRadius;

				float weight0 = gaussTable[sampleIndex];
				float weight1 = gaussTable[sampleIndex + 1];
				weights.push_back(weight0 + weight1);
				offsets.push_back(float2(0.0f, 1.0f) * (offsetStart + weight1 / weights.back()));
				weightSum += weights.back();
			}
			weights.push_back(gaussTable.back());
			offsets.push_back(float2(0.0f, 1.0f) * blurRadius);

			for (auto & w : weights)
				w /= weightSum;
			for (auto & offset : offsets)
				offset /= float2((float)inTex->GetDesc().width, (float)inTex->GetDesc().height);

			TextureFilter(tmpTex->GetShaderResourceView(), inTex->GetRenderTargetView(0, 0, 1), offsets, weights, SamplerTemplate<FILTER_MIN_MAG_MIP_LINEAR>::Get());
		}

	}