Skip to content

Commit

Permalink
Internal: Moving lighting to outside of vertex loop.
Browse files Browse the repository at this point in the history
FIX: Node.HierarchyAsString() previously incorrectly set the prefix; I also added more node differentiations (AMB for ambient light, POINT for point lights, etc).
Updating lighting example.
  • Loading branch information
SolarLune committed Jun 19, 2022
1 parent 8e5f36b commit 5a65bc4
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 107 deletions.
28 changes: 18 additions & 10 deletions camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,24 @@ func (camera *Camera) Render(scene *Scene, models ...*Model) {
depthVertexList[vertexListIndex+2].DstX = float32(p2[0])
depthVertexList[vertexListIndex+2].DstY = float32(p2[1])

if lighting {

t := time.Now()

for i := range lightColors {
lightColors[i] = 0
}

for _, light := range lights {
for i, v := range light.Light(tri) {
lightColors[i] += v
}
}

camera.DebugInfo.lightTime += time.Since(t)

}

for i, vert := range tri.Vertices {

// We set the UVs back here because we might need to use them if the material has clip alpha enabled.
Expand Down Expand Up @@ -928,16 +946,6 @@ func (camera *Camera) Render(scene *Scene, models ...*Model) {

t := time.Now()

for i := range lightColors {
lightColors[i] = 0
}

for _, light := range lights {
for i, v := range light.Light(tri) {
lightColors[i] += v
}
}

colorVertexList[vertexListIndex+i].ColorR *= lightColors[i*3]
colorVertexList[vertexListIndex+i].ColorG *= lightColors[i*3+1]
colorVertexList[vertexListIndex+i].ColorB *= lightColors[i*3+2]
Expand Down
Binary file modified examples/lighting/lighting.blend
Binary file not shown.
Loading

0 comments on commit 5a65bc4

Please sign in to comment.