您的位置:首页 > 其它

GLSL per-pixel lighting + spot texture (聚光灯贴图)

2008-10-26 10:18 351 查看
聚光灯贴图,就是聚光灯照射在表面上的那个光圈,准备一张spot texture的亮度图,采用“GLSL projective texture ”一文中介绍的投影贴图方法把spot texture 投射到聚光灯方向。

unsigned char* pixels = (unsigned char*)malloc( 64*64 );

for (int j = 0; j < 64; j++){

for (int i = 0; i < 64; i++){

float x = (i / 31.5f) - 1;

float y = (j / 31.5f) - 1;

float ls = max(1 - (x * x + y * y), 0.0f);

pixels[j * 64 + i] = (unsigned char) (255.0f * ls);

}

}

texid_spot = GL_create_texture( 64,64,GL_LUMINANCE,pixels );

glBindTexture( GL_TEXTURE_2D,texid_spot );

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D( GL_TEXTURE_2D,0,GL_LUMINANCE8,64,64,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,pixels );

glBindTexture( GL_TEXTURE_2D,0);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: