update Spheremap Transform algorithm
This commit is contained in:
parent
e7e70491b1
commit
1cfb30faea
@ -6,7 +6,7 @@
|
||||
|
||||
Normal to GBufffer:
|
||||
|
||||
G=normalize(N.xy)*sqrt(N.z*0.5+0.5)
|
||||
G=normalize(N.xy)*sqrt(-N.z*0.5+0.5)
|
||||
|
||||
GBuffer to Normal:
|
||||
|
||||
@ -19,7 +19,7 @@ namespace hgl
|
||||
void normal_compress(uint8 *x,uint8 *y,const uint8 *rgb,const uint count)
|
||||
{
|
||||
Vector3f in;
|
||||
Vector2f in_xy;
|
||||
float f;
|
||||
Vector2f out;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
@ -28,8 +28,11 @@ namespace hgl
|
||||
in.y=float(*rgb)/255.0f;++rgb;
|
||||
in.z=float(*rgb)/255.0f;++rgb;
|
||||
|
||||
in_xy=in.xy().Normalized();
|
||||
out=in_xy*sqrt(in.z*0.5+0.5);
|
||||
//Spheremap Transform,PSNR 48.071 dB,15 GPU cycles
|
||||
f=sqrt(8*in.z+8);
|
||||
out=in.xy()/f+Vector2f(0.5);
|
||||
|
||||
out=out.Clamp01();
|
||||
|
||||
*x=out.x*255;++x;
|
||||
*y=out.y*255;++y;
|
||||
@ -39,20 +42,25 @@ namespace hgl
|
||||
void normal_decompress(uint8 *rgb,const uint8 *x,const uint8 *y,const uint count)
|
||||
{
|
||||
Vector2f in;
|
||||
Vector2f in_normal;
|
||||
Vector2f fenc;
|
||||
Vector3f out;
|
||||
float s;
|
||||
float f,g;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
in.x=(*x)/255.0f;++x;
|
||||
in.y=(*y)/255.0f;++y;
|
||||
|
||||
//Spheremap Transform,PSNR 48.071 dB,15 GPU cycles
|
||||
fenc=in*4.0f-Vector2f(2.0f);
|
||||
f=dot(fenc,fenc);
|
||||
g=sqrt(1.0-f/4.0f);
|
||||
|
||||
out.z=length(in)*2.0-1;
|
||||
in_normal=in.Normalized();
|
||||
s=sqrt(1-out.z*out.z);
|
||||
out.x=in_normal.x*s;
|
||||
out.y=in_normal.y*s;
|
||||
out.x=fenc.x*g;
|
||||
out.y=fenc.y*g;
|
||||
out.z=1-f/2.0f;
|
||||
|
||||
out=out.Clamp01();
|
||||
|
||||
*rgb=out.x*255;++rgb;
|
||||
*rgb=out.y*255;++rgb;
|
||||
|
Loading…
x
Reference in New Issue
Block a user