Jump to content

[NormalMap] Restore Z from X and Y


Recommended Posts

[RUS] Плагин для восстановления Z из X и Y. Для установки скопировать xy2xyz.dll в папку Effects.

[ENG] Plugin to restore Z from X and Y. To install, copy xy2xyz.dll to the Effects folder.

 

// Name:		xy2xyz
// Submenu:		
// Author:		iOrange & xrModder
// Title:		xy2xyz
// Version:		0.1
// Desc:		Restore Z from X and Y
// Keywords:	
// URL:			
// Help:		

float Clamp(float v, float a, float b)
{
	return Math.Min(b, Math.Max(a, v));
}

void Render(Surface dst, Surface src, Rectangle rect)
{
	ColorBgra srcPixel, dstPixel = new ColorBgra();

	// [QAZ] Alfa kanaldy aq túspen boıaý
	// [RUS] Залить альфа канал белым цветом
	// [ENG] Fill alpha channel with white
	dstPixel.A = 255;

	for (int y = rect.Top; y < rect.Bottom; ++y)
	{
		if (IsCancelRequested) return;

		for (int x = rect.Left; x < rect.Right; ++x)
		{
			srcPixel = src[x, y];

			// [QAZ] R men G kanaldy (0...255) X pen Y (-1...+1) túrlendirý
			// [RUS] Конвертировать R и G канал (0...255) в X и Y (-1...+1)
			// [ENG] Convert R and G channel (0...255) to X and Y (-1...+1)
			float nx = (float)srcPixel.R / 127.5f - 1.0f;
			float ny = (float)srcPixel.G / 127.5f - 1.0f;

			// [QAZ] Z esepteý
			// [RUS] Вычислить Z
			// [ENG] Calculate Z
			float nz = (float)Math.Sqrt(Clamp(1.0f - (nx * nx + ny * ny), 0.0f, 1.0f));

			// [QAZ] R men G kanaldy ózgerissiz qaldyrý
			// [RUS] Оставить каналы R и G без изменений
			// [ENG] Keep R and G channel unchanged
			dstPixel.R = srcPixel.R;
			dstPixel.G = srcPixel.G;

			// [QAZ] Z (0...1) B kanalǵa túrlendirý (0...255)
			// [RUS] Конвертировать Z (0...1) в B канал (0...255)
			// [ENG] Convert Z (0...1) to B channel (0...255)
			dstPixel.B = (byte)Clamp(nz * 127.5f + 127.5f, 0.0f, 255.0f);

			dst[x, y] = dstPixel;
		}
	}
}

 

xy2xyz.zip

xy2xyz.jpg

Edited by xrModder
Добавил изображение
  • Like 2
  • Upvote 1
  • You're a Smart Cookie! 1
Link to post
Share on other sites

Hello @xrModder - congratulations on this plugin!

 

Can I suggest you change the location of it to Effects > Height Map? There are several tools which use this submenu, and I think yours will be a good fit.

Link to post
Share on other sites

[RUS] Можно восстановить любой NormalMap, если в текстуре есть X и Y. К примеру X в NormalMap игры Survarium находится в альфа канале (так как при сжатии DXT5 (BC3) в зелёном канале практический нет потерь, а альфа канал остается без изменении).

 

[ENG] You can restore any NormalMap, if the texture contains X and Y. For example, X in the NormalMap of Survarium is in the alpha channel (since with DXT5 (BC3) compression in the green channel there is practically no loss, and the alpha channel remains unchanged).

 

Пример кода / Sample code:

 

			...

			float nx = (float)srcPixel.A / 127.5f - 1.0f;
			float ny = (float)srcPixel.G / 127.5f - 1.0f;

			float nz = (float)Math.Sqrt(Clamp(1.0f - (nx * nx + ny * ny), 0.0f, 1.0f));

			dstPixel.R = srcPixel.A;
			dstPixel.G = srcPixel.G;

			dstPixel.B = (byte)Clamp(nz * 127.5f + 127.5f, 0.0f, 255.0f);

			...

 

xy2xyz.jpg

Edited by xrModder
+ English text
Link to post
Share on other sites

In English please @xrModder. It is acceptable to post a Google Translation :)

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...