NeNe OpenGL Lesson41 - Volumetric Fog(体积雾) & IPicture Image Loading

本文探讨了使用OpenGL创建不随距离衰减的雾效果的方法,包括通过glFogCoordf指定每个顶点的雾密度,以及使用渲染到纹理和后期处理来提升视觉效果。介绍了两种体积雾实现方式:通过前后表面深度图计算雾密度,和利用体积纹理表示场景中的雾分布。
部署运行你感兴趣的模型镜像

lesson41_screenshot

     This samples shows us how to create some fog effect that does not fall off by the distance between the viewer and vertex position. With OpenGL command glFogCoordf, we could specify a fog density for each vertex.
    Of course, there are other ways to create the volumetric fog effect. To get better visual effect, we usually work with the render to texture & post-process.
1) method one, draw the back surface & front surface of a box separately to get two different depth map. These two depth map could be used to check whether some pixel in the fog or not. A volumetric fog post-process created to calculate how fog density will be for each pixel.
2) method two, we could create a volume texture to represent how the fog in the scene should be. In the post-process step, we could restore a 3D position by screen position, depth value and view matrix. We could sample the volume texture well with this 3D vertex position.

Volumetric fog with glFogCoordf

Set up fog with OpenGL commands, the code almost the same as usual fog set up process except the last line to switch on the fog coordinate feature:

glEnable(GL_FOG);    
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_START,  0.0f);
glFogf(GL_FOG_END,    1.0f);
glHint(GL_FOG_HINT, GL_NICEST);    
glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);

Fog extension on windows, because windows does not support OpenGL advanced feature natively.(Windows already has D3D, no need for them update OpenGL)

// check "EXT_fog_coord" extension first
...
// Enable glFogCoordEXT
glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC) wglGetProcAddress("glFogCoordfEXT");

Draw with glFogCoordfEXT, specify a fog density for each vertex, a bit similar as specify a texture coordinates with glTexCoord2f function.

glBegin(GL_QUADS);                                                    // Back Wall
    glFogCoordfEXT( 1.0f);    glTexCoord2f(0.0f, 0.0f);    glVertex3f(-2.5f,-2.5f,-15.0f);
    glFogCoordfEXT( 1.0f);    glTexCoord2f(1.0f, 0.0f);    glVertex3f( 2.5f,-2.5f,-15.0f);
    glFogCoordfEXT( 1.0f);    glTexCoord2f(1.0f, 1.0f);    glVertex3f( 2.5f, 2.5f,-15.0f);
    glFogCoordfEXT( 1.0f);    glTexCoord2f(0.0f, 1.0f);    glVertex3f(-2.5f, 2.5f,-15.0f);
glEnd();


IPicture Image Load

Create a texture from temporary bitmap (get after OleLoadPicturePath() load the image content ), no matter from local disc or network. Well, I think no matter you write a small graphic program ,engine or game, we should need to design how texture should be found and loaded. We may even need to design a texture assets pipeline.


The full source code could be found here.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/17/2643389.html

您可能感兴趣的与本文相关的镜像

Dify

Dify

AI应用
Agent编排

Dify 是一款开源的大语言模型(LLM)应用开发平台,它结合了 后端即服务(Backend as a Service) 和LLMOps 的理念,让开发者能快速、高效地构建和部署生产级的生成式AI应用。 它提供了包含模型兼容支持、Prompt 编排界面、RAG 引擎、Agent 框架、工作流编排等核心技术栈,并且提供了易用的界面和API,让技术和非技术人员都能参与到AI应用的开发过程中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值