fix bug
This commit is contained in:
parent
78ac5d9b40
commit
212534298c
@ -59,7 +59,7 @@ ILImage::~ILImage()
|
|||||||
|
|
||||||
bool ILImage::Create(ILuint w,ILuint h,ILuint c,ILuint t,void *data)
|
bool ILImage::Create(ILuint w,ILuint h,ILuint c,ILuint t,void *data)
|
||||||
{
|
{
|
||||||
const ILenum format[]=
|
const ILenum format_list[]=
|
||||||
{
|
{
|
||||||
IL_LUMINANCE,
|
IL_LUMINANCE,
|
||||||
IL_LUMINANCE_ALPHA,
|
IL_LUMINANCE_ALPHA,
|
||||||
@ -71,8 +71,11 @@ bool ILImage::Create(ILuint w,ILuint h,ILuint c,ILuint t,void *data)
|
|||||||
|
|
||||||
Bind();
|
Bind();
|
||||||
|
|
||||||
ilClearImage();
|
if(!ilTexImage(w,h,1,c,format_list[c-1],t,data))
|
||||||
return ilTexImage(w,h,1,c,format[c-1],t,data);
|
return(false);
|
||||||
|
|
||||||
|
iluFlipImage();
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ILImage::SaveFile(const OSString &filename)
|
bool ILImage::SaveFile(const OSString &filename)
|
||||||
@ -90,10 +93,18 @@ void ILImage::Bind()
|
|||||||
|
|
||||||
bool ILImage::Resize(uint nw,uint nh)
|
bool ILImage::Resize(uint nw,uint nh)
|
||||||
{
|
{
|
||||||
if(nw==il_width&&nh==il_height)return(false);
|
if(nw==il_width&&nh==il_height)return(true);
|
||||||
if(nw==0||nh==0)return(false);
|
if(nw==0||nh==0)return(false);
|
||||||
|
|
||||||
return iluScale(nw,nh,il_depth);
|
Bind();
|
||||||
|
|
||||||
|
if(!iluScale(nw,nh,il_depth))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
il_width=nw;
|
||||||
|
il_height=nh;
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ILImage::Convert(ILuint format,ILuint type)
|
bool ILImage::Convert(ILuint format,ILuint type)
|
||||||
|
40
MicroPBR.cpp
40
MicroPBR.cpp
@ -93,6 +93,8 @@ namespace hgl
|
|||||||
|
|
||||||
uint8 *GetRGB(){return (uint8 *)img.GetRGB(IL_UNSIGNED_BYTE);}
|
uint8 *GetRGB(){return (uint8 *)img.GetRGB(IL_UNSIGNED_BYTE);}
|
||||||
uint8 *GetLum(){return (uint8 *)img.GetLum(IL_UNSIGNED_BYTE);}
|
uint8 *GetLum(){return (uint8 *)img.GetLum(IL_UNSIGNED_BYTE);}
|
||||||
|
|
||||||
|
bool SaveFile(const OSString &fn){return img.SaveFile(fn);}
|
||||||
};//class PBRComponent
|
};//class PBRComponent
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
|
||||||
@ -112,14 +114,14 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
CmdParse cp(argc,argv);
|
CmdParse cp(argc,argv);
|
||||||
|
|
||||||
|
ilInit();
|
||||||
|
|
||||||
PBRComponent color (OS_TEXT("BaseColor"),OS_TEXT("/C:")),
|
PBRComponent color (OS_TEXT("BaseColor"),OS_TEXT("/C:")),
|
||||||
normal (OS_TEXT("Normal" ),OS_TEXT("/N:")),
|
normal (OS_TEXT("Normal" ),OS_TEXT("/N:")),
|
||||||
metallic (OS_TEXT("Metallic" ),OS_TEXT("/M:")),
|
metallic (OS_TEXT("Metallic" ),OS_TEXT("/M:")),
|
||||||
roughness (OS_TEXT("Roughness"),OS_TEXT("/R:"));
|
roughness (OS_TEXT("Roughness"),OS_TEXT("/R:"));
|
||||||
|
|
||||||
ilInit();
|
|
||||||
|
|
||||||
color.Parse(cp);
|
color.Parse(cp);
|
||||||
normal.Parse(cp);
|
normal.Parse(cp);
|
||||||
metallic.Parse(cp);
|
metallic.Parse(cp);
|
||||||
@ -138,12 +140,15 @@ namespace hgl
|
|||||||
uint nh=hgl_max(color.height(),normal.height());
|
uint nh=hgl_max(color.height(),normal.height());
|
||||||
|
|
||||||
color.Resize(nw,nh);
|
color.Resize(nw,nh);
|
||||||
|
normal.Resize(nw,nh);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint w=color.width();
|
const uint w=color.width();
|
||||||
const uint h=color.height();
|
const uint h=color.height();
|
||||||
const uint half_w=w>>1;
|
const uint half_w=w>>1;
|
||||||
const uint half_h=h>>1;
|
const uint half_h=h>>1;
|
||||||
|
const uint pixel_total=w*h;
|
||||||
|
const uint half_pixel_total=half_w*half_h;
|
||||||
|
|
||||||
if(metallic.isHas())
|
if(metallic.isHas())
|
||||||
{
|
{
|
||||||
@ -159,11 +164,11 @@ namespace hgl
|
|||||||
|
|
||||||
uint8 *y,*u,*v,*nx,*ny;
|
uint8 *y,*u,*v,*nx,*ny;
|
||||||
|
|
||||||
y=new uint8[w*h];
|
y=new uint8[pixel_total];
|
||||||
u=new uint8[half_w*half_h];
|
u=new uint8[half_pixel_total];
|
||||||
v=new uint8[half_w*half_h];
|
v=new uint8[half_pixel_total];
|
||||||
nx=new uint8[w*h];
|
nx=new uint8[pixel_total];
|
||||||
ny=new uint8[w*h];
|
ny=new uint8[pixel_total];
|
||||||
|
|
||||||
RGB2YUV(y,u,v,color.GetRGB(),w,h);
|
RGB2YUV(y,u,v,color.GetRGB(),w,h);
|
||||||
normal_compress(nx,ny,normal.GetRGB(),w*h);
|
normal_compress(nx,ny,normal.GetRGB(),w*h);
|
||||||
@ -173,9 +178,9 @@ namespace hgl
|
|||||||
ILImage img;
|
ILImage img;
|
||||||
const OSString out_filename=OSString(argv[1])+OS_TEXT("_YN.png");
|
const OSString out_filename=OSString(argv[1])+OS_TEXT("_YN.png");
|
||||||
|
|
||||||
uint8 *pixels=new uint8[w*h*3];
|
uint8 *pixels=new uint8[pixel_total*3];
|
||||||
|
|
||||||
MixRGB<uint8>(pixels,y,nx,ny,w*h);
|
MixRGB<uint8>(pixels,y,nx,ny,pixel_total);
|
||||||
|
|
||||||
img.Create(w,h,3,IL_UNSIGNED_BYTE,pixels);
|
img.Create(w,h,3,IL_UNSIGNED_BYTE,pixels);
|
||||||
|
|
||||||
@ -190,9 +195,12 @@ namespace hgl
|
|||||||
ILImage img;
|
ILImage img;
|
||||||
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVMR.png");
|
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVMR.png");
|
||||||
|
|
||||||
uint8 *pixels=new uint8[half_w*half_h*4];
|
const uint8 *m=metallic.GetLum();
|
||||||
|
const uint8 *r=roughness.GetLum();
|
||||||
|
|
||||||
MixRGBA<uint8>(pixels,u,v,metallic.GetLum(),roughness.GetLum(),half_w*half_h);
|
uint8 *pixels=new uint8[half_pixel_total*4];
|
||||||
|
|
||||||
|
MixRGBA<uint8>(pixels,u,v,m,r,half_pixel_total);
|
||||||
|
|
||||||
img.Create(half_w,half_h,4,IL_UNSIGNED_BYTE,pixels);
|
img.Create(half_w,half_h,4,IL_UNSIGNED_BYTE,pixels);
|
||||||
|
|
||||||
@ -207,9 +215,10 @@ namespace hgl
|
|||||||
ILImage img;
|
ILImage img;
|
||||||
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVM.png");
|
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVM.png");
|
||||||
|
|
||||||
uint8 *pixels=new uint8[half_w*half_h*3];
|
uint8 *pixels=new uint8[half_pixel_total*3];
|
||||||
|
const uint8 *m=metallic.GetLum();
|
||||||
|
|
||||||
MixRGB<uint8>(pixels,u,v,metallic.GetLum(),half_w*half_h);
|
MixRGB<uint8>(pixels,u,v,m,half_pixel_total);
|
||||||
|
|
||||||
img.Create(half_w,half_h,3,IL_UNSIGNED_BYTE,pixels);
|
img.Create(half_w,half_h,3,IL_UNSIGNED_BYTE,pixels);
|
||||||
|
|
||||||
@ -224,9 +233,10 @@ namespace hgl
|
|||||||
ILImage img;
|
ILImage img;
|
||||||
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVR.png");
|
const OSString out_filename=OSString(argv[1])+OS_TEXT("_UVR.png");
|
||||||
|
|
||||||
uint8 *pixels=new uint8[half_w*half_h*3];
|
uint8 *pixels=new uint8[half_pixel_total*3];
|
||||||
|
const uint8 *r=roughness.GetLum();
|
||||||
|
|
||||||
MixRGB<uint8>(pixels,u,v,roughness.GetLum(),half_w*half_h);
|
MixRGB<uint8>(pixels,u,v,r,half_pixel_total);
|
||||||
|
|
||||||
img.Create(half_w,half_h,3,IL_UNSIGNED_BYTE,pixels);
|
img.Create(half_w,half_h,3,IL_UNSIGNED_BYTE,pixels);
|
||||||
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
#include<hgl/type/DataType.h>
|
#include<hgl/type/DataType.h>
|
||||||
#include<hgl/math/Vector.h>
|
#include<hgl/math/Vector.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A_bit_more_deferred_-_CryEngine3
|
* A_bit_more_deferred_-_CryEngine3
|
||||||
|
|
||||||
Normal to GBufffer:
|
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:
|
GBuffer to Normal:
|
||||||
|
|
||||||
N.z=length2(G.xy)*2-1N.xy=normalize(G.xy)*sqrt(1-N.z*N.z)
|
N.z=length2(G.xy)*2-1
|
||||||
|
N.xy=normalize(G.xy)*sqrt(1-N.z*N.z)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user