Android OpenGL 天空盒光不起作用

发布于 2024-12-11 12:21:22 字数 2538 浏览 0 评论 0原文

好的,我已经制作了一个“天空盒”(它实际上是 5 个平面,因为纹理不同)。它工作正常,但闪电有问题。这不是我在 OpenGL 方面的强项,所以如果答案不是那么难,我也不会感到惊讶。

这就是我的起始位置视图。正如你所看到的,前平面是明亮的,但左、上、右并不是真正的,它们和前平面之间有一个边界。

http://img696.imageshack.us/img696/3673/light01.png

当我到达天空盒的绝对中心(接近)时,边框就不那么明显了(我猜在绝对中心没有边框。

http://img233.imageshack.us/img233/2949/light02.png

首先我尝试使用这些设置在位置(0,0,0)处使用一盏灯,但什么也没有,我尝试改变环境,漫反射,但并没有真正帮助:

    private float[] lightAmbient = {0.5f, 0.5f, 0.5f, 1.0f};
    private float[] lightDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};
    private float[] lightPosition = {0.0f, 0.0f, 0.0f, 1.0f};

    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            gl.glEnable(GL10.GL_DITHER);
            gl.glEnable(GL10.GL_TEXTURE_2D);
            gl.glShadeModel(GL10.GL_SMOOTH);
            gl.glClearColor(0, 0, 0, 0);

            gl.glClearDepthf(1.0f);
            gl.glEnable(GL10.GL_DEPTH_TEST);
            gl.glDepthFunc(GL10.GL_LEQUAL);
            gl.glEnable(GL10.GL_LIGHT0);
            gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
            gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbientBuffer);
            gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuseBuffer);
            gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer);
    }

    public void onDrawFrame(GL10 gl) {
            gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
            gl.glLoadIdentity();
            gl.glEnable(GL10.GL_LIGHTING);

            GLU.gluLookAt(gl, eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0.0f, 1.0f, 0.0f);
    }

    public void onSurfaceChanged(GL10 gl, int width, int height) {
            if(height == 0) {
                height = 1;                         
            }

            gl.glViewport(0, 0, width, height);
            gl.glMatrixMode(GL10.GL_PROJECTION);
            gl.glLoadIdentity();
            GLU.gluPerspective(gl, 65.0f, (float)width / (float)height, 1.0f, 80.0f);
            gl.glMatrixMode(GL10.GL_MODELVIEW);
            gl.glLoadIdentity();
    }

所以问题是我怎样才能让它在我所在的每个地方都起作用,我希望有人可以帮助我,因为现在它看起来不太好(没有灯光很好,但我真的不想要夜景,特别是有纹理的地方)。有太阳:)。

编辑(现在是如何工作的):正如答案中那样,天空盒不再有法线,但在启用闪电后,我需要添加这一行到代码,现在它的工作方式就像魅力四射,处处天空明亮。

    gl.glLightModelf(GL10.GL_LIGHT_MODEL_TWO_SIDE, GL10.GL_TRUE);

Okay, I have made a "skybox" (it's actually 5 plane, because of the different textures). It's works fine, but there is a problem with the lightning. It's not my strongest point in OpenGL, so I will be not surprised if the answer is not so hard.

So that is my start position view. As you can see the front plane is bright, but the left, top, right are not really, and there is a border between them and the front.

http://img696.imageshack.us/img696/3673/light01.png

When I go to the absolute center (nearly) of the skybox then the border are not so visible (I guess at the absolute center there is no border.

http://img233.imageshack.us/img233/2949/light02.png

First I tried with one light at the posistion (0,0,0) with these settings, but nothing, I tried to change the ambient, the diffuse, but not really helps:

    private float[] lightAmbient = {0.5f, 0.5f, 0.5f, 1.0f};
    private float[] lightDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};
    private float[] lightPosition = {0.0f, 0.0f, 0.0f, 1.0f};

    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            gl.glEnable(GL10.GL_DITHER);
            gl.glEnable(GL10.GL_TEXTURE_2D);
            gl.glShadeModel(GL10.GL_SMOOTH);
            gl.glClearColor(0, 0, 0, 0);

            gl.glClearDepthf(1.0f);
            gl.glEnable(GL10.GL_DEPTH_TEST);
            gl.glDepthFunc(GL10.GL_LEQUAL);
            gl.glEnable(GL10.GL_LIGHT0);
            gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
            gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbientBuffer);
            gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuseBuffer);
            gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer);
    }

    public void onDrawFrame(GL10 gl) {
            gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
            gl.glLoadIdentity();
            gl.glEnable(GL10.GL_LIGHTING);

            GLU.gluLookAt(gl, eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0.0f, 1.0f, 0.0f);
    }

    public void onSurfaceChanged(GL10 gl, int width, int height) {
            if(height == 0) {
                height = 1;                         
            }

            gl.glViewport(0, 0, width, height);
            gl.glMatrixMode(GL10.GL_PROJECTION);
            gl.glLoadIdentity();
            GLU.gluPerspective(gl, 65.0f, (float)width / (float)height, 1.0f, 80.0f);
            gl.glMatrixMode(GL10.GL_MODELVIEW);
            gl.glLoadIdentity();
    }

So the question is how can I make this to work in every place where I am. I hope someone can help me, because now it's not really looking nice (without light is good, but I don't really want a night scene, ecspecially with a texture where there is the sun :).

EDIT (how it works now): as it was in the answer there are no normals for the skybox anymore, but after I have enabled lightning I was needed to add this line to the code, and now it works like a charm, and the sky is bright everywhere.

    gl.glLightModelf(GL10.GL_LIGHT_MODEL_TWO_SIDE, GL10.GL_TRUE);

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

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

发布评论

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

评论(1

少年亿悲伤 2024-12-18 12:21:22

答案确实不那么难;你根本不应该在你的天空盒上使用照明。

The answer is indeed not so hard; you simply shouldn't use lighting at all on your skybox.

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