diff options
Diffstat (limited to 'Resources')
7 files changed, 109 insertions, 5 deletions
diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua new file mode 100644 index 0000000..75e6f18 --- /dev/null +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua @@ -0,0 +1,8 @@ +local m = GameLab.Engine.Rendering or {} +GameLab.Engine.Rendering = m + +m.LoadTexture = function(path) + +end + +return m
\ No newline at end of file diff --git a/Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua b/Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua index 5b1b140..22869e5 100644 --- a/Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua +++ b/Resources/Libraries/GameLab/Editor/GUI/EditorWindow.lua @@ -1,8 +1,8 @@ local EditorWindow = GameLab.Class("EditorWindow", "GameLab.Editor.GUI")
EditorWindow.Ctor = function(self, title)
- self.title = title
- self.guiWindow = nil
+ self.title = title -- 编辑器名称
+ self.guiWindow = nil -- 绑定的GUIWindow
end
EditorWindow.OnGUI = function(self)
diff --git a/Resources/Libraries/GameLab/Editor/GUI/Functions.lua b/Resources/Libraries/GameLab/Editor/GUI/Functions.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Resources/Libraries/GameLab/Editor/GUI/Functions.lua diff --git a/Resources/Libraries/GameLab/Editor/GUI/init.lua b/Resources/Libraries/GameLab/Editor/GUI/init.lua index a9c6ac9..e1b4576 100644 --- a/Resources/Libraries/GameLab/Editor/GUI/init.lua +++ b/Resources/Libraries/GameLab/Editor/GUI/init.lua @@ -5,6 +5,6 @@ local require = GameLab.require(...) m.EditorWindow = require("EditorWindow")
-
+require("Functions")
return m
\ No newline at end of file diff --git a/Resources/Libraries/GameLab/Editor/Resource/ResourceManager b/Resources/Libraries/GameLab/Editor/Resource/ResourceManager new file mode 100644 index 0000000..b28b04f --- /dev/null +++ b/Resources/Libraries/GameLab/Editor/Resource/ResourceManager @@ -0,0 +1,3 @@ + + + diff --git a/Resources/Scripts/Editor/AssetBrowser.lua b/Resources/Scripts/Editor/AssetBrowser.lua index 07cead4..ee6de6a 100644 --- a/Resources/Scripts/Editor/AssetBrowser.lua +++ b/Resources/Scripts/Editor/AssetBrowser.lua @@ -3,14 +3,17 @@ local AssetBrowser = GameLab.Editor.GUI.EditorWindow.Extend("AssetBrowser", "Gam AssetBrowser.Ctor = function(self)
self.base.Ctor(self, "AssetBrowser")
+
end
AssetBrowser.OnGUI = function(self)
- Debug.Log("AssetBrowser.OnGUI()" .. self.title)
+
+
end
AssetBrowser.OnFocus = function(self)
- Debug.Log("AssetBrowser.OnFocus()" .. self.title)
+
+
end
return AssetBrowser
\ No newline at end of file diff --git a/Resources/Scripts/EditorApplication.lua b/Resources/Scripts/EditorApplication.lua index 8a175db..92bc5b9 100644 --- a/Resources/Scripts/EditorApplication.lua +++ b/Resources/Scripts/EditorApplication.lua @@ -39,6 +39,96 @@ local V4 = GameLab.Engine.Math.Vector4.Extend("V4", "GameLab.Engine.Math") Debug.Log(EditorWindowManager.name) +local vert = [[ + #version 330 core + layout (location = 0) in vec3 aPos; + layout (location = 1) in vec3 aNormal; + layout (location = 2) in vec2 aTexCoords; + layout (location = 3) in vec3 aTangent; + layout (location = 4) in vec3 aBitangent; + + out VS_OUT { + vec3 FragPos; + vec2 TexCoords; + vec3 TangentLightPos; + vec3 TangentViewPos; + vec3 TangentFragPos; + } vs_out; + + uniform mat4 projection; + uniform mat4 view; + uniform mat4 model; + + uniform vec3 lightPos; + uniform vec3 viewPos; + + void main() + { + vs_out.FragPos = vec3(model * vec4(aPos, 1.0)); + vs_out.TexCoords = aTexCoords; + + mat3 normalMatrix = transpose(inverse(mat3(model))); + vec3 T = normalize(normalMatrix * aTangent); + vec3 N = normalize(normalMatrix * aNormal); + T = normalize(T - dot(T, N) * N); + vec3 B = cross(N, T); + + mat3 TBN = transpose(mat3(T, B, N)); + vs_out.TangentLightPos = TBN * lightPos; + vs_out.TangentViewPos = TBN * viewPos; + vs_out.TangentFragPos = TBN * vs_out.FragPos; + + gl_Position = projection * view * model * vec4(aPos, 1.0); + } +]] + +local frag = [[ + #version 330 core + out vec4 FragColor; + + in VS_OUT { + vec3 FragPos; + vec2 TexCoords; + vec3 TangentLightPos; + vec3 TangentViewPos; + vec3 TangentFragPos; + } fs_in; + + uniform sampler2D diffuseMap; + uniform sampler2D normalMap; + + uniform vec3 lightPos; + uniform vec3 viewPos; + + void main() + { + // obtain normal from normal map in range [0,1] + vec3 normal = texture(normalMap, fs_in.TexCoords).rgb; + // transform normal vector to range [-1,1] + normal = normalize(normal * 2.0 - 1.0); // this normal is in tangent space + + // get diffuse color + vec3 color = texture(diffuseMap, fs_in.TexCoords).rgb; + // ambient + vec3 ambient = 0.1 * color; + // diffuse + vec3 lightDir = normalize(fs_in.TangentLightPos - fs_in.TangentFragPos); + float diff = max(dot(lightDir, normal), 0.0); + vec3 diffuse = diff * color; + // specular + vec3 viewDir = normalize(fs_in.TangentViewPos - fs_in.TangentFragPos); + vec3 reflectDir = reflect(-lightDir, normal); + vec3 halfwayDir = normalize(lightDir + viewDir); + float spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0); + + vec3 specular = vec3(0.2) * spec; + FragColor = vec4(ambient + diffuse + specular, 1.0); + } +]] + +local shader = GameLab.Engine.Rendering.Shader.New(vert, frag) +Debug.Log("shader is " .. inspect(shader:IsValid())) + while true do app:PullMessage() |