-
Notifications
You must be signed in to change notification settings - Fork 0
/
sponza.lua
125 lines (95 loc) · 3.15 KB
/
sponza.lua
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
------------------
-- Create Scene --
------------------
scene = Scene.new(applicationContext)
-----------------------------
-- Create and add Renderer --
-----------------------------
-- forward with skybox
--[[
SkyboxRenderer.new(3, scene)
SunRenderer.new(2, scene)
ForwardRenderer.new(1, scene)
]]
-- deferred with skybox
--[[
DeferredRenderer.new(3, scene)
SkyboxRenderer.new(2, scene)
SunRenderer.new(1, scene)
]]
-- forward with skydome
SkydomeRenderer.new(3, scene)
SunRenderer.new(2, scene)
ForwardRenderer.new(1, scene)
-- deferred with skydome
--[[
DeferredRenderer.new(3, scene)
SkydomeRenderer.new(2, scene)
SunRenderer.new(1, scene)
]]
----------------------------
-- Create and add Cameras --
----------------------------
firstPersonCamera = FirstPersonCamera.new("first_person_camera1", applicationContext, Vec3.new(1197.0, 171.0, -23.0), -179.0, 1.0, scene)
firstPersonCamera:SetCameraVelocity(200.0)
firstPersonCamera:SetMouseSensitivity(0.1)
------------------
-- Config Scene --
------------------
scene:SetCurrentCamera("first_person_camera1")
scene:SetAmbientIntensity(Vec3.new(0.2, 0.2, 0.2))
--------------------
-- Load resources --
--------------------
sponza = modelManager:GetModel("res/model/Sponza/sponza.obj")
dome = modelManager:GetModel("res/model/Dome/dome.obj")
sunTextureId = textureManager:LoadTexture("res/sun/sun.png")
a = {}
a[1] = "res/skybox/sky1/sRight.png"
a[2] = "res/skybox/sky1/sLeft.png"
a[3] = "res/skybox/sky1/sUp.png"
a[4] = "res/skybox/sky1/sDown.png"
a[5] = "res/skybox/sky1/sBack.png"
a[6] = "res/skybox/sky1/sFront.png"
skyboxCubemapId = textureManager:GetCubemapId(a)
---------------------
-- Create Entities --
---------------------
-- sponza
sponzaEntity = ecs:CreateEntity()
ecs:AddModelComponent(sponzaEntity, sponza, false)
ecs:AddTransformComponent(sponzaEntity, Vec3.new(0.0, 0.0, 0.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(1.0, 1.0, 1.0))
-- sun
sunEntity = ecs:CreateEntity()
ecs:AddSunComponent(sunEntity,
Vec3.new(1.0, -0.2, -0.4), -- direction
Vec3.new(1.0, 0.8, 0.6), -- diffuseIntensity
Vec3.new(0.6, 0.6, 0.6), -- specularIntensity
sunTextureId,
10.0
)
-- point lights
p1 = ecs:CreateEntity()
ecs:AddPointLightComponent(p1,
Vec3.new(-945.0, 20.0, -89.0), -- position
Vec3.new(0.2, 0.2, 0.2), -- ambientIntensity
Vec3.new(10.0, 1.0, 1.0), -- diffuseIntensity
Vec3.new(1.0, 1.0, 1.0), -- specularIntensity
1.0, 0.007, 0.002 -- constant, linear, quadratic
)
p2 = ecs:CreateEntity()
ecs:AddPointLightComponent(p2,
Vec3.new(-64.0, 20.0, -89.0), -- position
Vec3.new(0.2, 0.2, 0.2), -- ambientIntensity
Vec3.new(1.0, 1.0, 10.0), -- diffuseIntensity
Vec3.new(1.0, 1.0, 1.0), -- specularIntensity
1.0, 0.007, 0.002 -- constant, linear, quadratic
)
-- skybox
skyboxEntity = ecs:CreateEntity()
ecs:AddCubemapComponent(skyboxEntity, skyboxCubemapId)
-- skydome
skydomeEntity = ecs:CreateEntity()
ecs:AddModelComponent(skydomeEntity, dome, false)
ecs:AddTransformComponent(skydomeEntity, Vec3.new(0.0, 0.0, 0.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(5000.0, 5000.0, 5000.0))
ecs:AddSkydomeComponent(skydomeEntity, "skydome")