2014年2月25日星期二(DEMO8-2,光照图调制)

本文详细介绍了如何通过调整光照图和纹理映射来优化实时渲染中的光照效果,包括光照图的初始化、纹理和光照图的混合计算,以及光照效果的最终呈现。通过将光照图与纹理进行融合,实现更真实、细腻的视觉体验。

粗略看了下,这个DEMO加上了个光照图,

首先定义了个灯光数量,

#define                       NUM_LAMP                              4

以及光照图数组

BITMAP_IMAGE    lightmaps[NUM_LAMP];

 

初始化时,位置不同了

{

                  bitmap->Create_Bitmap( & textures[itext], ( SCREEN_WIDTH / 2) - 4 *( TEXTSIZE / 2), ( SCREEN_HEIGHT / 2 ) - 2 *( TEXTSIZE / 2), TEXTSIZE, TEXTSIZE, 16 );

        

         bitmap->Create_Bitmap( & temp_text, ( SCREEN_WIDTH / 2) - ( TEXTSIZE / 2), ( SCREEN_HEIGHT / 2) + ( TEXTSIZE / 2), TEXTSIZE, TEXTSIZE, 16 );

 

光照图的初始化

bitmap->Load_Bitmap_File( & bitmap16bit, "lightmaps128_24.BMP");

         for ( int itext = 0; itext < NUM_LAMP; itext++)

         {

                  bitmap->Create_Bitmap( & lightmaps[itext], ( SCREEN_WIDTH / 2) + 2 *( TEXTSIZE / 2), ( SCREEN_HEIGHT / 2 ) - 2 *( TEXTSIZE / 2), TEXTSIZE, TEXTSIZE, 16 );

                  bitmap->Load_Image_Bitmap16( & lightmaps[itext],&bitmap16bit, itext % 4, itext / 4, BITMAP_EXTRACT_MODE_CELL );

 

         }

         bitmap->Unload_Bitmap_File( &bitmap16bit );

把数值改了下

 

         int             curr_texture                = 7;

         float scalef                                   = 0.5;

         int         curr_lightmap              = 1;

这个DEMO是用了下面方式调制

Pixel_dest[x,y]rgb = pixel_source[x,y]rgb * ambient +

//                      pixel_source[x,y]rgb * light_map[x,y]rgb

其实,知道原理了,剩下的都顺理成章了

 

         USHORT *                sbuffer                                         = ( USHORT * )textures[curr_texture].buffer;

         USHORT *                lbuffer                                          = ( USHORT * )lightmaps[curr_lightmap].buffer;

         USHORT *                tbuffer                                         = ( USHORT * )temp_text.buffer;

 

         for ( int iy = 0; iy < temp_text.height; iy ++)

         {

                  for ( int ix = 0; ix < temp_text.width; ix ++)

                  {

                          int             rs, gs, bs;

                          int             rl, gl, bl;

                          int             rf, gf, bf;

 

                          USHORT spixel                                   = sbuffer[iy * temp_text.width + ix];                   

                          _RGB565FROM16BIT( spixel, &rs, &gs, &bs );

                          USHORT lpixel                                   = lbuffer[iy * temp_text.width + ix];                   

                          _RGB565FROM16BIT( lpixel, &rs, &gs, &bs );

 

                          rf                                                           = ( scalef * (float) rs ) + ( ( float) rs * (float )rl/(float)64 );

                          gf                                                          = ( scalef * (float) gs ) + ( ( float) gs * (float )rl/(float)64 );

                          bf                                                          = ( scalef * (float) bs ) + ( ( float) bs * (float )rl/(float)64 );

 

                          if ( rf > 255 )

                          {

                                   rf                                                  = 255;

                          }

                          if ( gf > 255 )

                          {

                                   gf                                                 = 255;

                          }               

                          if ( bf > 255 )

                          {

                                   bf                                                 = 255;

                          }                       

                          tbuffer[iy * temp_text.width + ix]       = _RGB16BIT565( rf, gf, bf );

                  }

 

         }

        

        

         bitmap->Draw_Bitmap16( &temp_text, ddraw->getbackbuffer(), ddraw->getbacklpitch(), 0);

         bitmap->Draw_Bitmap16( &textures[curr_texture], ddraw->getbackbuffer(), ddraw->getbacklpitch(), 0);

         bitmap->Draw_Bitmap16( &lightmaps[curr_lightmap], ddraw->getbackbuffer(), ddraw->getbacklpitch(), 0);

 

结果如下图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值