Alina's picture

spot light

Project:The Open Toolkit library
Category:support request

I want to have a light similar with a street lamp. Please help. Thanks !


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


It's difficult to tell what the problem is without some code. What are the light parameters?

A screenshot would also help identify the cause of the issue.

One potential problem is that the lighting equations built into OpenGL need relatively well-tesselated geometry to function. For example, if the street consists of only two triangles, the whole street will be lit by the street light, as the equations are only evaluated at the triangle vertices.

Alina's picture


I attach a screen shot. I disable the textures, the light color is red and it is placed inside the lamp. I think I have to use per pixel points lights, but I don't know how.

1.PNG112.2 KB
Alina's picture


I attach a new file with the result that I want to obtain. (light only in the selected areas).

whatIwant.PNG114.22 KB
the Fiddler's picture


Ok, the screenshot looks definitely wrong. The road receives no light from the lamp, which either means it has incorrect normals or that its tesselation is too low.

Is it possible to increase the tesselation of the road? If not, as far as I know per-pixel lighting is the only solution.

Alina's picture


Hello again ! The road and the building is built in 3D studio Max and each separate object is exported into .txt format(points, polygons, normals, texture coordinates). The road has only 2 polygons in order to have a minimum number of polygons and increase the speed. I'll try per-pixel lighting, but I have any idea how I could do this. I found this tutorial but there are few methods and variables that I can't understand. Have you know another tutorials about per-pixel lighting ? Thanks !

Inertia's picture


I kinda liked typhoon lab's shading language course (5 chapters), if you are looking more for a c&p solution take a look here.

But imho you want a huge point light originating from the lamp, not a spotlight. A spotlight pointing downwards would not illuminate the tree next to the lamp.

the Fiddler's picture


GLSL has an initial learning curve, but the results are worth it once you get it working. Plus, it can simplify OpenGL code a lot, if you code with GLSL in mind.

OpenTK comes with a simple GLSL example that could help you get started: SimpleGLSL.cs.

A quick overview:

  1. Create the vertex and fragment shaders (you don't need to provide a vertex shader for per pixel lighting, but some drivers may complain). This is done in the CreateShaders() method of the SimpleGLSL example.
  2. Call GL.UseProgram(id) to render using your new shader and GL.UseShader(0) to revert back to disable the shader.
  3. Call GL.ActiveTexture and GL.Uniform1 to attach all necessary textures to the shader.
  4. Emit a draw call as usually (VBO, display list or even immediate mode).

In other words, the main change is that you have to add calls to UseProgram, ActiveTexture and Uniform to your drawing code.

the Fiddler's picture


Status:open» closed

Closing issue after a month with no activity.