OpenGL 照明小物体?

发布于 2024-11-03 06:05:43 字数 1114 浏览 3 评论 0原文

在处理非常小的颗粒时,我遇到了照明问题。我正在进行基于粒子的流体模拟,并且现在将流体渲染为非常小的多边形球体(我所说的非常小,是指球体的半径约为 0.03 个单位)。我的场景中的灯光没有按照我想要的方式照亮它们,而且我无法让它看起来正确。我正在寻找类似于此图像中粒子上的柔和灯光的东西...... 具有正确光照的粒子

但是我的粒子看起来像这样...

我的粒子看起来像什么

查看我的粒子如何具有明亮的白色部分,而绿色粒子只是柔和地点亮,并且没有大的白色热点。我知道原因要么是我的灯光设置,要么只是粒子太小,以至于灯光占据了更大的空间(这可能吗?)。我的照明设置如下......

GLfloat mat_ambient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess[] = {10.0};
GLfloat light_position[] = {0.0, 0.1, p_z, 1.0};
GLfloat model_ambient[] = {0.5, 0.5, 0.5, 1.0};

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

I'm having a problem with lighting when dealing with really small particles. I'm doing particle-based fluid simulation and am right now rendering the fluid as really tiny polygonized spheres (by really tiny I'm saying about 0.03 units radius for the spheres). The lighting in my scene isn't lighting them how I want and I can't get it to look right. I'm looking for something similar to the soft lighting on the particles in this image...
particles with correct lighting

However my particles look like this...

What my particles look like

See how my particles have bright white sections whereas the green particles are just lit up softly and don't have large white hotspots. I know the reason is either the settings for my light or simply the fact that the particles are so small that the light takes up a larger space (is that possible??). My settings for lighting are as follows...

GLfloat mat_ambient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess[] = {10.0};
GLfloat light_position[] = {0.0, 0.1, p_z, 1.0};
GLfloat model_ambient[] = {0.5, 0.5, 0.5, 1.0};

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绝情姑娘 2024-11-10 06:05:43

感谢大家的所有建议,但不幸的是没有任何效果。我和我的图形学教授坐下来,我们确定这个问题实际上与粒子的大小以及 OpenGL 将定向光视为距离任何顶点无限远这一事实有关。修复它的正确方法是像这样修改光源的恒定衰减...

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 10.0);

现在我的粒子看起来像这样...

“在此输入图像描述”
这正是我想要的灯光!

Thanks for all the suggestions everyone but unfortunately nothing worked. I sat down with my graphics professor and we determined that this problem was in fact related to the size of the particles and the fact that OpenGL treats directional lights as being infinitely far away from any vertex. The proper way to fix it was modifying the constant attenuation of the light source like this...

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 10.0);

Now my particles look like this...

enter image description here
which is exactly the lighting I was after!

深海蓝天 2024-11-10 06:05:43

颗粒的大小不是问题——你的颜色过度饱和了。

对于每个 RGB 分量,您应该具有环境光 + 漫反射 + 镜面反射 <= 1.0

对于这样的场景,我希望 环境光 不超过 0.1 左右,漫反射0.6左右,镜面反射弥补其余部分。

The size of the particles isn't an issue - you're over-saturating your colours.

For each RGB component, you should have ambient + diffuse + specular <= 1.0

For a scene like this I'd expect ambient to be no more than 0.1 or so, diffuse of 0.6 or so, and specular making up the rest.

怀念你的温柔 2024-11-10 06:05:43

看来您需要调低材质的镜面反射分量,稍微调低环境光,并添加一些漫反射着色 (GL_DIFFUSE)。还要考虑将灯光放置在视口/相机后面。

It looks like you need to turn down the specular component of your material, turn down the ambient a bit, and add some diffuse shading (GL_DIFFUSE). Consider also positioning the light behind the the viewport/camera.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文