//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	FeatureGrid::BLENDFUNCTION (
		FeatureInstance *featureInstance, 
		unsigned char *pix_buf, 
		int start_span, 
		int end_span,
		int downScale
	)
{
	unsigned char *data_ptr = featureInstance->currentTexturePtr;
	int texture_width = (featureInstance->feature->featureTexture->width) >> downScale;
	int count_down = featureInstance->countDownToBorder;

#ifdef SHOW_MATERIAL
	DWORD mat_color = downScale & 0xffffff;
	downScale >>= 24;
#endif

#ifdef TEXTURE_HORIZONTAL_FLIP
#else
#endif
	WORD *data_ptr_word = (WORD *)data_ptr;

#ifdef TEXTURE_HORIZONTAL_FLIP
	int i, j;
	for(i=0,j=0;i<end_span-start_span;i++,j--)
#else
	for(int i=0;i<end_span-start_span;i++)
#endif
	{
#ifdef TEXTURE_HORIZONTAL_FLIP
		int alpha = (data_ptr_word[j] & 0xf) << 4;

	#ifdef SHOW_MATERIAL
		if(alpha>0x80)
		{
			*(DWORD *)pix_buf = mat_color;
		}
	#else	//	SHOW_MATERIAL
		if(alpha>0)
		{
			int col = *pix_buf*(0xf0-alpha) + (data_ptr_word[j] & 0xf0)*alpha;
			*pix_buf = static_cast<unsigned char>(col>>8);

			col = *(pix_buf+1)*(0xf0-alpha) + ((data_ptr_word[j] & 0xf00)>>4)*alpha;
			*(pix_buf+1) = static_cast<unsigned char>(col>>8);

			col = *(pix_buf+2)*(0xf0-alpha) + ((data_ptr_word[j] & 0xf000)>>8)*alpha;
			*(pix_buf+2) = static_cast<unsigned char>(col>>8);
		}
	#endif	//	SHOW_MATERIAL

		if(--count_down <= 0)
		{
			data_ptr_word += texture_width;
			count_down = texture_width;
		}
#else
		int alpha = (data_ptr_word[i] & 0xf) << 4;

	#ifdef SHOW_MATERIAL
		if(alpha>0x80)
		{
			*(DWORD *)pix_buf = mat_color;
		}
	#else	//	SHOW_MATERIAL
		if(alpha>0)
		{
			int col = *pix_buf*(0xf0-alpha) + (data_ptr_word[i] & 0xf0)*alpha;
			*pix_buf = static_cast<unsigned char>(col>>8);

			col = *(pix_buf+1)*(0xf0-alpha) + ((data_ptr_word[i] & 0xf00)>>4)*alpha;
			*(pix_buf+1) = static_cast<unsigned char>(col>>8);

			col = *(pix_buf+2)*(0xf0-alpha) + ((data_ptr_word[i] & 0xf000)>>8)*alpha;
			*(pix_buf+2) = static_cast<unsigned char>(col>>8);
		}
	#endif	//	SHOW_MATERIAL

		if(--count_down <= 0)
		{
			data_ptr_word -= texture_width;
			count_down = texture_width;
		}
#endif

		pix_buf += colorDepth;
	}

}