2014年2月25日星期二(DEMO8-2,光照图调制)
来源:互联网 发布:济宁seo 编辑:程序博客网 时间:2024/06/05 05:41
粗略看了下,这个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);
结果如下图
- 2014年2月25日星期二(DEMO8-2,光照图调制)
- 2014年8月26日星期二(DEMO8-9加载COB模型)
- 2014年7月8日星期二(DEMO8-8加载3DSMAX ASCII格式模型.ASC)
- 2014年2月22日星期六(DEMO8-1,颜色与放缩系数相乘)
- 2009年6月2日星期二
- 2006年2月1日~3日 星期二 雨
- 2014年3月3日星期一(DEMO8-3,ALPHA混合)
- 2014年3月7日星期五(DEMO8-4,实体三角形着色)
- 2014年3月8日星期六(DEMO8-5恒定着色)
- 2014年3月9日星期日(DEMO8-6,画家算法)
- 2014年7月7日星期一(DEMO8-7使用新的模型格式)
- 2014年1月14日星期二(DEMO7-2,加载3D线框立方体物体模型)
- 2013年9月24日星期二(demo5_1参数化2D直线)
- 2013年11月26日星期二(t3dlib1剩余部分---2)
- 2014年11月18日星期二( DEMO9-4)
- 2013年9月11日星期三(demo8-7,三角形)
- 2013年11月22日星期五(demo8-12,稀疏平铺显示)
- 2011年12月6日星期二(oracle读书笔记)
- 别人同一个房间
- 排序算法大总结
- 【开发工具】二、版本控制工具历史的十个里程碑
- 数据库系统概念 sql 查询语句 读书笔记
- 公司项目注意事项 教训三
- 2014年2月25日星期二(DEMO8-2,光照图调制)
- extjs4.0——目录结构
- 同样会尽快么
- Android平台架构
- C#模拟post提交HttpPost类(可以提交文件)
- 好朋友的祝福
- HSIPAW(昔卜)
- php中include和require的区别
- CAS原理分析