如何在 openGL 中制作一个光球?
我正在尝试制作一个光球(如太阳),但我似乎根本无法使其可见。我会给你一些我拥有的代码片段。它是用 Java LWJGL 编写的,所以看起来可能有点不同。
private float lightAmbient[] = { 0.0f, 1.0f, 1.0f, 1.0f }; // Ambient Light Values ( NEW )
private float lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values ( NEW )
private float lightPosition[] = { 0.0f, 0.0f, -5.0f, 1.0f }; // Light Position ( NEW )
float lightSpecular[] = { 0f, 0f, 0.5f, 1.0f }; // highlight
?
ByteBuffer temp = ByteBuffer.allocateDirect(16);
temp.order(ByteOrder.nativeOrder());
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip()); // Setup The Ambient Light
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip()); // Setup The Diffuse Light
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip()); // Position The Light
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR,(FloatBuffer)temp.asFloatBuffer().put(lightSpecular).flip()); // Position The Light
GL11.glEnable(GL11.GL_LIGHT1);
我还需要做什么才能使光线可见
I'm trying to make a orb of light (Like a sun) but I can't seem to make it visible at all. I'll give you some snipets of code I have. It's in Java LWJGL, so it might look a little different.
private float lightAmbient[] = { 0.0f, 1.0f, 1.0f, 1.0f }; // Ambient Light Values ( NEW )
private float lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values ( NEW )
private float lightPosition[] = { 0.0f, 0.0f, -5.0f, 1.0f }; // Light Position ( NEW )
float lightSpecular[] = { 0f, 0f, 0.5f, 1.0f }; // highlight
and
ByteBuffer temp = ByteBuffer.allocateDirect(16);
temp.order(ByteOrder.nativeOrder());
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip()); // Setup The Ambient Light
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip()); // Setup The Diffuse Light
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip()); // Position The Light
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR,(FloatBuffer)temp.asFloatBuffer().put(lightSpecular).flip()); // Position The Light
GL11.glEnable(GL11.GL_LIGHT1);
What else do I have to do to make the light visible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
灯永远不可见。
然而,它们对其他物体材质的影响却很大。因此,场景中的所有对象都设置适当的材质属性非常重要。
您可能会对这篇文章感兴趣,其中提到了人们在以下情况下犯的所有常见错误试图照亮场景。
您将需要查找 glColorMaterial 函数,因为它们是设置材质属性的最简单方法。
Lights are never visible.
However, their affects on the materials of other objects are. It's therefore important that all objects in the scene have appropriate material properties set.
You may be interested in this article that mentions all the common mistakes one makes when trying to illuminate scenes.
You will want to look up the glColorMaterial functions as they are the easiest way to set material properties.
正如弗兰克所说,灯光是不可见的,它们仅用作渲染系统(硬件/软件)用于计算几何体的最终颜色的照明方程的输入。
如果您希望某些东西看起来像光,您需要模仿您在观看明亮光源时所看到的效果。对于太阳来说,最明显的效果之一就是光晕。
有关生成光绽放的信息,请阅读OpenGL Bloom 教程,这里有一些Java 中使用 GLSL 生成光晕效果的示例代码。
Like Frank said, lights are invisible, they are merely used as an input to the lighting equation used by the rendering system (hardware/software) to calculate the final colors of geometry.
If you want something to look like a light you need to mimic the effects that you are used to seeing when looking at a bright light source. For the sun one of the most noticeable effects is light bloom.
For information on generating light bloom read this OpenGL Bloom Tutorial, and here is some sample code in Java using GLSL to generate a bloom effect.
根据您是否想要盛开风格的效果(如果是这样,请查看 Josh Perry 的答案)或只是一个看起来发光的非暗对象,您可能需要考虑这种简单的方法。
由于您已禁用照明,因此太阳将被渲染为“全亮”,并且不会执行任何着色或照明计算。
Depending on if you want full bloom style effects (if so, look at Josh Perry's answer) or just a not-dark object object that seems to emit light you might want to consider this simple approach.
Because you've disabled lighting, the sun will be rendered 'full-bright' with no shading or lighting calculations being performed.