| 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 | #include <gui/newshader.hh> |
| 38 | #include <database/locale.hh> |
| 39 | #include <util/vector.hh> |
| 40 | #include <imgui.h> |
| 41 | |
| 42 | namespace gui { |
| 43 | db::ShaderData NewShader::Make(ShaderType type) { |
| 44 | db::ShaderData newShader = {}; |
| 45 | auto curLang = m_Info->i18n->GetCurrentLanguage().code; |
| 46 | newShader.id = 0; |
| 47 | if (curLang == "ja_JP") newShader.name = "(名無し)"; |
| 48 | else newShader.name = "(Unnamed)"; |
| 49 | newShader.clearColor.rgba = { 0.f, 0.f, 0.f, 1.f }; |
| 50 | newShader.description = ""; |
| 51 | |
| 52 | newShader.vertexShader.id = 0; |
| 53 | newShader.vertexShader.type = db::ShaderCodeType::GlslVertex; |
| 54 | newShader.vertexShader.filename = ""; |
| 55 | |
| 56 | newShader.fragmentShader.id = 0; |
| 57 | newShader.fragmentShader.type = db::ShaderCodeType::GlslFragment; |
| 58 | newShader.fragmentShader.filename = ""; |
| 59 | |
| 60 | newShader.luaCode.id = 0; |
| 61 | newShader.luaCode.type = db::ShaderCodeType::Lua; |
| 62 | newShader.luaCode.filename = ""; |
| 63 | |
| 64 | if (type == ShaderType::Scene) { |
| 65 | newShader.vertexShader.code = getDefaultVertScene(); |
| 66 | newShader.fragmentShader.code = getDefaultFragScene(); |
| 67 | newShader.luaCode.code = getDefaultLuaScene(); |
| 68 | } else if (type == ShaderType::Simple3D) { |
| 69 | newShader.vertexShader.code = getDefaultVert3D(); |
| 70 | newShader.fragmentShader.code = getDefaultFrag3D(); |
| 71 | newShader.luaCode.code = getDefaultLua3D(); |
| 72 | } else { |
| 73 | newShader.vertexShader.code = getDefaultVert2D(); |
| 74 | newShader.fragmentShader.code = getDefaultFrag2D(); |
| 75 | newShader.luaCode.code = getDefaultLua2D(); |
| 76 | } |
| 77 | |
| 78 | return newShader; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | |
| 83 | string NewShader::getDefaultVert2D() { |
| 84 | return R"(#version 460 core |
| 85 | |
| 86 | layout(location = 0) in vec2 aPosition; |
| 87 | layout(location = 1) in vec3 aColor; |
| 88 | out vec3 vColor; |
| 89 | |
| 90 | void main() { |
| 91 | vColor = aColor; |
| 92 | gl_Position = vec4(aPosition, 0.0, 1.0); |
| 93 | })"; |
| 94 | } |
| 95 | |
| 96 | string NewShader::getDefaultFrag2D() { |
| 97 | return R"(#version 460 core |
| 98 | |
| 99 | in vec3 vColor; |
| 100 | out vec4 out_color; |
| 101 | |
| 102 | void main() { |
| 103 | out_color = vec4(vColor, 1.0); |
| 104 | })"; |
| 105 | } |
| 106 | |
| 107 | string NewShader::getDefaultLua2D() { |
| 108 | return R"(local stride = le.sizeof("vec2") + le.sizeof("vec3") |
| 109 | |
| 110 | local mesh = { |
| 111 | vertices = { |
| 112 | 0, .5, 1, 0, 0, |
| 113 | -.5, -.5, 0, 1, 0, |
| 114 | .5, -.5, 0, 0, 1 |
| 115 | }, |
| 116 | indices = { 0, 1, 2 }, |
| 117 | |
| 118 | attributes = { |
| 119 | { |
| 120 | location = 0, |
| 121 | size = 2, |
| 122 | stride = stride, |
| 123 | offset = 0 |
| 124 | }, -- position |
| 125 | { |
| 126 | location = 1, |
| 127 | size = 3, |
| 128 | stride = stride, |
| 129 | offset = le.sizeof("vec2") |
| 130 | } -- uv |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | le.gfx.add_mesh(mesh) |
| 135 | le.gfx.set_position(0, 0, 0, 0) |
| 136 | |
| 137 | function init() |
| 138 | end |
| 139 | |
| 140 | function update() |
| 141 | end)"; |
| 142 | } |
| 143 | |
| 144 | string NewShader::getDefaultVert3D() { |
| 145 | return R"(#version 460 core |
| 146 | |
| 147 | layout(location = 0) in vec3 aPosition; |
| 148 | layout(location = 1) in vec3 aColor; |
| 149 | |
| 150 | out vec3 vColor; |
| 151 | |
| 152 | uniform mat4 uModel; |
| 153 | uniform mat4 uView; |
| 154 | uniform mat4 uProjection; |
| 155 | |
| 156 | void main() { |
| 157 | vColor = aColor; |
| 158 | gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0); |
| 159 | })"; |
| 160 | } |
| 161 | |
| 162 | string NewShader::getDefaultFrag3D() { |
| 163 | return R"(#version 460 core |
| 164 | |
| 165 | in vec3 vColor; |
| 166 | out vec4 out_color; |
| 167 | |
| 168 | void main() { |
| 169 | out_color = vec4(vColor, 1.0); |
| 170 | })"; |
| 171 | } |
| 172 | |
| 173 | string NewShader::getDefaultLua3D() { |
| 174 | return R"(local offset = le.sizeof("vec3") |
| 175 | local stride = offset * 2 |
| 176 | |
| 177 | local mesh = { |
| 178 | vertices = { |
| 179 | -- position -- uv |
| 180 | -- mae |
| 181 | -0.5, -0.5, -0.5, 1,0,0, |
| 182 | 0.5, -0.5, -0.5, 0,1,0, |
| 183 | 0.5, 0.5, -0.5, 0,0,1, |
| 184 | -0.5, 0.5, -0.5, 1,1,0, |
| 185 | -- usiro |
| 186 | -0.5, -0.5, 0.5, 1,0,1, |
| 187 | 0.5, -0.5, 0.5, 0,1,1, |
| 188 | 0.5, 0.5, 0.5, 1,1,1, |
| 189 | -0.5, 0.5, 0.5, 1,0,1, |
| 190 | }, |
| 191 | |
| 192 | indices = { |
| 193 | 0,1,2, 2,3,0, -- mae |
| 194 | 1,5,6, 6,2,1, -- migi |
| 195 | 5,4,7, 7,6,5, -- usiro |
| 196 | 4,0,3, 3,7,4, -- hidari |
| 197 | 3,2,6, 6,7,3, -- ue |
| 198 | 4,5,1, 1,0,4 -- sita |
| 199 | }, |
| 200 | |
| 201 | attributes = { |
| 202 | { location = 0, size = 3, stride = stride, offset = 0 }, |
| 203 | { location = 1, size = 3, stride = stride, offset = offset } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | le.gfx.add_mesh(mesh) |
| 208 | le.gfx.set_position(0, 0, 0, 1) |
| 209 | le.gfx.add_mesh(mesh) |
| 210 | le.gfx.set_position(1, -8, -2, -11) |
| 211 | le.gfx.add_mesh(mesh) |
| 212 | le.gfx.set_position(2, 8, -2, -11) |
| 213 | |
| 214 | function init() |
| 215 | end |
| 216 | |
| 217 | function update() |
| 218 | local t = le.sys.get_time() |
| 219 | |
| 220 | le.gfx.set_rotation(0, t*0.7, t*1.0, t*0.4) |
| 221 | le.gfx.set_rotation(1, t*0.2, t*0.8, t*1.4) |
| 222 | le.gfx.set_rotation(2, t*0.4, t*0.3, t*0.8) |
| 223 | |
| 224 | local reso = le.sys.get_resolution() |
| 225 | local aspect = reso.x / reso.y |
| 226 | |
| 227 | local view = le.math.look_at( |
| 228 | 0, 0, 4, -- eye |
| 229 | 0, 0, 0, -- target |
| 230 | 0, 1, 0 -- up |
| 231 | ) |
| 232 | |
| 233 | local projection = le.math.perspective( |
| 234 | 45.0, |
| 235 | aspect, |
| 236 | 0.1, |
| 237 | 100.0 |
| 238 | ) |
| 239 | |
| 240 | le.gfx.set_uniform_mat4("uView", view) |
| 241 | le.gfx.set_uniform_mat4("uProjection", projection) |
| 242 | end)"; |
| 243 | } |
| 244 | |
| 245 | string NewShader::getDefaultVertScene() { |
| 246 | return R"(#version 460 core |
| 247 | |
| 248 | layout(location = 0) in vec3 aPosition; |
| 249 | layout(location = 1) in vec3 aNormal; |
| 250 | layout(location = 2) in vec3 aColor; |
| 251 | |
| 252 | out vec3 vFragPos; |
| 253 | out vec3 vNormal; |
| 254 | out vec3 vColor; |
| 255 | out vec4 vFragPosLightSpace; |
| 256 | |
| 257 | uniform mat4 uModel; |
| 258 | uniform mat4 uView; |
| 259 | uniform mat4 uProjection; |
| 260 | uniform mat4 uLightSpace; |
| 261 | |
| 262 | void main() { |
| 263 | vec4 worldPos = uModel * vec4(aPosition, 1.0); |
| 264 | |
| 265 | vFragPos = worldPos.xyz; |
| 266 | vNormal = mat3(transpose(inverse(uModel))) * aNormal; |
| 267 | vColor = aColor; |
| 268 | vFragPosLightSpace = uLightSpace * worldPos; |
| 269 | |
| 270 | gl_Position = uProjection * uView * worldPos; |
| 271 | })"; |
| 272 | } |
| 273 | |
| 274 | string NewShader::getDefaultFragScene() { |
| 275 | return R"(#version 460 core |
| 276 | |
| 277 | in vec3 vFragPos; |
| 278 | in vec3 vNormal; |
| 279 | in vec3 vColor; |
| 280 | in vec4 vFragPosLightSpace; |
| 281 | |
| 282 | out vec4 out_color; |
| 283 | |
| 284 | uniform vec3 uLightPos; |
| 285 | uniform vec3 uLightColor; |
| 286 | uniform sampler2D uShadowMap; |
| 287 | |
| 288 | void main() { |
| 289 | vec3 norm = normalize(vNormal); |
| 290 | vec3 lightDir = normalize(uLightPos - vFragPos); |
| 291 | |
| 292 | float diff = max(dot(norm, lightDir), 0.0); |
| 293 | |
| 294 | vec3 projCoords = vFragPosLightSpace.xyz / vFragPosLightSpace.w; |
| 295 | projCoords = projCoords * 0.5 + 0.5; |
| 296 | |
| 297 | float closestDepth = texture(uShadowMap, projCoords.xy).r; |
| 298 | float currentDepth = projCoords.z; |
| 299 | |
| 300 | float bias = max(0.05 * (1.0 - dot(norm, lightDir)), 0.005); |
| 301 | |
| 302 | float shadow = |
| 303 | (projCoords.z > 1.0) |
| 304 | ? 0.0 |
| 305 | : (currentDepth - bias > closestDepth ? 1.0 : 0.0); |
| 306 | |
| 307 | vec3 ambient = 0.2 * vColor; |
| 308 | vec3 diffuse = (1.0 - shadow) * diff * uLightColor * vColor; |
| 309 | |
| 310 | vec3 viewDir = normalize(-vFragPos); |
| 311 | vec3 reflectDir = reflect(-lightDir, norm); |
| 312 | float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32.0); |
| 313 | vec3 specular = (1.0 - shadow) * 0.3 * spec * uLightColor; |
| 314 | |
| 315 | vec3 result = ambient + diffuse + specular; |
| 316 | |
| 317 | out_color = vec4(result, 1.0); |
| 318 | })"; |
| 319 | } |
| 320 | |
| 321 | string NewShader::getDefaultLuaScene() { |
| 322 | return R"(local posSize = le.sizeof("vec3") |
| 323 | local normalSize = le.sizeof("vec3") |
| 324 | local colorSize = le.sizeof("vec3") |
| 325 | |
| 326 | local stride = posSize + normalSize + colorSize |
| 327 | |
| 328 | local sphere = { |
| 329 | vertices = {}, |
| 330 | |
| 331 | indices = {}, |
| 332 | |
| 333 | attributes = { |
| 334 | { location = 0, size = 3, stride = stride, offset = 0 }, |
| 335 | { location = 1, size = 3, stride = stride, offset = posSize }, |
| 336 | { location = 2, size = 3, stride = stride, offset = posSize + normalSize } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | local plane = { |
| 341 | vertices = { |
| 342 | -20, -2, -20, 0,1,0, 0.4, 0.4, 0.4, |
| 343 | 20, -2, -20, 0,1,0, 0.4, 0.4, 0.4, |
| 344 | 20, -2, 20, 0,1,0, 0.4, 0.4, 0.4, |
| 345 | -20, -2, 20, 0,1,0, 0.4, 0.4, 0.4, |
| 346 | }, |
| 347 | indices = { |
| 348 | 0, 1, 2, |
| 349 | 0, 2, 3, |
| 350 | }, |
| 351 | attributes = { |
| 352 | { location = 0, size = 3, stride = stride, offset = 0 }, |
| 353 | { location = 1, size = 3, stride = stride, offset = posSize }, |
| 354 | { location = 2, size = 3, stride = stride, offset = posSize + normalSize } |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | local pyramid = { |
| 359 | vertices = { |
| 360 | 0.0, 0.8, 0.0, 0.0, 0.447, 0.894, 1,1,1, |
| 361 | -0.5, -0.2, 0.5, 0.0, 0.447, 0.894, 1,0,0, |
| 362 | 0.5, -0.2, 0.5, 0.0, 0.447, 0.894, 0,1,0, |
| 363 | |
| 364 | 0.0, 0.8, 0.0, 0.894, 0.447, 0.0, 1,1,1, |
| 365 | 0.5, -0.2, 0.5, 0.894, 0.447, 0.0, 0,1,0, |
| 366 | 0.5, -0.2, -0.5, 0.894, 0.447, 0.0, 0,0,1, |
| 367 | |
| 368 | 0.0, 0.8, 0.0, 0.0, 0.447, -0.894, 1,1,1, |
| 369 | 0.5, -0.2, -0.5, 0.0, 0.447, -0.894, 0,0,1, |
| 370 | -0.5, -0.2, -0.5, 0.0, 0.447, -0.894, 1,1,0, |
| 371 | |
| 372 | 0.0, 0.8, 0.0, -0.894, 0.447, 0.0, 1,1,1, |
| 373 | -0.5, -0.2, -0.5, -0.894, 0.447, 0.0, 1,1,0, |
| 374 | -0.5, -0.2, 0.5, -0.894, 0.447, 0.0, 1,0,0, |
| 375 | |
| 376 | -0.5, -0.2, 0.5, 0,-1,0, 1,0,0, |
| 377 | 0.5, -0.2, 0.5, 0,-1,0, 0,1,0, |
| 378 | 0.5, -0.2, -0.5, 0,-1,0, 0,0,1, |
| 379 | -0.5, -0.2, -0.5, 0,-1,0, 1,1,0, |
| 380 | }, |
| 381 | |
| 382 | indices = { |
| 383 | 0,1,2, |
| 384 | 3,4,5, |
| 385 | 6,7,8, |
| 386 | 9,10,11, |
| 387 | |
| 388 | 12,13,14, |
| 389 | 12,14,15 |
| 390 | }, |
| 391 | |
| 392 | attributes = { |
| 393 | { location = 0, size = 3, stride = stride, offset = 0 }, |
| 394 | { location = 1, size = 3, stride = stride, offset = posSize }, |
| 395 | { location = 2, size = 3, stride = stride, offset = posSize + normalSize } |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | local cube = { |
| 400 | vertices = { |
| 401 | -- position --normal -- uv |
| 402 | -- mae |
| 403 | -0.5, -0.5, -0.5, 0, 0, -1, 1,0,0, |
| 404 | 0.5, -0.5, -0.5, 0, 0, -1, 0,1,0, |
| 405 | 0.5, 0.5, -0.5, 0, 0, -1, 0,0,1, |
| 406 | -0.5, 0.5, -0.5, 0, 0, -1, 1,1,0, |
| 407 | -- usiro |
| 408 | -0.5, -0.5, 0.5, 0, 0, 1, 1,0,1, |
| 409 | 0.5, -0.5, 0.5, 0, 0, 1, 0,1,1, |
| 410 | 0.5, 0.5, 0.5, 0, 0, 1, 1,1,1, |
| 411 | -0.5, 0.5, 0.5, 0, 0, 1, 1,0,1, |
| 412 | -- (migi) |
| 413 | 0.5, -0.5, -0.5, 1, 0, 0, 0,1,0, |
| 414 | 0.5, -0.5, 0.5, 1, 0, 0, 0,1,1, |
| 415 | 0.5, 0.5, 0.5, 1, 0, 0, 1,1,1, |
| 416 | 0.5, 0.5, -0.5, 1, 0, 0, 0,0,1, |
| 417 | -- hidari |
| 418 | -0.5, -0.5, 0.5, -1, 0, 0, 1,0,1, |
| 419 | -0.5, -0.5, -0.5, -1, 0, 0, 1,0,0, |
| 420 | -0.5, 0.5, -0.5, -1, 0, 0, 1,1,0, |
| 421 | -0.5, 0.5, 0.5, -1, 0, 0, 1,0,1, |
| 422 | -- ue |
| 423 | -0.5, 0.5, -0.5, 0, 1, 0, 1,1,0, |
| 424 | 0.5, 0.5, -0.5, 0, 1, 0, 0,0,1, |
| 425 | 0.5, 0.5, 0.5, 0, 1, 0, 1,1,1, |
| 426 | -0.5, 0.5, 0.5, 0, 1, 0, 1,0,1, |
| 427 | -- sita |
| 428 | -0.5, -0.5, -0.5, 0, -1, 0, 1,0,0, |
| 429 | 0.5, -0.5, -0.5, 0, -1, 0, 0,1,0, |
| 430 | 0.5, -0.5, 0.5, 0, -1, 0, 0,1,1, |
| 431 | -0.5, -0.5, 0.5, 0, -1, 0, 1,0,1, |
| 432 | }, |
| 433 | |
| 434 | indices = { |
| 435 | 0,1,2, 2,3,0, |
| 436 | 4,5,6, 6,7,4, |
| 437 | 8,9,10, 10,11,8, |
| 438 | 12,13,14, 14,15,12, |
| 439 | 16,17,18, 18,19,16, |
| 440 | 20,21,22, 22,23,20 |
| 441 | }, |
| 442 | |
| 443 | attributes = { |
| 444 | { location = 0, size = 3, stride = stride, offset = 0 }, |
| 445 | { location = 1, size = 3, stride = stride, offset = posSize }, |
| 446 | { location = 2, size = 3, stride = stride, offset = posSize + normalSize } |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | local radius = .5 |
| 451 | local stacks = 16 |
| 452 | local slices = 24 |
| 453 | |
| 454 | for i = 0, stacks do |
| 455 | local phi = math.pi * i / stacks |
| 456 | local y = radius * math.cos(phi) |
| 457 | local ringRadius = radius * math.sin(phi) |
| 458 | |
| 459 | for j = 0, slices -1 do |
| 460 | local theta = 2 * math.pi * j / slices |
| 461 | |
| 462 | local x = ringRadius * math.cos(theta) |
| 463 | local z = ringRadius * math.sin(theta) |
| 464 | |
| 465 | local len = math.sqrt(x*x + y*y + z*z) |
| 466 | local nx = x / len |
| 467 | local ny = y / len |
| 468 | local nz = z / len |
| 469 | |
| 470 | local r = (x + radius) / (2 * radius) |
| 471 | local g = (y + radius) / (2 * radius) |
| 472 | local b = (z + radius) / (2 * radius) |
| 473 | |
| 474 | table.insert(sphere.vertices, x) |
| 475 | table.insert(sphere.vertices, y) |
| 476 | table.insert(sphere.vertices, z) |
| 477 | |
| 478 | table.insert(sphere.vertices, nx) |
| 479 | table.insert(sphere.vertices, ny) |
| 480 | table.insert(sphere.vertices, nz) |
| 481 | |
| 482 | table.insert(sphere.vertices, r) |
| 483 | table.insert(sphere.vertices, g) |
| 484 | table.insert(sphere.vertices, b) |
| 485 | end |
| 486 | end |
| 487 | |
| 488 | for i = 0, stacks - 1 do |
| 489 | for j = 0, slices - 1 do |
| 490 | local nextJ = (j + 1) % slices |
| 491 | |
| 492 | local a = i * slices + j |
| 493 | local b = (i + 1) * slices + j |
| 494 | local c = i * slices + nextJ |
| 495 | local d = (i + 1) * slices + nextJ |
| 496 | |
| 497 | table.insert(sphere.indices, a) |
| 498 | table.insert(sphere.indices, b) |
| 499 | table.insert(sphere.indices, c) |
| 500 | |
| 501 | table.insert(sphere.indices, c) |
| 502 | table.insert(sphere.indices, b) |
| 503 | table.insert(sphere.indices, d) |
| 504 | end |
| 505 | end |
| 506 | |
| 507 | le.gfx.add_mesh(cube) |
| 508 | le.gfx.set_position(0, 0, 0, -1) |
| 509 | le.gfx.add_mesh(cube) |
| 510 | le.gfx.set_position(1, -8, -2, -11) |
| 511 | le.gfx.add_mesh(cube) |
| 512 | le.gfx.set_position(2, 8, -2, -11) |
| 513 | |
| 514 | le.gfx.add_mesh(pyramid) |
| 515 | le.gfx.set_position(3, 8, 2, -11) |
| 516 | le.gfx.set_scale(3, 2, 2, 2) |
| 517 | |
| 518 | le.gfx.add_mesh(sphere) |
| 519 | le.gfx.set_position(4, -2, 1, -3) |
| 520 | |
| 521 | le.gfx.add_mesh(plane) |
| 522 | le.gfx.set_position(5, 0, -2, 0) |
| 523 | |
| 524 | function init() |
| 525 | end |
| 526 | |
| 527 | function update() |
| 528 | local t = le.sys.get_time() |
| 529 | local zs = -3 + math.sin(t * 1.5) * 6 |
| 530 | le.gfx.set_position(4, -2.3, -1, zs) |
| 531 | |
| 532 | local size = 8 |
| 533 | local speed = 0.8 |
| 534 | local phase = (t * speed) % (4 * math.pi) |
| 535 | local cubeX, cubeY |
| 536 | |
| 537 | if phase < math.pi then |
| 538 | cubeX = -size/2 + (phase / math.pi) * size |
| 539 | cubeY = size/2 |
| 540 | elseif phase < 2 * math.pi then |
| 541 | cubeX = size/2 |
| 542 | cubeY = size/2 - ((phase - math.pi) / math.pi) * size |
| 543 | elseif phase < 3 * math.pi then |
| 544 | cubeX = size/2 - ((phase - 2*math.pi) / math.pi) * size |
| 545 | cubeY = -size/2 |
| 546 | else |
| 547 | cubeX = -size/2 |
| 548 | cubeY = -size/2 + ((phase - 3*math.pi) / math.pi) * size |
| 549 | end |
| 550 | |
| 551 | le.gfx.set_position(2, cubeX, cubeY, -11) |
| 552 | |
| 553 | le.gfx.set_rotation(0, t*0.7, t*1.0, t*0.4) |
| 554 | le.gfx.set_rotation(1, t*0.2, t*0.8, t*1.4) |
| 555 | le.gfx.set_rotation(2, t*0.4, t*0.5, t*0.8) |
| 556 | le.gfx.set_rotation(3, 0, t*0.8, -.5) |
| 557 | |
| 558 | local reso = le.sys.get_resolution() |
| 559 | local aspect = reso.x / reso.y |
| 560 | |
| 561 | local view = le.math.look_at( |
| 562 | 0, 0, 4, -- eye |
| 563 | 0, 0, 0, -- target |
| 564 | 0, 1, 0 -- up |
| 565 | ) |
| 566 | |
| 567 | local projection = le.math.perspective( |
| 568 | 45.0, |
| 569 | aspect, |
| 570 | 0.1, |
| 571 | 100.0 |
| 572 | ) |
| 573 | |
| 574 | le.gfx.set_uniform_mat4("uView", view) |
| 575 | le.gfx.set_uniform_mat4("uProjection", projection) |
| 576 | le.gfx.set_uniform_vec3("uLightPos", 3, 5, 2) |
| 577 | le.gfx.set_uniform_vec3("uLightColor", 1, 1, 1) |
| 578 | end)"; |
| 579 | } |
| 580 | } |