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);
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);
相关文章推荐
- Cg per-pixel lighting with texture
- per pixel lighting 和 per vertex lighting
- Spot Light Per Pixel
- Cg per-pixel lighting with vertex lights
- Per Pixel Lighting [Part 2]
- Per Pixel Lighting [Part 7]
- Shader快速复习:Per Pixel Lighting(逐像素光照)
- Per Pixel Lighting(逐像素光照)
- Per Pixel Lighting [Part 3]
- Per Pixel Lighting [Part 6]
- Cg per-vertex lighting with texture
- Per Pixel Lighting [Part 5]
- Per-Pixel Lighting 逐象素光照
- Irrlicht学习备忘录——11 PerPixelLighting
- Irrlicht学习笔记(10)--PerPixelLighting
- 【GLSL教程】(八)纹理贴图
- OpenGL进阶(十六) - GLSL纹理(Texture)
- 批量修改Texture属性 两种方式加载贴图,通过Resources.LoadAll Directoy 获取项目路径:Application.dataPath; using UnityEn
- Cg per-pixel lighting
- OpenGL进阶(十三) - GLSL光照(Lighting)