简体   繁体   English

如何在openGL中制作一个光球?

[英]How can I make a ball of light in openGL?

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. 我会给你一些代码snipets。 It's in Java LWJGL, so it might look a little different. 它在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

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? 我还需要做些什么来使灯光可见?

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. 您将需要查找glColorMaterial函数,因为它们是设置材质属性的最简单方法。

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. 有关生成轻微绽放的信息,请阅读此OpenGL Bloom教程 ,这里是一些使用GLSL生成bloom效果的Java 示例代码

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. 根据你是否想要盛开式效果(如果是这样,看看Josh Perry的答案)或者只是一个看似发光的非暗物体对象,你可能想要考虑这种简单的方法。

  • Render the scene without the actual 'sun' mesh but with a point light at the centre of your 'sun'. 渲染场景时没有实际的“太阳”网格,但在“太阳”的中心有一个点光源。
  • Disable GL Lighting. 禁用GL照明。
  • Render a sphere or use a billboard to render an image of your sun in the appropriate spot. 渲染球体或使用广告牌在适当的位置渲染太阳图像。
  • Re-enable GL Lighting before you display your next frame. 在显示下一帧之前重新启用GL Lighting。

Because you've disabled lighting, the sun will be rendered 'full-bright' with no shading or lighting calculations being performed. 因为您已禁用照明,所以太阳将呈现为“全亮”,不会执行阴影或光照计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM