summaryrefslogtreecommitdiff
path: root/Resources/Scripts/EditorApplication.lua
blob: 92bc5b992f587c4fa092d9128c91382b91f7e5c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
local json = require "LiteJson.json"
local inspect = require "inspect"
local AssetBrowser = require "./Scripts/Editor/AssetBrowser"
local EditorWindowManager = require "./Scripts/EditorGUI/EditorWindowManager"

local Debug = GameLab.Debug
local GUI = GameLab.Editor.GUI

local app = GameLab.Editor.EditorApplication.New()

if app == nil then 
	Debug.LogError("app is nil")
end 

local mainWindow = GUI.ContainerWindow.New({400, 400, 800, 500}, GUI.EShowMode.MainWindow, {100, 100}, {700, 700}) 
mainWindow:SetTitle("GameLab")
mainWindow:SetIcon("./Icon/GameLab.ico")

app:SetMainWindow(mainWindow)

local guiWindow = GUI.GUIWindow.New() 
guiWindow:SetContainerWindow(mainWindow)
guiWindow:SetPosition({0,0, 500, 400})

collectgarbage()

Debug.Log(GameLab.Path.GetRootDirectory())

Debug.Log(inspect{foo=1,2,3,4})

local wnd = AssetBrowser.New() 
Debug.Log(inspect(mainWindow._type))
guiWindow:SetInstance(wnd)

local v = GameLab.Engine.Math.Vector4.New(1,2,3,4)
Debug.Log(inspect(v))

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()

end