Ejemplo n.º 1
0
void DiffuseGain::applyPtmRGB(const PyramidCoeff& redCoeff, const PyramidCoeff& greenCoeff, const PyramidCoeff& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	int offsetBuf = 0;
	const PTMCoefficient* redPtr = redCoeff.getLevel(info.level);
	const PTMCoefficient* greenPtr = greenCoeff.getLevel(info.level);
	const PTMCoefficient* bluePtr = blueCoeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	// Creates the output texture.
	
    #pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
        int offsetBuf = ((y-info.offy)*info.width)<<2;
		int offset = y * mipMapSize[info.level].width() + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			buffer[offsetBuf + 0] = tobyte(applyModel(&(redPtr[offset][0]), normalsPtr[offset].X(), normalsPtr[offset].Y(), info.light.X(), info.light.Y()));
			buffer[offsetBuf + 1] = tobyte(applyModel(&(greenPtr[offset][0]), normalsPtr[offset].X(), normalsPtr[offset].Y(), info.light.X(), info.light.Y()));
			buffer[offsetBuf + 2] = tobyte(applyModel(&(bluePtr[offset][0]), normalsPtr[offset].X(), normalsPtr[offset].Y(), info.light.X(), info.light.Y()));
            buffer[offsetBuf + 3] = 255;
			offset++;
			offsetBuf += 4;
		}
	}
	//qDebug() << "gain = " << DiffuseGain::gain;
}
Ejemplo n.º 2
0
void DiffuseGain::applyPtmLRGB(const PyramidCoeff& coeff, const PyramidRGB& rgb, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	int offsetBuf = 0;
	const unsigned char* rgbPtr = rgb.getLevel(info.level);
	const PTMCoefficient* coeffPtr = coeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	// Creates the output texture.

    #pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
        int offsetBuf = ((y-info.offy)*info.width)<<2;
		int offset = y * mipMapSize[info.level].width() + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			//int offset = y * mipMapSize[info.level].width() + x;
            float lum = applyModel(&(coeffPtr[offset][0]), normalsPtr[offset].X(), normalsPtr[offset].Y(), info.light.X(), info.light.Y()) / 256.0f;
			int offset3 = offset*3;
			for (int i = 0; i < 3; i++)
				buffer[offsetBuf + i] = tobyte(rgbPtr[offset3 + i] * lum);
            buffer[offsetBuf + 3] = 255;
			offsetBuf += 4;
			offset++;
		}
	}
	//qDebug() << "gain = " << DiffuseGain::gain;
}
Ejemplo n.º 3
0
void SpecularEnhancement::applyPtmRGB(const PyramidCoeff& redCoeff, const PyramidCoeff& greenCoeff, const PyramidCoeff& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	// Creates the output texture.
	const PTMCoefficient* redPtr = redCoeff.getLevel(info.level);
	const PTMCoefficient* greenPtr = greenCoeff.getLevel(info.level);
	const PTMCoefficient* bluePtr = blueCoeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	LightMemoized lVec(info.light.X(), info.light.Y());
	
	#pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
		int offsetBuf = (y-info.offy)*info.width<<2;
		int offset = y * mipMapSize[info.level].width() + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			vcg::Point3f h(0, 0, 1);
			h += info.light;
			h /= 2;
			h.Normalize();
            float nDotH = h * normalsPtr[offset];
			if (nDotH < 0) 
				nDotH = 0.0;
			else if (nDotH > 1)
				nDotH = 1.0;
			nDotH = pow(nDotH, exp);
			float r = redPtr[offset].evalPoly(lVec);
			float g = greenPtr[offset].evalPoly(lVec);
            float b = bluePtr[offset].evalPoly(lVec);
			float temp = (r + g + b)/3;
            float lum =  temp * ks * 2 * nDotH;
			buffer[offsetBuf + 0] = tobyte( r * kd + lum);
			buffer[offsetBuf + 1] = tobyte( g * kd + lum );
			buffer[offsetBuf + 2] = tobyte( b * kd + lum );
			buffer[offsetBuf + 3] = 255;
			offsetBuf += 4;
			offset++;
		}
	}
}
Ejemplo n.º 4
0
void SpecularEnhancement::applyPtmLRGB(const PyramidCoeff& coeff, const PyramidRGB& rgb, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	// Creates the output texture.
	//int offsetBuf = 0;
	const PTMCoefficient* coeffPtr = coeff.getLevel(info.level);
	const unsigned char* rgbPtr = rgb.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	LightMemoized lVec(info.light.X(), info.light.Y());
	
	#pragma omp parallel for schedule(static,CHUNK) 
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
		int offsetBuf = (y-info.offy)*info.width*4;
		int offset = y * mipMapSize[info.level].width() + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			float lum = coeffPtr[offset].evalPoly(lVec) / 255.0f;
            vcg::Point3f h(0, 0, 1);
			h += info.light;
			h /= 2;
			h.Normalize();
			float nDotH = h * normalsPtr[offset];
			if (nDotH < 0) 
				nDotH = 0.0;
			else if (nDotH > 1)
				nDotH = 1.0;
			nDotH = pow(nDotH, exp);
			nDotH *= ks*255;
			int offset3 = offset*3;
			for (int i = 0; i < 3; i++)
				buffer[offsetBuf + i]  = tobyte((rgbPtr[offset3 + i]*kd + nDotH)*lum);
			buffer[offsetBuf + 3] = 255;
			offsetBuf += 4;
			offset++;
		}
	}

}
Ejemplo n.º 5
0
void UnsharpMasking::applyPtmRGB(const PyramidCoeff& redCoeff, const PyramidCoeff& greenCoeff, const PyramidCoeff& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	int offsetBuf = 0;
	const PTMCoefficient* redPtr = redCoeff.getLevel(info.level);
	const PTMCoefficient* greenPtr = greenCoeff.getLevel(info.level);
	const PTMCoefficient* bluePtr = blueCoeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
    float* lumMap = new float[info.width*info.height];
	int width = mipMapSize[info.level].width();
	if (type == 0) //classic unsharp masking
	{
        float* uvMap = new float[info.width*info.height*2];
		LightMemoized lVec(info.light.X(), info.light.Y());
        
		#pragma omp parallel for schedule(static,CHUNK)
		for (int y = info.offy; y < info.offy + info.height; y++)
		{
            int offsetBuf = (y-info.offy)*info.width<<2;
			int offset = y * width + info.offx;
			int offset2 = (y - info.offy)*info.width;
			for (int x = info.offx; x < info.offx + info.width; x++)
			{
				float r = redPtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(redPtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
                float g = greenPtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(greenPtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
                float b = bluePtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(bluePtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
				getYUV(r, g, b, lumMap[offset2], uvMap[offset2*2], uvMap[offset2*2 + 1]);
				offset++;
				offset2++;
			}
		}
		enhancedLuminance(lumMap, info.width, info.height, info.mode);
		bool flag = (info.mode == LUM_UNSHARP_MODE || info.mode == SMOOTH_MODE || info.mode == CONTRAST_MODE || info.mode == ENHANCED_MODE);
		if (flag)
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset2 =(y - info.offy)*info.width; 
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(lumMap[offset2] * 255.0);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2++;
				}
			}
		}
		else
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset2 =(y - info.offy)*info.width; 
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float r, g, b;
					getRGB(lumMap[offset2], uvMap[offset2*2], uvMap[offset2*2 +1], r, g, b);
					buffer[offsetBuf] = tobyte(r*255);
					buffer[offsetBuf + 1] = tobyte(g*255);
					buffer[offsetBuf + 2] = tobyte(b*255);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2++;
				}
			}
		}
		delete[] uvMap;
	}
	else //luminance unsharp masking
	{
        #pragma omp parallel for schedule(static,CHUNK)
		for (int y = info.offy; y < info.offy + info.height; y++)
		{
			int offset= y * width + info.offx;
			int offset2 = (y - info.offy)*info.width;
			for (int x = info.offx; x < info.offx + info.width; x++)
			{
				lumMap[offset2] = getLum(normalsPtr[offset], info.light);
				offset++;
				offset2++;
			}
		}
		enhancedLuminance(lumMap, info.width, info.height, info.mode);
		bool flag = (info.mode == LUM_UNSHARP_MODE || info.mode == SMOOTH_MODE || info.mode == CONTRAST_MODE || info.mode == ENHANCED_MODE);
		LightMemoized lVec(info.light.X(), info.light.Y());
		if (flag)
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset = y * width + info.offx;
				int offset2 = (y - info.offy)*info.width;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float lum = lumMap[offset2];
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(lum / 2.0 * 255.0);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset++;
					offset2++;
				}
			}
		}
		else
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset = y * width + info.offx;
				int offset2 = (y - info.offy)*info.width;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float lum = lumMap[offset2];
					buffer[offsetBuf] = tobyte(redPtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(redPtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 1] = tobyte(greenPtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(greenPtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 2] = tobyte(bluePtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(bluePtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset++;
					offset2++;
				}
			}
		}
	}
	delete[] lumMap;
}
Ejemplo n.º 6
0
void SpecularEnhancement::applyHSH(const PyramidCoeffF& redCoeff, const PyramidCoeffF& greenCoeff, const PyramidCoeffF& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	const float* redPtr = redCoeff.getLevel(info.level);
	const float* greenPtr = greenCoeff.getLevel(info.level);
	const float* bluePtr = blueCoeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	int tempW = mipMapSize[info.level].width();
    float hweights[9];
	vcg::Point3d temp(info.light.X(), info.light.Y(), info.light.Z());
	temp.Normalize();
	float phi = atan2(temp.Y(), temp.X());
	if (phi<0) 
		phi = 2*M_PI+phi;
    float theta = qMin<float>(acos(temp.Z()/temp.Norm()), M_PI / 2 - 0.04);

	//int offsetBuf = 0;
	getHSH(theta, phi, hweights, sqrt((float)info.ordlen));
	
	#pragma omp parallel for schedule(static,CHUNK) 
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
		int offsetBuf = (y-info.offy)*info.width*4;
		int offset= y * tempW + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
            float red = 0, green = 0, blue = 0;
			int offset2 = offset * info.ordlen;
			for (int k = 0; k < info.ordlen; k++)
			{
				int offset3 = offset2 + k;
				red += redPtr[offset3] * hweights[k];
				green += greenPtr[offset3] * hweights[k];
				blue += bluePtr[offset3] * hweights[k];
			}
			red *= 256;
			green *= 256;
			blue *= 256;

            vcg::Point3f h(0.0f, 0.0f, 1.0f);
			h += info.light;
            h /= 2.0f;
			h.Normalize();

            float nDotH = h * normalsPtr[offset];
			if (nDotH < 0) 
				nDotH = 0.0;
            else if (nDotH > 1.0f)
				nDotH = 1.0;
            nDotH = pow(nDotH, exp/5.0f);

            float temp = (red + green + blue)/3;
            float lum =  temp * ks * 4.0f * nDotH;
			buffer[offsetBuf + 0] = tobyte( red * kd + lum);
			buffer[offsetBuf + 1] = tobyte( green * kd + lum );
			buffer[offsetBuf + 2] = tobyte( blue * kd + lum );
            buffer[offsetBuf + 3] = 0xff;
			offsetBuf += 4;
			offset++;
		}
	}


}