PacktPublishing / PacktPublishing/Cpp-Game-Animation-Programming-Second-Edition

Light calculations

Open
#37 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
146
Forks
28
PR merge metrics
No merged PRs in 30d

Description

As you requested, I'm opening an issue. Chapter 8 handles lighting strangely. In the gltf.vert shader, the normal is taken in local space (usually it is multiplied by the transposed and inverted model matrix, i.e., translated into world space), which is usually inconvenient for calculating lighting in a pixel shader. Furthermore, the book doesn't explain why the gltf.frag shader uses the cosine for shading (it seems to be Lambert's cosine law). It seems like a bug that the light direction is specified as the light source's position (or perhaps it's not normalized direction). Also, remember that the normal is in local space. It looks like a direction light source is used here(it has no position, only direction). And if this is a point light source, then the world point position (or local space position) must also be passed to the pixel shader(or gl_FragCoord and depth), and then the light direction vector is calculated as light_source.position - point_pos. Of course, I could be wrong somewhere and maybe I didn't notice something.

https://github.com/PacktPublishing/Cpp-Game-Animation-Programming-Second-Edition/blob/18a135db9e0a50659a9322b7b6c512d883e21a59/chapter08/02_vulkan_gltf_load/shader/gltf.vert#L16

https://github.com/PacktPublishing/Cpp-Game-Animation-Programming-Second-Edition/blob/18a135db9e0a50659a9322b7b6c512d883e21a59/chapter08/02_vulkan_gltf_load/shader/gltf.frag#L23

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with chapter08/02_vulkan_gltf_load/shader/gltf.vert at line 16 and shader/gltf.frag at line 23, then trace how normals, light values, and positions are supplied. Resolve the coordinate-space and light-model questions raised in the issue, and confirm the chapter's shader behavior is consistent and explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.