Forum > OpenGL

Lighting moving with model and want it fixed position

(1/2) > >>

ranny:
Hi,

I was posting elsewhere in this forum on a clipboard problem and it was turning into a OpenGL discussion so I am starting a new subject here.

I am really new to OpenGl and have had some excellent advice on this forum.  But I have a little problem...

I am drawing a function that is displayed with quads with a colour gradient.  All is well until I go to add lighting.  When I add the lighting direction and type etc., the faces of the quads are lit, maybe not quite as I expected, but also as I rotate the model the lit faces move with the model when I want the direction of lighting to be fixed.  On advice from others I tried to ensure that lighting is fixed before any other transformations and is called only once, but it doesn't seem to make any difference.

Any advice please?

SymbolicFrank:
How does your shader(s) look like and how do you supply the inputs (calculated value, point, gradient, texture)?

ChrisR:
Here are two Lazarus OpenGL mesh viewers that have the light position relative to the viewer:
 https://github.com/neurolabusc/plyview
 https://github.com/neurolabusc/Metal-Demos/tree/master/mesh
They are very similar, but the latter can also be compiled for Metal on MacOS (and therefore you will have to use the package inspector to remove the Metal package when you load the project with Windows or Linux).

The shader is here
  https://github.com/neurolabusc/Metal-Demos/blob/master/mesh/Resources/shader/Phong.glsl
 Lighting uses the viewing direction (vV) and the surface normal:
    vV = -vec3(ModelViewMatrix*vec4(Vert,1.0))
    vN = normalize((NormalMatrix * vec4(Norm,1.0)).xyz);

ranny:
Thanks, I cannot get github on my works laptop and I am far from home at the moment but will look at the weekend.

I did say I was new to this (!) so this is what I do...

Make polygons in clockwise order, establish normals using dot product/cross product and normalise, use one colour for all polygons, do all this in one begin/end quad block.

Lighting is set in an initialisation procedure called once.

Rotations and translations carried out in a OpenGL.paint event.

Am I creating the normals in the wrong place?

See attached plot, I am trying to get a better distribution of colour from light to dark that is from a fixed light source.

Thanks for any help.   

wp:
Looks correct. But the devil hides in the details. For giving better help I ask you to provide a simple compilable project which shows the issue (*.pas, *.lfm, *.lpr and *.lpi files in a shared zip which you upload in section "Attachment and other options" of this site. No exe, ppi or other compiler-generated files in the zip, please).

Interestingly I have the same issue in my own 3d-chart project (https://github.com/wp-xyz/OpenGLChart). Because every data point sphere, but not the calculated surfece, behaves correctly with respect to lighting I think that the issue is somewhere related to calculation of normals.

As for the contrast between dark and light: Did you change the position of the light? Did you play with the properties of the light source and, if you don't use COLOR_MATERIAL, of the surface (ambient, diffuse, specular)?

Navigation

[0] Message Index

[#] Next page

Go to full version