简体   繁体   English

在原点跟随主光的鬼光

[英]Ghost light following main light at point of origin

I have a spotlight in my OpenGL project, the light currently shines down the -z axis like a ceiling light, towards the floor, which is just a big quad. 我在OpenGL项目中有一个聚光灯,当前该光像天花板灯一样沿-z轴照向地面,这只是一个大四边形。

I currently have a cube at the origin of the light, that follows the light around, so I can see exactly where the light is at all times. 目前,我在光源的原点有一个立方体,跟随着周围的光源,因此我可以随时准确地看到光源的位置。

My problem is that there is another brighter spotlight that follows the main light, it starts at the origin, or the bottom left corner of the floor. 我的问题是,有一个更亮的聚光灯跟随主光,从原点或地板的左下角开始。

I'd like to remove this white light, as I don't know what's causing it, or how to remove it. 我想删除此白光,因为我不知道是什么原因或如何删除它。

I have tried to play around with some of the variables and see their impact, but I've had little to no success. 我试图尝试一些变量并观察它们的影响,但是我几乎没有成功。

Any assistance would be greatly appreciated. 任何帮助将不胜感激。

The error: 错误:

错误

//ceiling light
GLfloat Light_Ambient[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat Light_Diffuse[] = { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat Light_Position[] = { Sun.X, Sun.Y, Sun.Z, 1.0f };
GLfloat Spot_Direction[] = { 0.0f, 0.0f, -1.0f };

//ambient
GLfloat Light_Ambient1[] = { 0.4f, 0.4f, 0.4f, 1.0f };
GLfloat Light_Diffuse1[] = { 1.0f, 1.0f, 1.0f, 0.0f };
GLfloat Light_Position1[] = { Sun.X, Sun.Y, Sun.Z, 1.0f };

//ceiling light
glLightfv(GL_LIGHT0, GL_AMBIENT, Light_Ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, Light_Diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, Light_Position);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 55);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, Spot_Direction);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 5);
glEnable(GL_LIGHT0);

//ambient
glLightfv(GL_LIGHT1, GL_AMBIENT, Light_Ambient1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, Light_Diffuse1);
glLightfv(GL_LIGHT1, GL_POSITION, Light_Position1);
glEnable(GL_LIGHT1);

I changed some things around and I seem to have solved it. 我改变了一些事情,似乎已经解决了。

//ceiling light
GLfloat Light_Ambient[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat Light_Diffuse[] = { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat Light_Position[] = { Sun.X, Sun.Y, Sun.Z, 1.0f };
GLfloat Spot_Direction[] = { 0.0f, 0.0f, -1.0f };

//ambient
GLfloat Light_Ambient1[] = { 0.6f, 0.6f, 0.6f, 1.0f };
GLfloat Light_Diffuse1[] = { 1.0f, 1.0f, 1.0f, 0.0f };
GLfloat Light_Position1[] = { 0, 0, 0, 0.0f };

//ceiling light
glLightfv(GL_LIGHT0, GL_AMBIENT, Light_Ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, Light_Diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, Light_Position);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 55);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, Spot_Direction);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 20);
glEnable(GL_LIGHT0);

//ambient
glLightfv(GL_LIGHT1, GL_AMBIENT, Light_Ambient1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, Light_Diffuse1);
glLightfv(GL_LIGHT1, GL_POSITION, Light_Position1);
glEnable(GL_LIGHT1);

UPDATE: 更新:

I'm returning to edit this months later simply because I feel that this answer may help a lot of people with OpenGL and this confusion with lights. 我几个月后将返回编辑仅仅是因为我觉得这个答案可能会帮助很多使用OpenGL以及灯光混淆的人。

If your lights are broken (like mine were) there's actually a good chance there's nothing wrong with your lights at all, but how you're rendering the world. 如果您的灯光坏了(就像我的一样),实际上很有可能您的灯光完全没有问题,但是您如何渲染世界。 It's worthwhile to remember that opengl looks a little like this: 值得记住的是,opengl看起来像这样:

https://imgur.com/a/saYxy https://imgur.com/a/saYxy

What I was actually doing wrong, as you can see from my initial question i was convinced that the Z was the Y and the Y was the Z, and vice versa, this broke all of my lighting calculations back then. 我实际上做错了,从最初的问题中可以看出,我坚信Z是Y,Y是Z,反之亦然,这打破了我当时的所有照明计算。 If your lights look like mine do, there's a good chance that you're confusing your axis, it isn't that hard to do this when moving from 2d to 3D opengl. 如果您的光源看起来像我的光源,那么很有可能会混淆轴,从2d到3D opengl进行转换并不难。

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

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