diff --git a/camera.go b/camera.go index b594637..fc83558 100644 --- a/camera.go +++ b/camera.go @@ -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. @@ -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] diff --git a/examples/lighting/lighting.blend b/examples/lighting/lighting.blend index bd75912..7edd416 100644 Binary files a/examples/lighting/lighting.blend and b/examples/lighting/lighting.blend differ diff --git a/examples/lighting/lighting.gltf b/examples/lighting/lighting.gltf index 427b570..b994b19 100644 --- a/examples/lighting/lighting.gltf +++ b/examples/lighting/lighting.gltf @@ -1,6 +1,6 @@ { "asset" : { - "generator" : "Khronos glTF Blender I/O v1.8.19", + "generator" : "Khronos glTF Blender I/O v3.2.40", "version" : "2.0" }, "extensionsUsed" : [ @@ -101,7 +101,9 @@ }, "name" : "Scene", "nodes" : [ + 1, 2, + 3, 4, 5, 6, @@ -112,51 +114,53 @@ 11, 12, 13, + 14, 15, - 17, - 19, - 20, - 21, - 22 + 16, + 17 ] } ], "nodes" : [ { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 4.076244831085205, + 1.0054539442062378, + 5.903861999511719 + ] + }, "mesh" : 0, "name" : "PointlightVisibility", "rotation" : [ - -0.16907572746276855, - -0.7558803558349609, - 0.27217134833335876, - 0.570947527885437 + 0.28416627645492554, + -0.7269423007965088, + -0.34203392267227173, + 0.5232755541801453 ] }, { + "children" : [ + 0 + ], "extensions" : { "KHR_lights_punctual" : { "light" : 0 } }, - "name" : "Point light_Orientation", - "rotation" : [ - -0.7071067690849304, - 0, - 0, - 0.7071067690849304 - ] - }, - { - "children" : [ - 0, - 1 - ], + "extras" : { + "t3dOriginalLocalPosition__" : [ + 0.5288939476013184, + -3.7577967643737793, + 0.9038619995117188 + ] + }, "name" : "Point light", "rotation" : [ - 0.16907575726509094, - 0.7558803558349609, - -0.27217137813568115, - 0.570947527885437 + -0.2841663062572479, + 0.7269423604011536, + 0.34203392267227173, + 0.5232754349708557 ], "translation" : [ 4.076245307922363, @@ -166,24 +170,19 @@ }, { "camera" : 0, - "name" : "Camera_Orientation", - "rotation" : [ - -0.7071067690849304, - 0, - 0, - 0.7071067690849304 - ] - }, - { - "children" : [ - 3 - ], + "extras" : { + "t3dOriginalLocalPosition__" : [ + 7.358891487121582, + -6.925790786743164, + 4.958309173583984 + ] + }, "name" : "Camera", "rotation" : [ - 0.483536034822464, - 0.33687159419059753, - -0.20870360732078552, - 0.7804827094078064 + -0.20997299253940582, + 0.3857799470424652, + 0.09062844514846802, + 0.8937962055206299 ], "translation" : [ 7.358891487121582, @@ -192,10 +191,24 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 0.0, + 0.0, + 0.0 + ] + }, "mesh" : 1, "name" : "Plane" }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 4.0, + 6.0, + 1.0 + ] + }, "mesh" : 2, "name" : "Cube", "translation" : [ @@ -205,6 +218,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + -4.0, + 6.0, + 1.0 + ] + }, "mesh" : 2, "name" : "Cube.001", "translation" : [ @@ -214,6 +234,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + -4.0, + -6.0, + 1.0 + ] + }, "mesh" : 2, "name" : "Cube.002", "translation" : [ @@ -223,6 +250,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 4.0, + -6.0, + 1.0 + ] + }, "mesh" : 2, "name" : "Cube.003", "translation" : [ @@ -232,6 +266,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 6.0, + -4.0, + 1.0 + ] + }, "mesh" : 2, "name" : "Cube.004", "translation" : [ @@ -241,6 +282,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 6.0, + 4.0, + 1.0 + ] + }, "mesh" : 2, "name" : "Cube.005", "translation" : [ @@ -250,6 +298,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + -6.0, + 4.0, + 1.0 + ] + }, "mesh" : 2, "name" : "Cube.006", "translation" : [ @@ -259,6 +314,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + -6.0, + -4.0, + 1.0 + ] + }, "mesh" : 2, "name" : "Cube.007", "translation" : [ @@ -273,24 +335,19 @@ "light" : 1 } }, - "name" : "Light.001_Orientation", - "rotation" : [ - -0.7071067690849304, - 0, - 0, - 0.7071067690849304 - ] - }, - { - "children" : [ - 14 - ], + "extras" : { + "t3dOriginalLocalPosition__" : [ + 1.0762453079223633, + 3.0054540634155273, + 7.903861999511719 + ] + }, "name" : "Light.001", "rotation" : [ - 0, - -0.11334089189767838, - -0.26444491744041443, - 0.9577174782752991 + -0.677208662033081, + 0.10684666782617569, + -0.2671349048614502, + 0.6772083640098572 ], "translation" : [ 1.0762453079223633, @@ -304,24 +361,19 @@ "light" : 2 } }, - "name" : "Point light.001_Orientation", - "rotation" : [ - -0.7071067690849304, - 0, - 0, - 0.7071067690849304 - ] - }, - { - "children" : [ - 16 - ], + "extras" : { + "t3dOriginalLocalPosition__" : [ + -8.915050506591797, + 8.789344787597656, + 1.2601757049560547 + ] + }, "name" : "Point light.001", "rotation" : [ - 0.16907575726509094, - 0.7558803558349609, - -0.27217137813568115, - 0.570947527885437 + -0.2841663062572479, + 0.7269423604011536, + 0.34203392267227173, + 0.5232754349708557 ], "translation" : [ -8.915050506591797, @@ -335,24 +387,19 @@ "light" : 3 } }, - "name" : "Point light.002_Orientation", - "rotation" : [ - -0.7071067690849304, - 0, - 0, - 0.7071067690849304 - ] - }, - { - "children" : [ - 18 - ], + "extras" : { + "t3dOriginalLocalPosition__" : [ + 16.084949493408203, + -1.2106552124023438, + 1.2601757049560547 + ] + }, "name" : "Point light.002", "rotation" : [ - 0.16907575726509094, - 0.7558803558349609, - -0.27217137813568115, - 0.570947527885437 + -0.2841663062572479, + 0.7269423604011536, + 0.34203392267227173, + 0.5232754349708557 ], "translation" : [ 16.084949493408203, @@ -361,6 +408,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 4.076245307922363, + 1.0054539442062378, + 5.903861999511719 + ] + }, "mesh" : 3, "name" : "Sphere", "translation" : [ @@ -370,6 +424,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 13.076245307922363, + 8.005454063415527, + 3.9038619995117188 + ] + }, "mesh" : 4, "name" : "Plane.001", "translation" : [ @@ -379,6 +440,13 @@ ] }, { + "extras" : { + "t3dOriginalLocalPosition__" : [ + 0.0, + 0.0, + 6.0 + ] + }, "mesh" : 2, "name" : "Spin", "translation" : [ @@ -406,7 +474,7 @@ { "sampler" : 0, "target" : { - "node" : 2, + "node" : 1, "path" : "translation" } } diff --git a/examples/lighting/main.go b/examples/lighting/main.go index da82ef0..7fe184f 100644 --- a/examples/lighting/main.go +++ b/examples/lighting/main.go @@ -93,7 +93,7 @@ func (g *Game) Update() error { spin := g.Scene.Root.Get("Spin").(*tetra3d.Model) spin.Rotate(0, 1, 0, 0.025) - light := g.Scene.Root.Get("Point light").(*tetra3d.Node) + light := g.Scene.Root.Get("Point light").(*tetra3d.PointLight) light.AnimationPlayer().Play(g.Library.Animations["LightAction"]) light.AnimationPlayer().Update(1.0 / 60.0) diff --git a/node.go b/node.go index 48b2c36..683f6e6 100644 --- a/node.go +++ b/node.go @@ -700,14 +700,18 @@ func (node *Node) HierarchyAsString() string { printNode = func(node INode, level int) string { - prefix := "+" + prefix := "" nodeType := node.Type() if nodeType.Is(NodeTypeModel) { - nodeType = "MODEL" - } else if nodeType.Is(NodeTypeLight) { - nodeType = "LIGHT" + prefix = "MODEL" + } else if nodeType.Is(NodeTypeAmbientLight) { + prefix = "AMB" + } else if nodeType.Is(NodeTypeDirectionalLight) { + prefix = "DIR" + } else if nodeType.Is(NodeTypePointLight) { + prefix = "POINT" } else if nodeType.Is(NodeTypeCamera) { prefix = "CAM" } else if nodeType.Is(NodeTypeBoundingSphere) { @@ -720,6 +724,8 @@ func (node *Node) HierarchyAsString() string { prefix = "TRI" } else if nodeType.Is(NodeTypePath) { prefix = "CURVE" + } else { + prefix = "NODE" } str := ""