crognar
crognar

Reputation: 65

OpenGL Lighting on a polygon

I'm writing a very small game, in this game the player is carrying a flashlight.

The world the game takes place in is a small house.

The problem is that my walls are made by drawing polygons, one polygon is one wall. So when I shine my light on the wall it won't light up, only when the light hits one of the vertices do I see some light and only that one vertex gets lit up.

Is there any way to make the middle of this polygon affected by light even if there's no defined vertex there?

I also tested this with a positional light, and that also only affects the vertices.

Upvotes: 0

Views: 887

Answers (1)

derhass
derhass

Reputation: 45322

What you see here is Gouraud shading, or just per vertex lighting. This is what the fixed function pipleline of OpenGL implements. However, nobody is using that in this millenium. What you ask for is Phong shading, or per pixel/per fragment lighting. In OpenGL, this means you have to use the programmable pipeline and have to write your own shaders. But you should be doing that anyway, as the fixed function pipeline is declared deprecated since GL3, and actually removed from modern core profiles of OpenGL.

So what I suggest you should do is learning modern OpenGL, maybe by follwoing some tutorials:

The first one also cover lighting topics in general and per fragment lighting (e.g. here), but you should be aware that these are a bit more advanced topics, and it will take some time for a beginnger to learn all the basics first.

Upvotes: 2

Related Questions