Compare commits

..

1 Commits

Author SHA1 Message Date
8c0be0a3fc initial bloom 2024-01-23 11:10:48 +01:00
37 changed files with 441 additions and 214968 deletions

View File

@ -1,30 +0,0 @@
# Interaktywny symulator lotu kosmicznego 3D "Interstellar Odyssey"
![Screenshot](screenshot.png)
## Motyw Aplikacji:
Interstellar Odyssey to gra zręcznościowa, której celem jest zebranie określonej liczby gwiazdek jednocześnie unikając pojawiających sie asteroid, które mogą zostać zniszczone pociskami gracza.
### Sceny:
- Kosmiczne asteroidy i planety.<br>
- Pasy asteroid. <br>
### Interakcje:
- Sterowanie statkiem.
- Strzelanie pociskami.
- Zbieranie gwiazdek.
- Unikanie przeszkód.
- Niszczenie asteroid.
### Przełożenie Metod Grafiki na Realizację Motywu Aplikacji:
* Mapowanie Normalnych: Detale powierzchni planet i asteroid, nadana trójwymiarowość.
* PBR (Physically Based Rendering): Odpowiedzialne za realistyczne oświetlenie, cienie, odbicia i tekstury wysokiej jakości na statkach kosmicznych i otaczających obiektach, stosujące model Fresnela-Schlick
* Proceduralne Generowanie Terenu: Generowanie asteroid i gwiazdek w przestrzeni kosmicznej.
* Skybox
* Kolizje
* Animacja ruchu statku: Płynne i realistyczne ruchy statku kosmicznego przy skręcaniu, wznoszeniu i opadaniu.
###
Wiktoria Grzesik <br>
Maksymilian Szygenda <br>
Nikodem Hederych <br>

View File

@ -37,8 +37,6 @@
<ClInclude Include="src\Texture.h" />
</ItemGroup>
<ItemGroup>
<None Include="shaders\rocket.frag" />
<None Include="shaders\rocket.vert" />
<None Include="shaders\shader_5_1.frag" />
<None Include="shaders\shader_5_1.vert" />
<None Include="shaders\shader_5_1_tex.frag" />
@ -47,10 +45,12 @@
<None Include="shaders\shader_5_sun.vert" />
<None Include="shaders\shader_5_tex.frag" />
<None Include="shaders\shader_5_tex.vert" />
<None Include="shaders\shader_bloom.frag" />
<None Include="shaders\shader_bloom.vert" />
<None Include="shaders\shader_quad.frag" />
<None Include="shaders\shader_quad.vert" />
<None Include="shaders\shader_skybox.frag" />
<None Include="shaders\shader_skybox.vert" />
<None Include="shaders\signs.frag" />
<None Include="shaders\signs.vert" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}</ProjectGuid>
@ -71,7 +71,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">

View File

@ -121,16 +121,16 @@
<None Include="shaders\shader_5_tex.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\rocket.vert">
<None Include="shaders\shader_bloom.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\rocket.frag">
<None Include="shaders\shader_bloom.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\signs.frag">
<None Include="shaders\shader_quad.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\signs.vert">
<None Include="shaders\shader_quad.frag">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>

View File

File diff suppressed because it is too large Load Diff

View File

@ -1,358 +0,0 @@
# This file uses centimeters as units for non-parametric coordinates.
mtllib estrellica.mtl
g default
v 7.889562 1.150329 -2.173651
v 2.212808 1.150329 -2.230414
v 0.068023 1.150328 -7.923502
v -2.151306 1.150329 -2.254857
v -7.817406 1.150328 -2.261558
v -3.523133 1.150328 1.888122
v -4.869315 1.150328 6.987552
v -0.006854 1.150329 4.473047
v 4.838127 1.150328 7.041885
v 3.538153 1.150329 1.927652
v 0.033757 0.000000 -0.314657
v 0.035668 2.269531 -0.312831
vt 0.626409 0.064409
vt 0.548284 0.007647
vt 0.451716 0.007647
vt 0.373591 0.064409
vt 0.343750 0.156250
vt 0.373591 0.248091
vt 0.451716 0.304853
vt 0.548284 0.304853
vt 0.626409 0.248091
vt 0.656250 0.156250
vt 0.375000 0.312500
vt 0.400000 0.312500
vt 0.425000 0.312500
vt 0.450000 0.312500
vt 0.475000 0.312500
vt 0.500000 0.312500
vt 0.525000 0.312500
vt 0.550000 0.312500
vt 0.575000 0.312500
vt 0.600000 0.312500
vt 0.625000 0.312500
vt 0.500000 0.688440
vt 0.500000 0.156250
vn 0.005105 -0.859861 -0.510503
vn 0.005105 -0.859861 -0.510503
vn 0.005105 -0.859861 -0.510503
vn 0.365127 -0.920739 -0.137556
vn 0.365127 -0.920739 -0.137556
vn 0.365127 -0.920739 -0.137556
vn -0.360232 -0.922140 -0.141034
vn -0.360232 -0.922140 -0.141034
vn -0.360232 -0.922140 -0.141034
vn 0.000604 -0.859880 -0.510496
vn 0.000604 -0.859880 -0.510496
vn 0.000604 -0.859880 -0.510496
vn -0.189615 -0.962051 0.196222
vn -0.189615 -0.962051 0.196222
vn -0.189615 -0.962051 0.196222
vn -0.358980 -0.928522 -0.094766
vn -0.358980 -0.928522 -0.094766
vn -0.358980 -0.928522 -0.094766
vn 0.120430 -0.965019 0.232884
vn 0.120430 -0.965019 0.232884
vn 0.120430 -0.965019 0.232884
vn -0.122414 -0.965251 0.230880
vn -0.122414 -0.965251 0.230880
vn -0.122414 -0.965251 0.230880
vn 0.363409 -0.927039 -0.092374
vn 0.363409 -0.927039 -0.092374
vn 0.363409 -0.927039 -0.092374
vn 0.188029 -0.961689 0.199495
vn 0.188029 -0.961689 0.199495
vn 0.188029 -0.961689 0.199495
vn 0.183421 0.963579 0.194606
vn 0.183421 0.963579 0.194606
vn 0.183421 0.963579 0.194606
vn 0.355062 0.930476 -0.090252
vn 0.355062 0.930476 -0.090252
vn 0.355062 0.930476 -0.090252
vn -0.119338 0.967005 0.225079
vn -0.119338 0.967005 0.225079
vn -0.119338 0.967005 0.225079
vn 0.117452 0.966757 0.227125
vn 0.117452 0.966757 0.227125
vn 0.117452 0.966757 0.227125
vn -0.350315 0.932055 -0.092478
vn -0.350315 0.932055 -0.092478
vn -0.350315 0.932055 -0.092478
vn -0.184852 0.963969 0.191293
vn -0.184852 0.963969 0.191293
vn -0.184852 0.963969 0.191293
vn 0.000591 0.866128 -0.499821
vn 0.000591 0.866128 -0.499821
vn 0.000591 0.866128 -0.499821
vn -0.351624 0.925964 -0.137664
vn -0.351624 0.925964 -0.137664
vn -0.351624 0.925964 -0.137664
vn 0.356828 0.924447 -0.134430
vn 0.356828 0.924447 -0.134430
vn 0.356828 0.924447 -0.134430
vn 0.004998 0.866108 -0.499832
vn 0.004998 0.866108 -0.499832
vn 0.004998 0.866108 -0.499832
s off
g pCylinder1
usemtl initialShadingGroup
f 1/11/1 11/22/2 2/12/3
f 2/12/4 11/22/5 3/13/6
f 3/13/7 11/22/8 4/14/9
f 4/14/10 11/22/11 5/15/12
f 5/15/13 11/22/14 6/16/15
f 6/16/16 11/22/17 7/17/18
f 7/17/19 11/22/20 8/18/21
f 8/18/22 11/22/23 9/19/24
f 9/19/25 11/22/26 10/20/27
f 10/20/28 11/22/29 1/21/30
f 1/1/31 12/23/32 10/10/33
f 10/10/34 12/23/35 9/9/36
f 9/9/37 12/23/38 8/8/39
f 8/8/40 12/23/41 7/7/42
f 7/7/43 12/23/44 6/6/45
f 6/6/46 12/23/47 5/5/48
f 5/5/49 12/23/50 4/4/51
f 4/4/52 12/23/53 3/3/54
f 3/3/55 12/23/56 2/2/57
f 2/2/58 12/23/59 1/1/60
g default
v 7.889562 1.150329 -2.173651
v 2.212808 1.150329 -2.230414
v 0.068023 1.150328 -7.923502
v -2.151306 1.150329 -2.254857
v -7.817406 1.150328 -2.261558
v -3.523133 1.150328 1.888122
v -4.869315 1.150328 6.987552
v -0.006854 1.150329 4.473047
v 4.838127 1.150328 7.041885
v 3.538153 1.150329 1.927652
v 0.033757 0.000000 -0.314657
v 0.035668 2.269531 -0.312831
vt 0.626409 0.064409
vt 0.548284 0.007647
vt 0.451716 0.007647
vt 0.373591 0.064409
vt 0.343750 0.156250
vt 0.373591 0.248091
vt 0.451716 0.304853
vt 0.548284 0.304853
vt 0.626409 0.248091
vt 0.656250 0.156250
vt 0.375000 0.312500
vt 0.400000 0.312500
vt 0.425000 0.312500
vt 0.450000 0.312500
vt 0.475000 0.312500
vt 0.500000 0.312500
vt 0.525000 0.312500
vt 0.550000 0.312500
vt 0.575000 0.312500
vt 0.600000 0.312500
vt 0.625000 0.312500
vt 0.500000 0.688440
vt 0.500000 0.156250
vn 0.005105 -0.859861 -0.510503
vn 0.005105 -0.859861 -0.510503
vn 0.005105 -0.859861 -0.510503
vn 0.365127 -0.920739 -0.137556
vn 0.365127 -0.920739 -0.137556
vn 0.365127 -0.920739 -0.137556
vn -0.360232 -0.922140 -0.141034
vn -0.360232 -0.922140 -0.141034
vn -0.360232 -0.922140 -0.141034
vn 0.000604 -0.859880 -0.510496
vn 0.000604 -0.859880 -0.510496
vn 0.000604 -0.859880 -0.510496
vn -0.189615 -0.962051 0.196222
vn -0.189615 -0.962051 0.196222
vn -0.189615 -0.962051 0.196222
vn -0.358980 -0.928522 -0.094766
vn -0.358980 -0.928522 -0.094766
vn -0.358980 -0.928522 -0.094766
vn 0.120430 -0.965019 0.232884
vn 0.120430 -0.965019 0.232884
vn 0.120430 -0.965019 0.232884
vn -0.122414 -0.965251 0.230880
vn -0.122414 -0.965251 0.230880
vn -0.122414 -0.965251 0.230880
vn 0.363409 -0.927039 -0.092374
vn 0.363409 -0.927039 -0.092374
vn 0.363409 -0.927039 -0.092374
vn 0.188029 -0.961689 0.199495
vn 0.188029 -0.961689 0.199495
vn 0.188029 -0.961689 0.199495
vn 0.183421 0.963579 0.194606
vn 0.183421 0.963579 0.194606
vn 0.183421 0.963579 0.194606
vn 0.355062 0.930476 -0.090252
vn 0.355062 0.930476 -0.090252
vn 0.355062 0.930476 -0.090252
vn -0.119338 0.967005 0.225079
vn -0.119338 0.967005 0.225079
vn -0.119338 0.967005 0.225079
vn 0.117452 0.966757 0.227125
vn 0.117452 0.966757 0.227125
vn 0.117452 0.966757 0.227125
vn -0.350315 0.932055 -0.092478
vn -0.350315 0.932055 -0.092478
vn -0.350315 0.932055 -0.092478
vn -0.184852 0.963969 0.191293
vn -0.184852 0.963969 0.191293
vn -0.184852 0.963969 0.191293
vn 0.000591 0.866128 -0.499821
vn 0.000591 0.866128 -0.499821
vn 0.000591 0.866128 -0.499821
vn -0.351624 0.925964 -0.137664
vn -0.351624 0.925964 -0.137664
vn -0.351624 0.925964 -0.137664
vn 0.356828 0.924447 -0.134430
vn 0.356828 0.924447 -0.134430
vn 0.356828 0.924447 -0.134430
vn 0.004998 0.866108 -0.499832
vn 0.004998 0.866108 -0.499832
vn 0.004998 0.866108 -0.499832
s off
g pCylinder1
f 13/34/61 23/45/62 14/35/63
f 14/35/64 23/45/65 15/36/66
f 15/36/67 23/45/68 16/37/69
f 16/37/70 23/45/71 17/38/72
f 17/38/73 23/45/74 18/39/75
f 18/39/76 23/45/77 19/40/78
f 19/40/79 23/45/80 20/41/81
f 20/41/82 23/45/83 21/42/84
f 21/42/85 23/45/86 22/43/87
f 22/43/88 23/45/89 13/44/90
f 13/24/91 24/46/92 22/33/93
f 22/33/94 24/46/95 21/32/96
f 21/32/97 24/46/98 20/31/99
f 20/31/100 24/46/101 19/30/102
f 19/30/103 24/46/104 18/29/105
f 18/29/106 24/46/107 17/28/108
f 17/28/109 24/46/110 16/27/111
f 16/27/112 24/46/113 15/26/114
f 15/26/115 24/46/116 14/25/117
f 14/25/118 24/46/119 13/24/120
g default
v 7.889562 1.150329 -2.173651
v 2.212808 1.150329 -2.230414
v 0.068023 1.150328 -7.923502
v -2.151306 1.150329 -2.254857
v -7.817406 1.150328 -2.261558
v -3.523133 1.150328 1.888122
v -4.869315 1.150328 6.987552
v -0.006854 1.150329 4.473047
v 4.838127 1.150328 7.041885
v 3.538153 1.150329 1.927652
v 0.033757 0.000000 -0.314657
v 0.035668 2.269531 -0.312831
vt 0.626409 0.064409
vt 0.548284 0.007647
vt 0.451716 0.007647
vt 0.373591 0.064409
vt 0.343750 0.156250
vt 0.373591 0.248091
vt 0.451716 0.304853
vt 0.548284 0.304853
vt 0.626409 0.248091
vt 0.656250 0.156250
vt 0.375000 0.312500
vt 0.400000 0.312500
vt 0.425000 0.312500
vt 0.450000 0.312500
vt 0.475000 0.312500
vt 0.500000 0.312500
vt 0.525000 0.312500
vt 0.550000 0.312500
vt 0.575000 0.312500
vt 0.600000 0.312500
vt 0.625000 0.312500
vt 0.500000 0.688440
vt 0.500000 0.156250
vn 0.005105 -0.859861 -0.510503
vn 0.005105 -0.859861 -0.510503
vn 0.005105 -0.859861 -0.510503
vn 0.365127 -0.920739 -0.137556
vn 0.365127 -0.920739 -0.137556
vn 0.365127 -0.920739 -0.137556
vn -0.360232 -0.922140 -0.141034
vn -0.360232 -0.922140 -0.141034
vn -0.360232 -0.922140 -0.141034
vn 0.000604 -0.859880 -0.510496
vn 0.000604 -0.859880 -0.510496
vn 0.000604 -0.859880 -0.510496
vn -0.189615 -0.962051 0.196222
vn -0.189615 -0.962051 0.196222
vn -0.189615 -0.962051 0.196222
vn -0.358980 -0.928522 -0.094766
vn -0.358980 -0.928522 -0.094766
vn -0.358980 -0.928522 -0.094766
vn 0.120430 -0.965019 0.232884
vn 0.120430 -0.965019 0.232884
vn 0.120430 -0.965019 0.232884
vn -0.122414 -0.965251 0.230880
vn -0.122414 -0.965251 0.230880
vn -0.122414 -0.965251 0.230880
vn 0.363409 -0.927039 -0.092374
vn 0.363409 -0.927039 -0.092374
vn 0.363409 -0.927039 -0.092374
vn 0.188029 -0.961689 0.199495
vn 0.188029 -0.961689 0.199495
vn 0.188029 -0.961689 0.199495
vn 0.183421 0.963579 0.194606
vn 0.183421 0.963579 0.194606
vn 0.183421 0.963579 0.194606
vn 0.355062 0.930476 -0.090252
vn 0.355062 0.930476 -0.090252
vn 0.355062 0.930476 -0.090252
vn -0.119338 0.967005 0.225079
vn -0.119338 0.967005 0.225079
vn -0.119338 0.967005 0.225079
vn 0.117452 0.966757 0.227125
vn 0.117452 0.966757 0.227125
vn 0.117452 0.966757 0.227125
vn -0.350315 0.932055 -0.092478
vn -0.350315 0.932055 -0.092478
vn -0.350315 0.932055 -0.092478
vn -0.184852 0.963969 0.191293
vn -0.184852 0.963969 0.191293
vn -0.184852 0.963969 0.191293
vn 0.000591 0.866128 -0.499821
vn 0.000591 0.866128 -0.499821
vn 0.000591 0.866128 -0.499821
vn -0.351624 0.925964 -0.137664
vn -0.351624 0.925964 -0.137664
vn -0.351624 0.925964 -0.137664
vn 0.356828 0.924447 -0.134430
vn 0.356828 0.924447 -0.134430
vn 0.356828 0.924447 -0.134430
vn 0.004998 0.866108 -0.499832
vn 0.004998 0.866108 -0.499832
vn 0.004998 0.866108 -0.499832
s off
g pCylinder1
f 25/57/121 35/68/122 26/58/123
f 26/58/124 35/68/125 27/59/126
f 27/59/127 35/68/128 28/60/129
f 28/60/130 35/68/131 29/61/132
f 29/61/133 35/68/134 30/62/135
f 30/62/136 35/68/137 31/63/138
f 31/63/139 35/68/140 32/64/141
f 32/64/142 35/68/143 33/65/144
f 33/65/145 35/68/146 34/66/147
f 34/66/148 35/68/149 25/67/150
f 25/47/151 36/69/152 34/56/153
f 34/56/154 36/69/155 33/55/156
f 33/55/157 36/69/158 32/54/159
f 32/54/160 36/69/161 31/53/162
f 31/53/163 36/69/164 30/52/165
f 30/52/166 36/69/167 29/51/168
f 29/51/169 36/69/170 28/50/171
f 28/50/172 36/69/173 27/49/174
f 27/49/175 36/69/176 26/48/177
f 26/48/178 36/69/179 25/47/180

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

16
cw 7/models/test.obj Normal file
View File

@ -0,0 +1,16 @@
# Blender v3.2.1 OBJ File: 'untitled.blend'
# www.blender.org
mtllib plane.mtl
o Plane.001
v -1.000000 -1.000000 -0.000000
v 1.000000 -1.000000 -0.000000
v -1.000000 1.000000 0.000000
v 1.000000 1.000000 0.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vn 0.0000 -0.0000 1.0000
usemtl None
s off
f 1/1/1 2/2/1 4/3/1 3/4/1

View File

@ -1,36 +0,0 @@
#version 330 core
in vec3 fragNormal;
in vec2 fragTexCoord;
out vec4 fragColor;
struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
// Dodaj inne właściwości materiałów, jeśli są potrzebne
};
uniform Material material;
uniform vec3 lightPosition;
uniform vec3 viewPosition;
void main()
{
vec3 normal = normalize(fragNormal);
vec3 lightDirection = normalize(lightPosition - gl_FragCoord.xyz);
float diff = max(dot(normal, lightDirection), 0.0);
vec3 viewDirection = normalize(viewPosition - gl_FragCoord.xyz);
vec3 reflectDirection = reflect(-lightDirection, normal);
float spec = pow(max(dot(viewDirection, reflectDirection), 0.0), 32.0);
vec3 ambient = material.ambient;
vec3 diffuse = material.diffuse * diff;
vec3 specular = material.specular * spec;
vec3 finalColor = ambient + diffuse + specular;
fragColor = vec4(finalColor, 1.0);
}

View File

@ -1,18 +0,0 @@
#version 330 core
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inTexCoord;
out vec3 fragNormal;
out vec2 fragTexCoord;
uniform mat4 transformation;
uniform mat4 modelMatrix;
void main()
{
gl_Position = transformation * modelMatrix * vec4(inPosition, 1.0);
fragNormal = mat3(transpose(inverse(modelMatrix))) * inNormal;
fragTexCoord = inTexCoord;
}

View File

@ -1,121 +1,18 @@
#version 430 core
float AMBIENT = 0.03;
float PI = 3.14;
uniform sampler2D depthMap;
uniform vec3 cameraPos;
float AMBIENT = 0.1;
uniform vec3 color;
uniform vec3 lightPos;
uniform vec3 lightColor;
uniform vec3 spotlightPos;
uniform vec3 spotlightColor;
uniform vec3 spotlightConeDir;
uniform vec3 spotlightPhi;
uniform float metallic;
uniform float roughness;
uniform float exposition;
in vec3 vecNormal;
in vec3 worldPos;
out vec4 outColor;
in vec3 viewDirTS;
in vec3 lightDirTS;
in vec3 spotlightDirTS;
in vec3 sunDirTS;
in vec3 test;
float GGX(vec3 normal, vec3 H, float roughness){
float a = roughness*roughness;
float a2 = a*a;
float NdotH = max(dot(normal, H), 0.0);
float NdotH2 = NdotH*NdotH;
float num = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return num / denom;
}
float Gs_GGX(float NdotV, float roughness){
float r = (roughness + 1.0);
float k = (r*r) / 8.0;
float num = NdotV;
float denom = NdotV * (1.0 - k) + k;
return num / denom;
}
float GS(vec3 normal, vec3 V, vec3 lightDir, float roughness){
float NdotV = max(dot(normal, V), 0.0);
float NdotL = max(dot(normal, lightDir), 0.0);
float ggx2 = Gs_GGX(NdotV, roughness);
float ggx1 = Gs_GGX(NdotL, roughness);
return ggx1 * ggx2;
}
vec3 fS(float cosTheta, vec3 F0){
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){
float diffuse=max(0,dot(normal,lightDir));
//vec3 V = normalize(cameraPos-worldPos);
vec3 F0 = vec3(0.04);
F0 = mix(F0, color, metallic);
vec3 H = normalize(V + lightDir);
float NDF = GGX(normal, H, roughness);
float G = GS(normal, V, lightDir, roughness);
vec3 F = fS(max(dot(H, V), 0.0), F0);
vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
kD *= 1.0 - metallic;
vec3 numerator = NDF * G * F;
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, lightDir), 0.0) + 0.0001;
vec3 specular = numerator / denominator;
float NdotL = max(dot(normal, lightDir), 0.0);
return (kD * color / PI + specular) * radiance * NdotL;
}
void main()
{
vec3 normal = normalize(vecNormal);
vec3 viewDir = normalize(cameraPos-worldPos);
vec3 lightDir = normalize(lightPos-worldPos);
vec3 ambient = AMBIENT*color;
vec3 attenuatedlightColor = lightColor/pow(length(lightPos-worldPos),2);
vec3 ilumination;
ilumination = ambient+PBRLight(lightDir,attenuatedlightColor,normal,viewDir);
vec3 spotlightDir= normalize(spotlightPos-worldPos);
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
vec3 normal = normalize(vecNormal);
float diffuse=max(0,dot(normal,lightDir));
outColor = vec4(color*min(1,AMBIENT+diffuse), 1.0);
}

View File

@ -3,8 +3,6 @@
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation;
uniform mat4 modelMatrix;
@ -12,32 +10,9 @@ uniform mat4 modelMatrix;
out vec3 vecNormal;
out vec3 worldPos;
uniform vec3 lightPos;
uniform vec3 spotlightPos;
uniform vec3 cameraPos;
uniform vec3 sunDir;
out vec3 viewDirTS;
out vec3 lightDirTS;
out vec3 spotlightDirTS;
out vec3 sunDirTS;
void main()
{
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
gl_Position = transformation * vec4(vertexPosition, 1.0);
vec3 w_tangent = normalize(mat3(modelMatrix)*vertexTangent);
vec3 w_bitangent = normalize(mat3(modelMatrix)*vertexBitangent);
mat3 TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
vec3 V = normalize(cameraPos-worldPos);
viewDirTS = TBN*V;
vec3 L = normalize(lightPos-worldPos);
lightDirTS = TBN*L;
vec3 SL = normalize(spotlightPos-worldPos);
spotlightDirTS = TBN*SL;
sunDirTS = TBN*sunDir;
}

View File

@ -1,7 +1,7 @@
#version 430 core
float AMBIENT = 0.1;
float MAX_DISTANCE = 6.0;
uniform vec3 color;
uniform vec3 lightPos;
uniform sampler2D colorTexture;
@ -16,10 +16,6 @@ void main()
vec3 lightDir = normalize(lightPos-worldPos);
vec3 normal = normalize(vecNormal);
vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
if (distanceToCamera > MAX_DISTANCE)
{
discard;
}
float diffuse=max(0,dot(normal,lightDir));
outColor = vec4(textureColor*min(1,AMBIENT+diffuse), 1.0);
}

View File

@ -1,17 +1,10 @@
#version 430 core
uniform vec3 objectColor;
uniform float exposition;
uniform sampler2D sunTexture;
out vec4 outColor;
in vec2 TexCoords;
in vec3 interpNormal;
void main()
{
vec3 textureColor = texture2D(sunTexture, TexCoords).xyz;
vec3 adjustedColor = 1.0 - exp(-textureColor * exposition);
// Output the color with unchanged alpha
outColor = vec4(clamp(adjustedColor, 0.0, 1.0), 1.0);
//outColor = vec4(textureColor*min(1,exposition), 1.0);
gl_FragColor = vec4(objectColor, 1.0);
}

View File

@ -1,15 +1,15 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 1) in vec2 vertexTexCoord;
layout(location = 2) in vec3 vertexNormal;
uniform mat4 transformation;
out vec2 TexCoords;
out vec3 interpNormal;
void main()
{
gl_Position = transformation * vec4(vertexPosition, 1.0);
TexCoords = vertexTexCoord;
interpNormal = vertexNormal;
}

View File

@ -1,72 +1,39 @@
#version 430 core
float AMBIENT = 0.4;
float roughness;
float metalic;
float MAX_DISTANCE = 12.0;
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 BloomColor;
float AMBIENT = 0.1;
uniform vec3 color;
uniform sampler2D colorTexture;
uniform sampler2D normalSampler;
uniform sampler2D metalnessTexture;
uniform sampler2D roughnessTexture;
in vec3 worldPos;
in vec2 vecTex;
in vec3 viewDirTS;
in vec3 lightDirTS;
in float distanceToCamera;
out vec4 outColor;
void main()
{
vec3 normal = vec3(0,0,1);
vec3 L = (lightDirTS);
vec3 V = (viewDirTS);
vec3 lightDir = normalize(lightDirTS);
vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
float metalnessValue = texture2D(metalnessTexture, vecTex).r;
float roughnessValue = texture2D(roughnessTexture, vecTex).r;
roughness =roughnessValue;
metalic = metalnessValue;
vec3 N = texture2D(normalSampler, vecTex).xyz;
N = 2.0 * N - 1.0;
N = normalize(N);
vec3 H = normalize(L + V);
float NdotH = max(0.0, dot(N, H));
float NdotL = max(dot(N, L),0.0000001 );
float NdotV = max(0.0, dot(N, V));
float VdotH = max(0.00001, dot(V, H));
float k = pow((roughness +1),2.0)/8.0;
float diffuse=max(0, dot(N, lightDir));
FragColor = vec4(textureColor * min(1, AMBIENT + diffuse), 1.0);
float D = (roughness * roughness) / (3.14159 * pow(pow(NdotH * NdotH,2.0) * (roughness * roughness - 1.0) + 1.0, 2.0));
float ggx1 = NdotV / (NdotV * (1.0 - k) + k);
float ggx2 = NdotL / (NdotL * (1.0 - k) + k);
vec3 F0 = mix(vec3(0.04), vec3(1.0), metalic);
float G = ggx1 * ggx2;
vec3 F = F0 + (1.0-F0)*pow(1-dot(V,H),5.0);
vec3 specular = (D*G*F)/(4*NdotL*NdotV+0.00001);
vec3 kD = vec3(1.0) - F;
vec3 BRDF = kD*(textureColor/3.1458493) + specular;
if (distanceToCamera > MAX_DISTANCE)
{
discard;
}
float brightness = dot(FragColor.rgb, vec3(0.2126f, 0.7152f, 0.0722f));
if(brightness > 0.15f)
BloomColor = vec4(FragColor.rgb, 1.0f);
else
BloomColor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
float diffuse=max(0.0001,dot(N,L));
outColor = vec4(BRDF*(AMBIENT + diffuse)*1.5, 1.0);
}

View File

@ -6,6 +6,7 @@ layout(location = 2) in vec2 vertexTexCoord;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation;
uniform mat4 modelMatrix;
@ -17,15 +18,11 @@ uniform vec3 cameraPos;
out vec3 viewDirTS;
out vec3 lightDirTS;
out float distanceToCamera;
mat3 TBN;
void main()
{
vec3 tangent = normalize(mat3(modelMatrix) * vertexTangent);
vec3 bitangent = normalize(mat3(modelMatrix) * vertexBitangent);
vec3 normal = normalize(mat3(modelMatrix) * vertexNormal);
@ -42,6 +39,6 @@ void main()
vecTex = vertexTexCoord;
vecTex.y = 1.0 - vecTex.y;
distanceToCamera = length(worldPos - cameraPos);
gl_Position = transformation * vec4(vertexPosition, 1.0);
}

View File

@ -0,0 +1,22 @@
#version 430 core
out vec4 FragColor;
in vec2 texCoords;
uniform sampler2D screenTexture;
uniform sampler2D bloomTexture;
uniform float gamma;
void main()
{
vec3 fragment = texture(screenTexture, texCoords).rgb;
vec3 bloom = texture(bloomTexture, texCoords).rgb;
vec3 color = fragment + bloom;
float exposure = 0.8f;
vec3 toneMapped = vec3(1.0f) - exp(-color * exposure);
FragColor.rgb = pow(toneMapped, vec3(1.0f / gamma));
}

View File

@ -0,0 +1,16 @@
#version 430 core
layout (location = 0) in vec2 inPos;
layout (location = 1) in vec2 inTexCoords;
out vec2 texCoords;
void main()
{
gl_Position = vec4(inPos.x, inPos.y, 0.0, 1.0);
texCoords = inTexCoords;
}

View File

@ -0,0 +1,15 @@
#version 430 core
uniform sampler2D colorTexture;
uniform sampler2D highlightTexture;
in vec2 vecTex;
out vec4 outColor;
void main()
{
vec3 color = texture(colorTexture,vecTex).rgb;
vec3 color2 = texture(highlightTexture,vecTex).rgb;
outColor = vec4(color+color2, 1.0);
}

View File

@ -0,0 +1,13 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
out vec2 vecTex;
void main()
{
//worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
vecTex = vertexPosition.xy*0.5+0.5;
gl_Position = vec4(vertexPosition, 1.0);
}

View File

@ -4,9 +4,15 @@ uniform samplerCube skybox;
in vec3 texCoord;
out vec4 out_color;
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 BloomColor;
void main()
{
out_color = texture(skybox,texCoord);
FragColor = texture(skybox,texCoord);
float brightness = dot(FragColor.rgb, vec3(0.2126f, 0.7152f, 0.0722f));
if(brightness > 0.15f)
BloomColor = vec4(FragColor.rgb, 1.0f);
else
BloomColor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
}

View File

@ -1,36 +0,0 @@
float AMBIENT = 0.2;
uniform vec3 color;
uniform float metalness;
uniform float roughness;
uniform vec3 lightPos;
uniform vec3 lightColor;
in vec3 viewDirTS;
in vec3 lightDirTS;
in vec3 worldPos;
out vec4 outColor;
in mat3 TBN;
void main()
{
vec3 normal = normalize(TBN * vec3(0, 0, 1)); // Normal z TBN
vec3 L = normalize(lightPos - worldPos);
vec3 V = normalize(viewDirTS);
vec3 H = normalize(L + V);
float k = pow((roughness + 1), 2.0) / 8.0;
float D = (roughness * roughness) / (3.14159 * pow(pow(dot(normal, H), 2.0) * (roughness * roughness - 1.0) + 1.0, 2.0));
float G = dot(normal, L) / (dot(normal, L) * (1.0 - k) + k);
vec3 F0 = mix(vec3(0.04), color, metalness);
vec3 F = F0 + (1.0 - F0) * pow(1 - dot(V, H), 5.0);
vec3 specular = lightColor * (D * G * F) / (4 * dot(normal, L) * dot(normal, V) + 0.00001);
vec3 kD = vec3(1.0) - F;
vec3 diffuse = lightColor * kD * (color / 3.1458493);
vec3 finalColor = (diffuse + specular) * min(1.0, AMBIENT + max(dot(normal, L), 0.0));
outColor = vec4(finalColor, 1.0);
}

View File

@ -1,41 +0,0 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec3 worldPos;
out vec2 vecTex;
uniform vec3 lightPos;
uniform vec3 cameraPos;
out vec3 viewDirTS;
out vec3 lightDirTS;
out mat3 TBN;
void main()
{
vec3 tangent = normalize(mat3(modelMatrix) * vertexTangent);
vec3 bitangent = normalize(mat3(modelMatrix) * vertexBitangent);
vec3 normal = normalize(mat3(modelMatrix) * vertexNormal);
mat3 TBN = transpose(mat3(tangent, bitangent, normal));
vec3 worldPos = (modelMatrix * vec4(vertexPosition, 1)).xyz;
vec3 viewDir = normalize(cameraPos - worldPos);
vec3 lightDir = normalize(lightPos - worldPos);
viewDirTS = vec3(TBN * viewDir);
lightDirTS = vec3(TBN * lightDir);
vecTex = vec2((worldPos.x + 10.0) / 20.0, 1.0 - (worldPos.y + 10.0) / 20.0);
gl_Position = transformation * vec4(vertexPosition, 1.0);
}

View File

@ -15,20 +15,15 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
#include <cmath>
#include "SOIL/SOIL.h"
#include <chrono>
#include <sstream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
namespace texture {
GLuint earth;
GLuint clouds;
GLuint moon;
GLuint ship;
GLuint rust;
GLuint sun;
GLuint mars;
@ -45,11 +40,6 @@ namespace texture {
GLuint moonNormal;
GLuint shipNormal;
GLuint rustNormal;
GLuint metalnessSphere;
GLuint roughnessSphere;
GLuint metalnessShip;
GLuint roughnessShip;
}
@ -59,44 +49,31 @@ GLuint programTex;
GLuint programEarth;
GLuint programProcTex;
GLuint programSkyBox;
GLuint programSign;
GLuint programBloom;
GLuint programQuad;
Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext;
Core::RenderContext sphereContext;
Core::RenderContext cubeContext;
Core::RenderContext starContext;
Core::RenderContext saberContext;
Core::RenderContext heartContext;
Core::RenderContext rocketContext;
Core::RenderContext test;
glm::vec3 cameraPos = glm::vec3(-3.f, 0, 0);
glm::vec3 cameraPos = glm::vec3(-4.f, 0, 0);
glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
glm::vec3 spaceshipPos = glm::vec3(-3.f, 0, 0);
glm::vec3 spaceshipPos = glm::vec3(-4.f, 0, 0);
glm::vec3 spaceshipDir = glm::vec3(1.f, 0.f, 0.f);
bool fire = false;
float a = 3;
bool START_AS = false;
float a = 3 ;
std::random_device rd;
std::mt19937 gen(rd());
//std::uniform_real_distribution<float> distribution(-0.5f, 0.5f);
std::uniform_real_distribution<float> radiusDistribution(-6.f, 6.f);
std::uniform_real_distribution<float> planetoidsYDistribution(-5.f, 5.f);
std::uniform_real_distribution<float> planetoidsXDistribution(-2.f, 11.f);
std::uniform_real_distribution<float> planetoidsScaleDistribution(0.2f, 0.3f);
std::vector<glm::vec4> shearVectors;
std::vector<glm::vec3> scaleVectors;
std::vector<glm::vec3> ammunitionPositions;
std::vector<glm::mat4> ammunitionModelMatrices;
const int arraySize = 200;
const int planetoidParams = 5;
std::vector<std::vector<float>> planetoidsVector(arraySize, std::vector<float>(planetoidParams));
float tempPlanArray[200][2];
std::uniform_real_distribution<float> distribution(-0.5f, 0.5f);
std::uniform_real_distribution<float> planetoidsYDistribution(-1.f, 1.f);
std::uniform_real_distribution<float> planetoidsScaleDistribution(0.01f, 0.05f);
float planetoidsArray[500][4];
glm::vec3 asteroid_Calc = spaceshipDir * glm::vec3(a, a, a);
glm::vec3 asteroid_Pos = spaceshipPos + glm::vec3(0, a, 0) + asteroid_Calc;
glm::vec3 distance = asteroid_Pos - spaceshipPos;
@ -104,35 +81,23 @@ glm::vec3 distance = asteroid_Pos - spaceshipPos;
double step = 0.0000001;
GLuint VAO,VBO;
float lastFiretime = 0;
float ammoReloadTime = 3.0f; // Czas ładowania amunicji w sekundach
float ammoReloadProgress = 0.0f;
float lastAsteroidTime = 0;
float aspectRatio = 1.f;
glm::vec3 ammoPos;
unsigned int textureID;
float tiltAngleSide;
float tiltAngleUpDown;
int colission = 3;
int star = 0;
int star_counter = 0;
float starMetalness = 0.8;
float starRoughness = 0.1;
glm::vec3 lightPos = glm::vec3(-8, 4, 2);
glm::vec3 lightColor = glm::vec3(0.9, 0.7, 0.8) * 100;
unsigned int hdrFBO;
GLuint testMap;
glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0);
glm::vec3 spotlightColor = glm::vec3(0.5, 0.9, 0.8) * 10;
float exposition = 1.f;
float spotlightPhi = 3.14 / 3;
unsigned int colorBuffers[2];
int WIDTH = 800;
int HEIGHT = 800;
unsigned int rectVAO, rectVBO;
double easeInExpo(double x) {
return pow(2, 10 * x - 10);
}
glm::mat4 createCameraMatrix()
@ -156,7 +121,7 @@ glm::mat4 createPerspectiveMatrix()
glm::mat4 perspectiveMatrix;
float n = 0.05;
float f = 60.;
float f = 20.;
float a1 = glm::min(aspectRatio, 1.f);
float a2 = glm::min(1 / aspectRatio, 1.f);
perspectiveMatrix = glm::mat4({
@ -172,76 +137,44 @@ glm::mat4 createPerspectiveMatrix()
return perspectiveMatrix;
}
void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float metalness, float roughness, glm::vec3 cameraPos) {
void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color) {
glUseProgram(program);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform3f(glGetUniformLocation(program, "lightPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform1f(glGetUniformLocation(program, "exposition"), exposition);
glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
glUniform1f(glGetUniformLocation(program, "metalness"), metalness);
glUniform1f(glGetUniformLocation(program, "roughness"), roughness);
glUniform3f(glGetUniformLocation(program, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spotlightConeDir.x, spotlightConeDir.y, spotlightConeDir.z);
glUniform3f(glGetUniformLocation(program, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z);
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi);
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform3f(glGetUniformLocation(program, "lightPos"), 0, 0, 0);
Core::DrawContext(context);
}
void drawObjectSigns(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float metalness, float roughness, glm::vec3 lightstarPos) {
glUseProgram(programSign);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programSign, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programSign, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform3f(glGetUniformLocation(programSign, "lightPos"), lightstarPos.x, lightstarPos.y, lightstarPos.z);
glUniform3f(glGetUniformLocation(programSign, "color"), color.x, color.y, color.z);
glUniform3f(glGetUniformLocation(programSign, "lightColor"), lightColor.r, lightColor.g, lightColor.b);
glUniform3f(glGetUniformLocation(programSign, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform1f(glGetUniformLocation(programSign, "metalness"), metalness);
glUniform1f(glGetUniformLocation(programSign, "roughness"), roughness);
// Przesyłanie informacji o widoku (view) do shadera
Core::DrawContext(context);
}
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalMapId, GLuint metalnessTexture, GLuint roughnessTexture) {
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalMapId) {
//glEnable(GL_DEPTH_TEST);
glUseProgram(programTex);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform3f(glGetUniformLocation(programTex, "lightPos"), 0, 0, 0);
Core::SetActiveTexture(normalMapId, "normalSampler", programTex, 1);
Core::SetActiveTexture(textureID, "colorTexture", programTex, 0);
glUniform1i(glGetUniformLocation(programTex, "metalnessTexture"), 2);
glUniform1i(glGetUniformLocation(programTex, "roughnessTexture"), 3);
glUseProgram(programBloom);
glUniform1i(glGetUniformLocation(programBloom, "screenTexture"), 0);
glUniform1i(glGetUniformLocation(programBloom, "bloomTexture"), 1);
glUniform1f(glGetUniformLocation(programBloom, "gamma"), 2.2f);
// Bind metalness and roughness textures to texture units
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, metalnessTexture);
glEnable(GL_DEPTH_TEST);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, roughnessTexture);
glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
Core::DrawContext(context);
//Core::SetActiveTexture(colorBuffers[0], "colorTexture", programQuad, 0);
}
void drawObjectSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
glDisable(GL_DEPTH_TEST);
glUseProgram(programSkyBox);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
@ -256,149 +189,52 @@ void drawObjectSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
}
void drawObjectSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID)
{
glUseProgram(programSun);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform1f(glGetUniformLocation(programSun, "exposition"), 1.f);
Core::SetActiveTexture(textureID, "sunTexture", programSun, 0);
glActiveTexture(GL_TEXTURE0); // Activate texture unit 0
glBindTexture(GL_TEXTURE_2D, textureID);
Core::DrawContext(sphereContext);
}
//void drawObjectBloom(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalMapId) {
//
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glUseProgram(programTex);
// glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
// glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
// glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
// glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
// glUniform3f(glGetUniformLocation(programTex, "lightPos"), 0, 0, 0);
// Core::SetActiveTexture(normalMapId, "normalSampler", programTex, 2);
// Core::SetActiveTexture(textureID, "colorTexture", programTex, 1);
// Core::DrawContext(context);
//
// glUseProgram(programBloom);
// glUniform1i(glGetUniformLocation(programBloom, "screenTexture"), 0);
// glUniform1i(glGetUniformLocation(programBloom, "bloomTexture"), 1);
// glUniform1f(glGetUniformLocation(programBloom, "gamma"), 2.2f);
//
// //Core::DrawContext(context);
//
//
//}
//float speed = 0.03;
float speed = 0.02;
float starind = 50;
bool checkCollision(glm::vec3 objectPos, float objectRadius, glm::vec3 spaceshipPos, float spaceshipRadius, bool isStar) {
float distance = glm::length(objectPos - spaceshipPos);
float starExtraRadius = isStar ? 0.03f : 0.0f;
return distance < objectRadius + spaceshipRadius + starExtraRadius;
void generateAsteroids(glm::vec3 asteroid_Pos, glm::vec3 distance, double step) {
glm::vec3 normalizedDir = glm::normalize(distance);
asteroid_Pos = asteroid_Pos - normalizedDir *step;
drawObjectTexture(sphereContext, glm::translate(asteroid_Pos) * glm::scale(glm::vec3(0.1f)), texture::moon, texture::moonNormal);
}
void generatePlanetoidBelt() {
for (int i = 0; i < 200; ++i) {
float z = tempPlanArray[i][0];
float y = tempPlanArray[i][1];
glm::vec3 Scale = scaleVectors[i];
bool collision = false;
planetoidsVector[i][3] -= speed;
float x = planetoidsVector[i][3];
if (planetoidsVector[i][3] < -3.5f) {
//planetoidsArray[i][0] += spaceshipPos.z - planetoidsArray[i][0];
//planetoidsArray[i][1] += spaceshipPos.y - planetoidsArray[i][1];
tempPlanArray[i][0] = spaceshipPos.z + planetoidsVector[i][0];
tempPlanArray[i][1] = spaceshipPos.y + planetoidsVector[i][1];
planetoidsVector[i][3] = 11.f;
z = tempPlanArray[i][0];
y = tempPlanArray[i][1];
x = planetoidsVector[i][3];
planetoidsVector[i][4] = 0;
}
for (int i = 0; i < 500; ++i) {
float x = planetoidsArray[i][0];
float z = planetoidsArray[i][1];
float y = planetoidsArray[i][2];
float pScale = planetoidsArray[i][3];
if (planetoidsVector[i][4] == 1) {
// Planeta ju<6A> uczestniczy<7A>a w kolizji, przejd<6A> do kolejnej iteracji
continue;
}
float time = glfwGetTime();
for (int j = 0; j < i; ++j) {
float prevZ = tempPlanArray[j][0];
float prevY = tempPlanArray[j][1];
glm::vec3 prevScale = scaleVectors[j];
float prevX = planetoidsVector[j][3];
float dx = x - prevX;
float dy = y - prevY;
float dz = z - prevZ;
float distanceSquared = dx * dx + dy * dy + dz * dz;
float sumRadiiSquared = glm::length2(Scale + prevScale);
if (distanceSquared < sumRadiiSquared) {
collision = true;
break;
}
}
if (!collision) {
if (fmod(i, starind) == 0) {
if (checkCollision(glm::vec3(x, y, z), 0.1f, spaceshipPos, 0.08f, true)) {
// Kolizja z gwiazd<7A>
//std::cout << "Collision with star " << i << std::endl;
planetoidsVector[i][4] = 1;
star_counter++;
if (star_counter == 3) {
exit(0);
}
}
}
else if (checkCollision(glm::vec3(x, y, z), 0.1f, spaceshipPos, 0.08f, true))
{
//kolizja z asteroida
std::cout << "Collision with asteroid " << i << std::endl;
colission--;
planetoidsVector[i][4] = 1;
if (colission == 0)
{
exit(0);
}
}
else
{
for (int n = 0; n < ammunitionPositions.size(); ++n)
{
if (checkCollision(glm::vec3(x, y, z), 0.1f, ammunitionPositions[n], 0.08f, true))
{
// Asteroida zestrzelona
std::cout << "Collision with ammo " << i << std::endl;
planetoidsVector[i][4] = 1;
}
}
}
}
if (!collision) {
if (fmod(i, starind) == 0) {
float time = glfwGetTime();
glm::mat4 modelMatrix = glm::translate(glm::vec3(x, y, z)) * glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 1.0f));
drawObjectColor(starContext, modelMatrix * glm::eulerAngleX(time) * glm::scale(glm::vec3(0.03f)), glm::vec3(0.1, 1.f, 1.0), starMetalness, starRoughness, glm::vec3(x-1, y, z));
if (star == 0)
{
star++;
std::cout << "Star " << star << std::endl;
}
}
else {
float rotationAngle = glm::radians(70*y);
glm::mat4 transformationMatrix = glm::translate(glm::vec3(x, y, z)) *
glm::rotate(glm::mat4(1.0f), rotationAngle, glm::vec3(1.0f, 0.0f, 1.0f)) *
glm::scale(glm::vec3(Scale));
drawObjectTexture(sphereContext, transformationMatrix,
texture::moon, texture::moonNormal, texture::metalnessSphere, texture::roughnessSphere);
}
}
}
drawObjectTexture(sphereContext,glm::eulerAngleY(time / 5) * glm::translate(glm::vec3(x, y, z)) * glm::scale(glm::vec3(pScale)), texture::moon, texture::moonNormal);
}
}
int steps = 0;
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
@ -408,81 +244,68 @@ glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
0.,0.,0.,1.,
});
void drawStars(int star_number) {
float yOffset = 0.55f + spaceshipPos.y;
float zOffset =5.10f + spaceshipPos.z;
float scaleFactor = 0.03f;
unsigned int quadVAO = 0;
unsigned int quadVBO;
void renderQuad()
{
if (quadVAO == 0)
{
float quadVertices[] = {
// positions // texture coords
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
};
for (int i = 0; i < star_number; ++i) {
drawObjectSigns(starContext, glm::translate(glm::vec3(2.3f, yOffset, (zOffset) - i * 0.5f ))
* glm::rotate(glm::mat4(), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f))
* glm::scale(glm::vec3(scaleFactor)), glm::vec3(0.1, 1.f, 1.0), starMetalness, starRoughness,glm::vec3(1.0f, yOffset, zOffset));
// setup plane VAO
glGenVertexArrays(1, &quadVAO);
glGenBuffers(1, &quadVBO);
glBindVertexArray(quadVAO);
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
}
glBindVertexArray(quadVAO);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
}
void drawHearts(int collision_number) {
float yOffset = -0.5f + spaceshipPos.y;
float zOffset = 6.15 + spaceshipPos.z;
for (int i = 0; i < 5; ++i) {
if (collision_number > i) {
drawObjectSigns(heartContext, glm::translate(glm::vec3(3.5f, yOffset, (zOffset) - i * 0.5f))
* glm::rotate(glm::mat4(), glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f))
* glm::scale(glm::vec3(0.025f)), glm::vec3(1, 0, 0), starMetalness, starRoughness, glm::vec3(1.0f, yOffset, zOffset));
}
}
}
void updateAmmunition() {
if (fire) {
glm::vec3 newAmmoPos = spaceshipPos + glm::vec3(0.025f, 0.f, 0.f);
ammunitionPositions.push_back(newAmmoPos);
fire = false;
}
}
void renderAmmunition() {
for (int i = ammunitionPositions.size() - 1; i >= 0; --i) {
ammunitionPositions[i] = ammunitionPositions[i] + glm::vec3(0.025f, 0.f, 0.f);
if (ammunitionPositions[i].x > 3.f) {
ammunitionPositions.erase(ammunitionPositions.begin() + i);
}
else {
glm::mat4 modelMatrix = glm::translate(ammunitionPositions[i]) * glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(1.0f, 0.0f, 0.f));
drawObjectColor(rocketContext, glm::translate(ammunitionPositions[i]) * glm::rotate(glm::mat4(1.0f), glm::radians(270.f), glm::vec3(0.0f, 1.0f, 0.f)) * glm::scale(glm::vec3(0.003f)), glm::vec3(0.1, 0.1, 0.7), starMetalness, starRoughness, spaceshipPos);
}
}
}
void renderScene(GLFWwindow* window)
{
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
glClearColor(0.0f, 0.f, 0.f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glm::mat4 transformation;
float time = glfwGetTime();
drawObjectSkyBox(cubeContext, glm::translate(cameraPos));
glDepthMask(GL_FALSE);
drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(16.0f, -4.0f, -13.0f)) * glm::scale(glm::mat4(), glm::vec3(2)), texture::sun);
drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(12.0f, -4.2f, -8.0f)) * glm::scale(glm::vec3(0.3f)), texture::earth);
//drawObjectTexture(sphereContext,
// glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(8.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), texture::moon, texture::moonNormal, texture::metalnessSphere, texture::roughnessSphere);
//drawObjectTexture(sphereContext, glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::rust, texture::rustNormal);
drawObjectTexture(sphereContext, glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::sun, texture::rustNormal);
drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(14.f, -4.5, -9.f)) * glm::scale(glm::vec3(0.05f)), texture::mercury);
//drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(9.f, -5.f, -7.0f)) * glm::scale(glm::vec3(0.1f)), texture::mars);
drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(12.f, -2.7f, -5.5f)) * glm::scale(glm::vec3(0.2f)), texture::venus);
drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(4.f, -2.f, 3.0f)) * glm::scale(glm::vec3(0.57f)), texture::jupiter);
drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(15.f, -3.f, 6.0f)) * glm::scale(glm::vec3(0.8f)), texture::saturn);
//drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(13.f, -8.0f, 8.0f)) * glm::scale(glm::vec3(0.6f)), texture::uranus);
drawObjectSun(sphereContext, glm::translate(spaceshipPos + glm::vec3(13.f, 0.f, 7.0f)) * glm::scale(glm::vec3(0.35f)), texture::neptune);
glDepthMask(GL_TRUE);
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(8.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.3f)), texture::earth, texture::earthNormal);
drawObjectTexture(sphereContext,
glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(8.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), texture::moon, texture::moonNormal);
drawObjectTexture(sphereContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.15f)), texture::mercury, texture::rustNormal);
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 4) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.2f)), texture::mars, texture::rustNormal);
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 2) * glm::translate(glm::vec3(6.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.3f)), texture::venus, texture::rustNormal);
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 5) * glm::translate(glm::vec3(14.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.9f)), texture::jupiter, texture::rustNormal);
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 6) * glm::translate(glm::vec3(17.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.9f)), texture::saturn, texture::rustNormal);
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 7) * glm::translate(glm::vec3(20.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.6f)), texture::uranus, texture::rustNormal);
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 8) * glm::translate(glm::vec3(23.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.6f)), texture::neptune, texture::rustNormal);
spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
specshipCameraRotrationMatrix = glm::mat4({
spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
@ -490,42 +313,91 @@ void renderScene(GLFWwindow* window)
0.,0.,0.,1.,
});
drawObjectTexture(shipContext,
glm::translate(spaceshipPos) *
specshipCameraRotrationMatrix *
glm::eulerAngleY(glm::pi<float>()) *
glm::rotate(glm::mat4(), tiltAngleSide * glm::radians(30.0f), glm::vec3(0, 0, 1)) *
glm::rotate(glm::mat4(), tiltAngleUpDown * glm::radians(20.0f), glm::vec3(1, 0, 0)) *
glm::scale(glm::vec3(0.025f)),
texture::ship, texture::shipNormal, texture::metalnessShip, texture::roughnessShip);
//drawObjectTexture(shipContext,
// glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>())*glm::scale(glm::vec3(0.1f)),
// texture::ship, texture::shipNormal
//);
updateAmmunition();
renderAmmunition();
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>())*glm::scale(glm::vec3(0.1f)),
texture::ship, texture::shipNormal
);
generatePlanetoidBelt();
//if (fire == true){
// ammoPos = ammoPos + glm::vec3(0.025f, 0.f, 0.f);
// glm::mat4 modelMatrix = glm::translate(ammoPos) * glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(1.0f, 0.0f, 0.f));
// drawObjectColor(rocketContext, modelMatrix * glm::rotate(glm::mat4(1.0f), glm::radians(270.f), glm::vec3(0.0f, 1.0f, 0.f)) * glm::scale(glm::vec3(0.003f)), glm::vec3(0.1, 0.1, 0.7), starMetalness, starRoughness, spaceshipPos);
// }
glDisable(GL_DEPTH_TEST);
drawStars(star_counter);
drawHearts(colission);
glEnable(GL_DEPTH_TEST);
if (time - lastAsteroidTime < 5 && START_AS) { //funkcja generujaca pierwsza asteroide
step = step + 0.03;
generateAsteroids(asteroid_Pos, distance, step);
//steps++;
//std::cout << steps << std::endl;
}
else {
float random_x = distribution(gen);
float random_y = distribution(gen);
float random_z = distribution(gen);
//std::cout << random_x << std::endl;
glm::vec3 random_dir = glm::normalize(glm::vec3(spaceshipDir.x + random_x, spaceshipDir.y + random_y, spaceshipDir.z + random_z));
asteroid_Calc = a * random_dir;
glm::vec3 estimated_Spaceship_Pos = spaceshipPos + glm::vec3(1.f, 1.f, 1.f) * glm::normalize(spaceshipDir);
asteroid_Pos = spaceshipPos + glm::vec3(0, a / 5, 0) + asteroid_Calc;
distance = asteroid_Pos - estimated_Spaceship_Pos;
lastAsteroidTime = time;
step = 0.0001;
//std::cout << cameraDir.x << cameraDir.y << cameraDir.z << std::endl;
//steps = 0;
}
glUseProgram(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programQuad);
//Core::SetActiveTexture(colorBuffers[0], "colorTexture", programQuad, 0);
//Core::SetActiveTexture(colorBuffers[1], "highlightTexture", programQuad, 1);
glUniform1i(glGetUniformLocation(programQuad, "originalTexture"), 0);
glUniform1i(glGetUniformLocation(programQuad, "bloomTexture"), 1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, colorBuffers[1]);
renderQuad();
//Core::DrawContext(test);
//glBindTexture(GL_TEXTURE_2D, 0);
//glUseProgram(0);
glfwSwapBuffers(window);
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
//// Draw the framebuffer rectangle
//glUseProgram(programQuad);
////glBindVertexArray(rectVAO);
////Core::DrawContext(test);
//renderQuad();
//glDisable(GL_DEPTH_TEST); // prevents framebuffer rectangle from being discarded
////glActiveTexture(GL_TEXTURE0);
////glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
////glActiveTexture(GL_TEXTURE1);
////glBindTexture(GL_TEXTURE_2D, colorBuffers[1]);
////glDrawArrays(GL_TRIANGLES, 0, 6);
//Core::SetActiveTexture(colorBuffers[0], "colorTexture", programQuad, 0);
//Core::SetActiveTexture(colorBuffers[1], "highlightTexture", programQuad, 1);
//glUseProgram(0);
//glfwSwapBuffers(window);
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
aspectRatio = static_cast<float>(width) / static_cast<float>(height);
//aspectRatio = static_cast<float>(width) / static_cast<float>(height);
//glViewport(0, 0, width, height);
aspectRatio = width / float(height);
glViewport(0, 0, width, height);
WIDTH = 800;
HEIGHT = 800;
}
void loadModelToContext(std::string path, Core::RenderContext& context)
{
@ -543,29 +415,30 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
void init(GLFWwindow* window)
{
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glEnable(GL_DEPTH_TEST);
program = shaderLoader.CreateProgram("shaders/shader_5_1.vert", "shaders/shader_5_1.frag");
programTex = shaderLoader.CreateProgram("shaders/shader_5_tex.vert", "shaders/shader_5_tex.frag");
programEarth = shaderLoader.CreateProgram("shaders/shader_5_tex.vert", "shaders/shader_5_tex.frag");
programProcTex = shaderLoader.CreateProgram("shaders/shader_5_tex.vert", "shaders/shader_5_tex.frag");
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_5_sun.vert", "shaders/shader_5_sun.frag");
programSign = shaderLoader.CreateProgram("shaders/signs.vert", "shaders/signs.frag");
programQuad = shaderLoader.CreateProgram("shaders/shader_quad.vert", "shaders/shader_quad.frag");
programBloom = shaderLoader.CreateProgram("shaders/shader_bloom.vert", "shaders/shader_bloom.frag");
loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/spaceship_new.obj", shipContext);
loadModelToContext("./models/spaceship.obj", shipContext);
loadModelToContext("./models/cube.obj", cubeContext);
loadModelToContext("./models/estrellica.obj", starContext);
loadModelToContext("./models/CraneoOBJ.obj", saberContext);
loadModelToContext("./models/heart.obj", heartContext);
loadModelToContext("./models/rocket.obj", rocketContext);
texture::earth = Core::LoadTexture("textures/earth.png");
texture::ship = Core::LoadTexture("textures/ship/spaceship_color.jpg");
texture::ship = Core::LoadTexture("textures/spaceship.jpg");
texture::moon = Core::LoadTexture("textures/moon.jpg");
texture::rust = Core::LoadTexture("textures/rust.jpg");
texture::sun = Core::LoadTexture("textures/2k_sun.jpg");
texture::mars = Core::LoadTexture("textures/2k_mars.jpg");
texture::mercury = Core::LoadTexture("textures/2k_mercury.jpg");
texture::venus = Core::LoadTexture("textures/2k_venus_surface.jpg");
@ -573,46 +446,84 @@ void init(GLFWwindow* window)
texture::saturn = Core::LoadTexture("textures/8k_saturn.jpg");
texture::uranus = Core::LoadTexture("textures/2k_uranus.jpg");
texture::neptune = Core::LoadTexture("textures/2k_neptune.jpg");
texture::sun = Core::LoadTexture("textures/2k_sun.jpg");
texture::earthNormal = Core::LoadTexture("textures/earth_normalmap.png");
texture::shipNormal = Core::LoadTexture("textures/ship/spaceship_nmap.jpg");
texture::shipNormal = Core::LoadTexture("textures/spaceship_normal.jpg");
texture::rustNormal = Core::LoadTexture("textures/rust_normal.jpg");
texture::moonNormal = Core::LoadTexture("textures/moon_normal.jpg");
texture::metalnessSphere = Core::LoadTexture("textures/rusty_metal_sheet_diff_2k.jpg");
texture::roughnessSphere = Core::LoadTexture("textures/rough_concrete_diff_1k.jpg");
loadModelToContext("./models/test.obj", test);
texture::metalnessShip = Core::LoadTexture("textures/ship/spaceship_metalness.jpg");
texture::roughnessShip = Core::LoadTexture("textures/ship/spaceship_rough.jpg");
for (int i = 0; i < 200; ++i) {
float z = radiusDistribution(gen);
float x = planetoidsXDistribution(gen);
float y = planetoidsYDistribution(gen);
planetoidsVector[i][0] = z;
planetoidsVector[i][1] = y;
planetoidsVector[i][3] = x;
glm::vec3 scaleVector = glm::vec3(planetoidsScaleDistribution(gen), planetoidsScaleDistribution(gen), planetoidsScaleDistribution(gen));
scaleVectors.push_back(scaleVector);
}
const int arraySize = 200;
const int planetoidParams = 5;
std::sort(planetoidsVector.begin(), planetoidsVector.end(),
[](const auto& a, const auto& b) {
return a[3] < b[3];
});
for (int i = 0; i < arraySize; ++i) {
tempPlanArray[i][0] = planetoidsVector[i][0];
tempPlanArray[i][1] = planetoidsVector[i][1];
}
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
//const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glGenFramebuffers(1, &hdrFBO);
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
glGenTextures(2, colorBuffers);
for (unsigned int i = 0; i < 2; i++)
{
glBindTexture(GL_TEXTURE_2D, colorBuffers[i]);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA16F,WIDTH, HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, colorBuffers[i], 0
);
}
unsigned int attachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
glDrawBuffers(2, attachments);
float rectangleVertices[] =
{
// Coords // texCoords
1.0f, -1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 1.0f
};
glGenVertexArrays(1, &rectVAO);
glGenBuffers(1, &rectVBO);
glBindVertexArray(rectVAO);
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(rectangleVertices), &rectangleVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
std::uniform_real_distribution<float> angleDistribution(0.0f, 2.0f * glm::pi<float>());
std::uniform_real_distribution<float> radiusDistribution(10.f, 17.f);
for (int i = 0; i < 500; ++i) {
float angle = angleDistribution(gen);
float radius = radiusDistribution(gen);
float y = planetoidsYDistribution(gen);
float pScale = planetoidsScaleDistribution(gen);
planetoidsArray[i][0] = radius * std::cos(angle);
planetoidsArray[i][1] = radius * std::sin(angle);
planetoidsArray[i][2] = y;
planetoidsArray[i][3] = pScale;
}
std::vector<std::string> filepaths = {
"textures/skybox/space_rt.png",
"textures/skybox/space_lf.png",
@ -639,6 +550,7 @@ void init(GLFWwindow* window)
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
}
void shutdown(GLFWwindow* window)
@ -649,82 +561,65 @@ void shutdown(GLFWwindow* window)
double lastX = 0.0;
double lastY = 0.0;
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) {
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
fire = true;
ammoPos = spaceshipPos;
lastFiretime = glfwGetTime();
}
void mouseCallback(GLFWwindow* window, double xpos, double ypos) {
double deltaX = xpos - lastX;
double deltaY = ypos - lastY;
lastX = xpos;
lastY = ypos;
//std::cout << lastY << " " << ypos << std::endl;
const float sensitivity = 0.001f;
deltaX *= sensitivity;
deltaY *= sensitivity;
glm::mat4 rotationMatrix = glm::eulerAngleY(-deltaX);
spaceshipDir = glm::normalize(rotationMatrix * glm::vec4(spaceshipDir,0));
spaceshipDir = spaceshipDir + glm::vec3(0, - deltaY / 4, 0);
/*specshipCameraRotrationMatrix = glm::rotate(specshipCameraRotrationMatrix, static_cast<float>(deltaX), glm::vec3(0.f, 1.f, 0.f));
specshipCameraRotrationMatrix = glm::rotate(specshipCameraRotrationMatrix, static_cast<float>(deltaY), spaceshipSide);
spaceshipDir = glm::normalize(glm::vec3(-specshipCameraRotrationMatrix[2]));
spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));*/
}
//obsluga wejscia
void processInput(GLFWwindow* window)
{
spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
float angleSpeed = 0.005f;
float moveSpeed = 0.01f;
double x = 0.01;
float angleSpeed = 0.01f;
float moveSpeed = 0.01f;
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
spaceshipPos += glm::vec3(0.f,moveSpeed,0.f);
tiltAngleUpDown -= easeInExpo(x);
}
else {
if (tiltAngleUpDown < 0) {
tiltAngleUpDown += 0.003;
}
}
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS){
spaceshipPos -= glm::vec3(0.f, moveSpeed, 0.f);
tiltAngleUpDown += easeInExpo(x);
}
else {
if (tiltAngleUpDown > 0) {
tiltAngleUpDown -= 0.003;
}
}
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
spaceshipPos += spaceshipDir * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
spaceshipPos -= spaceshipDir * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
spaceshipPos += spaceshipSide * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
spaceshipPos -= spaceshipSide * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
spaceshipPos += spaceshipUp * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
spaceshipPos -= spaceshipUp * moveSpeed;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
if (glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS)
START_AS = true;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
spaceshipPos -= glm::vec3(0.f, 0.f, moveSpeed);
tiltAngleSide -= easeInExpo(x);
} else {
if (tiltAngleSide < 0) {
tiltAngleSide += 0.003;
}
}
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
spaceshipPos += glm::vec3(0.f, 0.f, moveSpeed);
tiltAngleSide += easeInExpo(-x);
} else {
if (tiltAngleSide > 0) {
tiltAngleSide -= 0.003;
}
}
//glfwSetCursorPosCallback(window, mouseCallback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
cameraPos = spaceshipPos - 0.5 * spaceshipDir+ glm::vec3(0.f,0.3,0.f);
//cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 2, 0) * 0.1f;
//cameraDir = spaceshipDir;
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
cameraDir = spaceshipDir;
tiltAngleSide = fmaxf(-1, fminf(1, tiltAngleSide));
tiltAngleUpDown = fmaxf(-1, fminf(1, tiltAngleUpDown));
//cameraDir = glm::normalize(-cameraPos);
}

View File

@ -23,8 +23,8 @@ int main(int argc, char** argv)
#endif
// tworzenie okna za pomoca glfw
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "FirstWindow", NULL, NULL);
//const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
GLFWwindow* window = glfwCreateWindow(800, 800, "FirstWindow", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
@ -35,7 +35,7 @@ int main(int argc, char** argv)
// ladowanie OpenGL za pomoca glew
glewInit();
glViewport(0, 0, mode->width, mode->width);
glViewport(0, 0, 800, 800);
init(window);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1018 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 MiB