View Full Version : Lighting algorithm question

bobtedbob

05-11-2017, 09:29 AM

Hi

Looking here

http://www.lighthouse3d.com/tutorials/glsl-tutorial/point-lights/

I can see that to get the light direction you need to use the formula

"light direction = light position – vertex position"

The text following this says

"Before we can compute this vector we must apply the View Model matrix (m_viewModel in the shader) to the vertex position."

The vertex position would not be calculated from the viewModel matrix it would be calculated from the model matrix only.

This tutorial uses the model matrix as I would expect but then has other logic to work out the spec light

https://learnopengl.com/#!Lighting/Basic-Lighting

Can someone say if there is a typo in the first formula or if there is something basic that I haven;t understood which would explain it and also what the difference is between the two tutorials?

john_connor

05-11-2017, 11:07 AM

there are many way to lit your scene. i'm not sure what the "lighthouse" tutorial actually does, i think it's calculating light effect in "view space", not in "world space" (?)

imho, the easiest way to understand this topic is to do lighting in world space:

https://sites.google.com/site/john87connor/scene-light-material/3-directional-light

https://sites.google.com/site/john87connor/scene-light-material/3-2-point-light

https://sites.google.com/site/john87connor/scene-light-material/3-3-spot-light

there are different ways to "shade" your scene, that is different lighting models:

-- flat shading

-- phong shading

-- blinn shading

-- cel shading

-- fresnel shading

--- etc...

https://en.wikipedia.org/wiki/Shading

https://docs.blender.org/manual/en/dev/render/blender_render/materials/properties/diffuse_shaders.html

https://docs.blender.org/manual/en/dev/render/blender_render/materials/properties/specular_shaders.html

most of them consider light as a mix of 3 different parts:

-- ambient part

-- diffuse part

-- specular part

only diffuse and specular come from light sources, ambient has no source, it comes from "everywhere" (a kind of "cheat" to avoid completely dark (black) parts in your scene). diffuse and specular have to accumulated for each light source

GClements

05-12-2017, 03:27 PM

You can perform lighting calculations in any space, so long as

you are consistent, i.e. all positions and directions are in the same space, and

that space is affine to world space, i.e. none of the transformations have a projective component (this is why conventionally the projection matrix is separate from the model-view matrix). And it's easier if that space is orthogonal to world space (i.e. only rotations, translations and uniform scaling; no non-uniform scaling or shear); otherwise you need to take additional steps to preserve orthogonality of e.g. normal vectors.

The fixed-function pipeline uses eye space. World space works if you have such a thing. Object space can be made to work but if objects have distinct transformations, then you need to transform the eye and light vectors into each object's space, which is inconvenient.

Dark Photon

05-13-2017, 08:27 AM

Re lighting calculations and which space you choose...

One other point to consider is whether your WORLD-space is so large that you need double-precision to represent it to sufficient accuracy.

If so, and if you are doing lighting calculations with point light sources (which have you subtracting points in your "lighting space"), you may very well want to choose another space besides WORLD-space for your lighting calculations as single-precision floats likely won't provide enough precision (recall: in normal shaders, your positions are going to be represented with single-precision floats).

On the other hand, single-precision floats provide plenty of precision for EYE-space lighting math. This is one reason why choosing EYE-space for your lighting calculations is a reasonable choice.

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.