>::const_iterator g = m.faces.begin(); g != m.faces.end(); ++g){
+ out << g->first << " ";
+ }
+ out << "\n";
+// for(int i = 0; i < m.face.size(); ++i)
+// out << m.face[i] << (((i % 3) == 2)?"\n":"\t");
+ }
+ return out;
+}
+
+} // namespace obj
+
+#endif // OBJLOAD_H_
diff --git a/cw 3/style.css b/cw 3/style.css
new file mode 100644
index 0000000..cf42427
--- /dev/null
+++ b/cw 3/style.css
@@ -0,0 +1,107 @@
+html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
+
+body{
+color:#444;
+font-family:Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
+font-size:12px;
+line-height:1.5em;
+padding:1em;
+margin:auto;
+max-width:42em;
+background:#fefefe;
+}
+
+a{ color: #0645ad; text-decoration:none;}
+a:visited{ color: #0b0080; }
+a:hover{ color: #06e; }
+a:active{ color:#faa700; }
+a:focus{ outline: thin dotted; }
+a:hover, a:active{ outline: 0; }
+
+::-moz-selection{background:rgba(255,255,0,0.3);color:#000}
+::selection{background:rgba(255,255,0,0.3);color:#000}
+
+a::-moz-selection{background:rgba(255,255,0,0.3);color:#0645ad}
+a::selection{background:rgba(255,255,0,0.3);color:#0645ad}
+
+p{
+margin:1em 0;
+}
+
+img{
+max-width:100%;
+}
+
+h1,h2,h3,h4,h5,h6{
+font-weight:normal;
+color:#111;
+line-height:1em;
+}
+h4,h5,h6{ font-weight: bold; }
+h1{ font-size:2.5em; }
+h2{ font-size:2em; }
+h3{ font-size:1.5em; }
+h4{ font-size:1.2em; }
+h5{ font-size:1em; }
+h6{ font-size:0.9em; }
+
+blockquote{
+color:#666666;
+margin:0;
+padding-left: 3em;
+border-left: 0.5em #EEE solid;
+}
+hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa;border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; }
+pre, code, kbd, samp { color: #000; font-family: monospace, monospace; _font-family: 'courier new', monospace; font-size: 0.98em; }
+pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; }
+
+b, strong { font-weight: bold; }
+
+dfn { font-style: italic; }
+
+ins { background: #ff9; color: #000; text-decoration: none; }
+
+mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; }
+
+sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
+sup { top: -0.5em; }
+sub { bottom: -0.25em; }
+
+ul, ol { margin: 1em 0; padding: 0 0 0 2em; }
+li p:last-child { margin:0 }
+dd { margin: 0 0 0 2em; }
+
+img { border: 0; -ms-interpolation-mode: bicubic; vertical-align: middle; }
+
+table {
+border-collapse: collapse;
+border-spacing: 0;
+width: 100%;
+}
+th { border-bottom: 1px solid black; }
+td { vertical-align: top; }
+
+@media only screen and (min-width: 480px) {
+body{font-size:14px;}
+}
+
+@media only screen and (min-width: 768px) {
+body{font-size:16px;}
+}
+
+@media print {
+ * { background: transparent !important; color: black !important; filter:none !important; -ms-filter: none !important; }
+ body{font-size:12pt; max-width:100%;}
+ a, a:visited { text-decoration: underline; }
+ hr { height: 1px; border:0; border-bottom:1px solid black; }
+ a[href]:after { content: " (" attr(href) ")"; }
+ abbr[title]:after { content: " (" attr(title) ")"; }
+ .ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
+ pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; }
+ tr, img { page-break-inside: avoid; }
+ img { max-width: 100% !important; }
+ @page :left { margin: 15mm 20mm 15mm 10mm; }
+ @page :right { margin: 15mm 10mm 15mm 20mm; }
+ p, h2, h3 { orphans: 3; widows: 3; }
+ h2, h3 { page-break-after: avoid; }
+}
\ No newline at end of file
diff --git a/cw 3/zadania 3.html b/cw 3/zadania 3.html
new file mode 100644
index 0000000..37c9295
--- /dev/null
+++ b/cw 3/zadania 3.html
@@ -0,0 +1,165 @@
+
+
+
+
+
+
+ zadania 3
+
+
+
+
+
+
+Ćwiczenia 3
+Przestrzenie potoku graficznego
+W trakcie wykładu zostały opisane kolejne przestrzenie potoku graficznego. W tej części zajęć przejdziemy kolejne jego etapy.
+
+Pierwszy krok, czyli przejście do World Space
już wykonujemy za pomocą macierzy transformacji. Następnym krokiem będzie stworzenie macierzy projekcji i macierzy widoku. Zaczniemy od macierzy projekcji. Będziemy modyfikować macierz, którą wysyła funkcja createPerspectiveMatrix
(macierz jest transponowana dalej, więc zapisuj ją tak, jak tu widzisz). Zanim zaczniemy domnóż macierz perspektywy do macierzy transformacji obiektów.
+Nim przejdziemy dalej odkomentuj rysowanie prostopadłościanu.
+Macierz perspektywy
+Rozważmy mnożenie dowolnej macierzy przez wektor kolumnowy:
+\[\begin{bmatrix} m_{11} & m_{12} & m_{13}& m_{14}\\m_{21} & m_{22} & m_{23}& m_{24}\\m_{31} & m_{32} & m_{33}& m_{34}\\m_{41} & m_{42} & m_{43}& m_{44}\\\end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ w \end{bmatrix}=\begin{bmatrix} x*m_{11}+y*m_{12}+z*m_{13}+m_{14}\\x*m_{21} +y*m_{22} +z*m_{23} +m_{24}\\x*m_{31} +y*m_{32} +z*m_{33} +m_{34}\\x*m_{41} +y*m_{42} +z*m_{43} +m_{44}\\\end{bmatrix}\]
+Pierwszym krokiem jest wykorzystanie homogenizacji do uzyskania efektu perspektywy. W tym celu musimy ustawić współrzędną \(w\) na \(-z\) za pomocą macierzy. Jeśli przyjrzymy się obliczeniom powyżej. Zobaczymy, że do tego musimy ustawić \(m_{43}\) na \(-1\) a pozostałe w tym wierszu na \(0\). Przemnożenie daje nam:
+\[\begin{bmatrix} 1 & 0 & 0& 0\\0 & 1 & 0& 0\\0 & 0 & 1& 0\\0 & 0 & -1& 0 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}=\begin{bmatrix} x \\ y \\ z \\ -z\end{bmatrix}\]
+Po homogenizacji otrzymamy wektor:
+\[\begin{bmatrix} -\frac{x}{z} \\ -\frac{x}{z} \\ -1 \\ 1\end{bmatrix}\]
+
+Zadanie
+zmodyfikuj macierz perspektywy w taki sposób.
+
+Wartość współrzędnej \(z\) jest równa -1 dla każdego parametru. Co spowoduje, że nie będzie wiadomo, który wierzchołek bliżej, a który dalej i otrzymam zjawisko znane jako z-fighting. By tego uniknąć. Musimy zmapować współrzędną \(z\). Przypomnijmy, że przy arbitralnej macierzy wartość współrzędnej \(z\) będzie następującej postaci:
+\[ x*m_{31} +y*m_{32} +z*m_{33} +m_{34} \]
+więc możemy pracować tylko z parametrami \(m_{33}\) i \(m_{34}\), czyli \(z*m_{33} +m_{34}\), po uwzględnieniu dodatkowo homogenizacji otrzymamy ostateczny wzór:
+\[ z'=-m_{33} -\frac{m_{34}}{z}.\]
+Przypomnijmy, że w Clipping Space
współrzędna \(z\) musi się mapować na wartości od \(-1\) do \(1\), żeby znalazły się w bryle kanonicznej (obiekty poza bryłą kanoniczną nie będą wyświetlone). Jak na wykładzie określimy sobie parametry \(0 < n < f\), które będą określać pozycję minimalnej i maksymalnej płaszczyzny osi \(z\). Chcemy, żeby dla \(z=n\) wartość \(z'\) wynosiła \(-1\) oraz dla \(z=f\) wartość \(z'\) wynosiła \(1\), daje nam to układ równań:
+\[\begin{matrix} -m_{33}& -&\frac{m_{34}}{n}&=&-1\\-m_{33} &-&\frac{m_{34}}{f}&=&1\end{matrix}\]
+co po przekształceniu da nam:
+\[\begin{matrix} m_{33}&=&\frac{(n + f)}{(n - f)}\\m_{34} &=&\frac{(2 n f)}{(n - f)}\end{matrix}\]
+Ostatecznie otrzymujemy:
+\[\begin{bmatrix} 1 & 0 & 0& 0\\0 & 1 & 0& 0\\0 & 0 & \frac{(n + f)}{(n - f)}& \frac{(2 n f)}{(n - f)}\\0 & 0 & -1& 0 \end{bmatrix}\]
+Zauważ, że te wartość zmienia się zgodnie ze wzorem \(-\left(\frac{(n + f)}{(n - f)}+ \frac{(2 n f)}{z(n - f)}\right)\) czyli zmienia się to asymptotycznie, co można zobaczyć na wykresie.
+
+Zadanie*
+Rozwiąż samodzielnie ten układ równań.
+Zadanie
+Dodaj zmienne lokalne n
i f
w funkcji, ustal im jakieś arbitralne wartości i dodaj rzutowanie \(z\) zgodnie ze wzorem, który otrzymaliśmy. Spróbuj ustawić taką wartość f
, żeby tylna ściana sześcianu zniknęła.
+Uzyskana macierz daje nam rzutowanie perspektywiczne, ale możemy ją jeszcze rozbudować o zmianę kąta widzenia, a także naprawić problem z nieprawidłowym skalowaniem się ekranu przy zmianie jego proporcji. Obie te czynności sprowadzają się do tego samego, mianowicie chcemy zmienić kształt bryły widzenia w osiach \(x\) i \(y\). By tego dokonać, musimy zmienić wartość parametrów \(m_{11}\) i \(m_{22}\), to one odpowiadają za skalowanie w tych osiach. Parametry te ściskają lub rozszerzają przestrzeń w tych osiach, więc zmniejszenie wartości zwiększy kąt widzenia w danej osi.
+Zacznijmy od kąta widzenia. Można go zmienić zwyczajnie ustawiając zamiast \(1\) dowolną inną wartość \(S\) parametrów \(m_{11}\) i \(m_{22}\). Jednak jeśli chcemy uzyskać faktyczne parametry oparte na polu widzenia, musimy skorzystać ze wzoru:
+\[S=\frac{1}{\tan(\frac{fov}{2}*\frac{\pi}{180})}\]
+Zadanie
+Dodaj do createPerspectiveMatrix
argument fov, który będzie ustalał kąt widzenia.
+Zadanie
+Prawidłowe skalowanie okna uzyskamy poprzez mnożenie \(m_{22}\) przez stosunek szerokości do wysokości ekranu. W zadaniu jest zmienna globalna aspectRatio
. W funkcji framebuffer_size_callback
nadpisz tą zmienną właściwym stosunkiem (pamiętaj, że dzielenie liczb stałoprzecinkowych w c++ nie uwzględnia ułamków). Następnie prześlij ja do createPerspectiveMatrix
jako dodatkowy parametr i wykorzystaj przy renderowaniu sceny.
+
+Zadanie*
+Po dodaniu skalowania okna, poszerzanie kwadratowego okna będzie zmniejszać kąt widzenia na osi pionowej. Natomiast wydłużanie go będzie go zwiększać. Zaproponuj rozwiązanie, które sprawi, że poszerzanie kwadratowego okna będzie zwiększać kąt widzenia w osi poziomej i jednocześnie wydłużanie kwadratowego okna będzie zwiększać kąt widzenia w osi pionowej.
+Macierz widoku
+Celem macierzy widoku jest wprowadzenie pojęcia kamery, jako obiektu, który możemy ustawić i poruszać nim w przestrzeni. Na taką macierz składa się pozycja kamery kierunek patrzenia oraz jej orientacja: wektory cameraDir
oraz cameraUp
i cameraSide
. W tym celu potrzebujemy jeden wektor, który będzie określał pozycję początku układu współrzędnych (czyli pozycję kamery). Oraz 3 wektory ortonormalne, które będą rozpinać przestrzeń (odpowiedzialne za kierunek i orientację). Ponieważ te wektory są ortogonalne, możemy je rekonstruować za pomocą dwóch wektorów, jeden będzie nam wskazywać kierunek patrzenia (cameraDir
), drugi górę (cameraUp
).
+
+
+Układ współrzędnych kamery
+
+W kodzie jest zaimplementowana obsługa klawiatury, klawisze W i S przesuwają kamerę do przodu i do tyłu, natomiast A i D obracają ją na boki. Robią to poprzez modyfikacje zmiennych globalnych cameraDir
i cameraPos
, jednak, żeby kamera faktycznie działała, trzeba uzupełnić funkcję createCameraMatrix
i dodać jej wynik do transformacji obiektów.
+Zadanie
+Uzupełnij funkcję createCameraMatrix
. Najpierw oblicz wektor skierowany w bok za pomocą iloczynu wektorowego między cameraDir
a wektorem \([0,1,0]\). Wektor może być długości innej niż 1, dlatego znormalizuj go. Zapisz wynik do cameraSide
. Podobnie oblicz cameraUp
jako znormalizowany iloczyn wektorowy między cameraSide
i cameraDir
.
+
+Wektor normalizuje się za pomocą funkcji: glm::normalize
+
+Macierz kamery złożona jest z iloczynu macierzy obrotu i macierzy translacji. By otrzymać pierwszą z nich, korzystamy z ortonormalności bazy, dzięki temu wystarczy zapisać wektory cameraSide
, cameraUp
i -cameraDir
wierszami. >Zauważ, że cameraDir
musi być odwrócony tak jak na obrazku, ma być zwrócony do kamery, nie od niej. Macierz wygląda następująco:
+\[M_{VR}=\begin{bmatrix} cameraSide_x & cameraSide_y & cameraSide_z & 0\\cameraUp_x & cameraUp_y & cameraUp_z & 0\\-cameraDir_x & -cameraDir_y & -cameraDir_z & 0\\0 & 0 & 0 & 1 \end{bmatrix}\]
+Macierz translacji \(M_{VT}\) otrzymujemy przez translacje o -cameraPos
. Ostatecznie macierz widoku jest postaci \[M_V=M_{VR}*M_{VT}\]
+W macierzy transformation
umieść pomnożone przez siebie macierze perspektywy (wynik funkcji createPerspectiveMatrix
) i kamery (wynik funkcji createCameraMatrix
) w odpowiedniej kolejności. Jako efektem otrzymamy pełen potok graficzny, czyli kamerę, którą możemy poruszać klawiszami, z poprawnym rzutowaniem perspektywicznym.
+Zadanie
+Wyświetl dwa dodatkowe prostopadłościany w różnych pozycjach i orientacjach.
+Zadanie*
+Zmodyfikuj ustawienia tak, żeby kamera zawsze była zwrócona w punkt wybrany punkt \(p\) \((0,0,0)\). W funkcji processInput
zakomentuj obsługę klawiszy A i D. Zamiast tego na końcu tej funkcji ustaw cameraDir
jako znormalizowana różnicę między punktem \(p\) a cameraPos
. Jako obsługę klawiszy R i F dodaj przesuwanie kamery w górę i w dół.
+Ładowanie modeli z użyciem assimp**
+W tym zadaniu przećwiczymy ładowanie modeli z plików, wykorzystamy do tego bibliotekę assimp (The Open Asset Import Library ), która zapewnia wspólny interfejs dla różnych typów plików.
+Funkcja loadModelToContext
pobiera ścieżkę do pliku z modelem i wczytuje go przy użyciu importera assimp.
+const aiScene* scene = import.ReadFile(path, aiProcess_TriangulateaiProcess_Triangulate | aiProcess_CalcTangentSpace);
+Importer przyjmuje ścieżkę i flagi preprocesingu, które mówią, jakie operacje ma wykonać importer przed przekazaniem nam pliku. W naszym przypadku dokonuje triangularyzacji (zamienia wszystkie wielokąty na trójkąty) i oblicza przestrzeń styczną (o której będzie mowa później).
+
+Wywołaj funkcję dla ścieżki do statku ./models/spaceship.obj i zmiennej globalnej Core::RenderContext sphereContext
. Dodaj breakpoint po załadowaniu sceny i obejrzyj jak wygląda struktura załadowanego obiektu.
+
+Załadowany obiekt posiada szereg pól jak na przykład tekstury, oświetlenia, materiały, węzły (Node) czy modele. Węzły odpowiadają za hierarchię elementów w modelu, co ułatwia jego animację, wykorzystamy to w późniejszych zajęciach. Nasze pliki składają się z tylko jednego modelu, dlatego nie musimy się na tym skupiać i wywołujemy tylko pierwszy model, do którego odwołujemy się za pomocą scene->mMeshes[0]
. Wywołaj context.initFromAiMesh
z nim jako argumentem.
+Zadanie**
+Jeśli tego nie zrobiłeś wywołaj metodę context.initFromAiMesh
z argumentemscene->mMeshes[0]
w funkcji init
, po wczytaniu modelu. Metoda nie jest kompletna, uzupełnij ją o ładowanie indeksów, wierzchołków, normalnych i współrzędnych tekstur do bufora. Współrzędne tekstur i indeksy zostały przekonwertowane do odpowiedniego formatu i znajdują się w zmiennych std::vector<aiVector2D> textureCoord
i std::vector<unsigned int> indices
odpowiednio. Pozostałe są dostępne jako atrybuty aiMesh
, mianowicie mesh->mVertices
zawiera wierzchołki a mesh->mNormals
normalne.
+Dodatkowo mesh->mNumVertices
zawiera liczbę wierzchołków.
+zawierają rozmiary buforów.
+Utwórz jedną duża tablicę/vector, która zawiera informacje o wierzchołkach, normalnych i współrzędnych tekstur. Powinna mieć ona format jak na poniższym obrazku:
+
+Gdy załadujesz kontekst, wykorzystaj w renderScene
funkcję Core::DrawContext(Core::RenderContext& context)
do narysowania obiektów. Rozmieść statek i kulę w przestrzeni za pomocą macierzy transformacji i obrotu.
+
+
diff --git a/cw 3/zadania 3.md b/cw 3/zadania 3.md
new file mode 100644
index 0000000..719b4ac
--- /dev/null
+++ b/cw 3/zadania 3.md
@@ -0,0 +1,162 @@
+# Ćwiczenia 3
+## Przestrzenie potoku graficznego
+W trakcie wykładu zostały opisane kolejne przestrzenie potoku graficznego.
+W tej części zajęć przejdziemy kolejne jego etapy.
+
+![](./img/coordinate_systems.jpg)
+
+
+Pierwszy krok, czyli przejście do `World Space` już wykonujemy za pomocą macierzy transformacji. Następnym krokiem będzie stworzenie macierzy projekcji i macierzy widoku. Zaczniemy od macierzy projekcji. Będziemy modyfikować macierz, którą wysyła funkcja `createPerspectiveMatrix` (macierz jest transponowana dalej, więc zapisuj ją tak, jak tu widzisz). Zanim zaczniemy domnóż macierz perspektywy do macierzy transformacji obiektów.
+
+**Nim przejdziemy dalej odkomentuj rysowanie prostopadłościanu.**
+
+## Macierz perspektywy
+
+Rozważmy mnożenie dowolnej macierzy przez wektor kolumnowy:
+
+$$\begin{bmatrix} m_{11} & m_{12} & m_{13}& m_{14}\\m_{21} & m_{22} & m_{23}& m_{24}\\m_{31} & m_{32} & m_{33}& m_{34}\\m_{41} & m_{42} & m_{43}& m_{44}\\\end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ w \end{bmatrix}=\begin{bmatrix} x*m_{11}+y*m_{12}+z*m_{13}+m_{14}\\x*m_{21} +y*m_{22} +z*m_{23} +m_{24}\\x*m_{31} +y*m_{32} +z*m_{33} +m_{34}\\x*m_{41} +y*m_{42} +z*m_{43} +m_{44}\\\end{bmatrix}$$
+
+Pierwszym krokiem jest wykorzystanie homogenizacji do uzyskania efektu perspektywy. W tym celu musimy ustawić współrzędną $w$ na $-z$ za pomocą macierzy. Jeśli przyjrzymy się obliczeniom powyżej. Zobaczymy, że do tego musimy ustawić $m_{43}$ na $-1$ a pozostałe w tym wierszu na $0$. Przemnożenie daje nam:
+
+
+$$\begin{bmatrix} 1 & 0 & 0& 0\\0 & 1 & 0& 0\\0 & 0 & 1& 0\\0 & 0 & -1& 0 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}=\begin{bmatrix} x \\ y \\ z \\ -z\end{bmatrix}$$
+
+
+Po homogenizacji otrzymamy wektor:
+
+
+$$\begin{bmatrix} -\frac{x}{z} \\ -\frac{x}{z} \\ -1 \\ 1\end{bmatrix}$$
+
+
+----
+
+### Zadanie
+zmodyfikuj macierz perspektywy w taki sposób.
+
+----
+
+Wartość współrzędnej $z$ jest równa -1 dla każdego parametru. Co spowoduje, że nie będzie wiadomo, który wierzchołek bliżej, a który dalej i otrzymam zjawisko znane jako z-fighting. By tego uniknąć. Musimy zmapować współrzędną $z$.
+Przypomnijmy, że przy arbitralnej macierzy wartość współrzędnej $z$ będzie następującej postaci:
+
+$$ x*m_{31} +y*m_{32} +z*m_{33} +m_{34} $$
+
+więc możemy pracować tylko z parametrami $m_{33}$ i $m_{34}$, czyli $z*m_{33} +m_{34}$, po uwzględnieniu dodatkowo homogenizacji otrzymamy ostateczny wzór:
+
+$$ z'=-m_{33} -\frac{m_{34}}{z}.$$
+
+Przypomnijmy, że w `Clipping Space` współrzędna $z$ musi się mapować na wartości od $-1$ do $1$, żeby znalazły się w bryle kanonicznej (obiekty poza bryłą kanoniczną nie będą wyświetlone). Jak na wykładzie określimy sobie parametry $0 < n < f$, które będą określać pozycję minimalnej i maksymalnej płaszczyzny osi $z$. Chcemy, żeby dla $z=n$ wartość $z'$ wynosiła $-1$ oraz dla $z=f$ wartość $z'$ wynosiła $1$, daje nam to układ równań:
+
+
+$$\begin{matrix} -m_{33}& -&\frac{m_{34}}{n}&=&-1\\-m_{33} &-&\frac{m_{34}}{f}&=&1\end{matrix}$$
+
+co po przekształceniu da nam:
+
+
+$$\begin{matrix} m_{33}&=&\frac{(n + f)}{(n - f)}\\m_{34} &=&\frac{(2 n f)}{(n - f)}\end{matrix}$$
+
+Ostatecznie otrzymujemy:
+
+$$\begin{bmatrix} 1 & 0 & 0& 0\\0 & 1 & 0& 0\\0 & 0 & \frac{(n + f)}{(n - f)}& \frac{(2 n f)}{(n - f)}\\0 & 0 & -1& 0 \end{bmatrix}$$
+
+
+
+ Zauważ, że te wartość zmienia się zgodnie ze wzorem $-\left(\frac{(n + f)}{(n - f)}+ \frac{(2 n f)}{z(n - f)}\right)$ czyli zmienia się to asymptotycznie, co można zobaczyć na wykresie.
+
+![](./img/z_depth_graph.jpg)
+
+
+
+
+### Zadanie*
+Rozwiąż samodzielnie ten układ równań.
+
+
+### Zadanie
+
+Dodaj zmienne lokalne `n` i `f` w funkcji, ustal im jakieś arbitralne wartości i dodaj rzutowanie $z$ zgodnie ze wzorem, który otrzymaliśmy. Spróbuj ustawić taką wartość `f`, żeby tylna ściana sześcianu zniknęła.
+
+
+
+Uzyskana macierz daje nam rzutowanie perspektywiczne, ale możemy ją jeszcze rozbudować o zmianę kąta widzenia, a także naprawić problem z nieprawidłowym skalowaniem się ekranu przy zmianie jego proporcji. Obie te czynności sprowadzają się do tego samego, mianowicie chcemy zmienić kształt bryły widzenia w osiach $x$ i $y$. By tego dokonać, musimy zmienić wartość parametrów $m_{11}$ i $m_{22}$, to one odpowiadają za skalowanie w tych osiach. Parametry te ściskają lub rozszerzają przestrzeń w tych osiach, więc zmniejszenie wartości zwiększy kąt widzenia w danej osi.
+
+Zacznijmy od kąta widzenia. Można go zmienić zwyczajnie ustawiając zamiast $1$ dowolną inną wartość $S$ parametrów $m_{11}$ i $m_{22}$. Jednak jeśli chcemy uzyskać faktyczne parametry oparte na polu widzenia, musimy skorzystać ze wzoru:
+
+$$S=\frac{1}{\tan(\frac{fov}{2}*\frac{\pi}{180})}$$
+
+
+### Zadanie
+Dodaj do `createPerspectiveMatrix` argument fov, który będzie ustalał kąt widzenia.
+
+
+### Zadanie
+Prawidłowe skalowanie okna uzyskamy poprzez mnożenie $m_{22}$ przez stosunek szerokości do wysokości ekranu. W zadaniu jest zmienna globalna `aspectRatio`. W funkcji `framebuffer_size_callback` nadpisz tą zmienną właściwym stosunkiem (pamiętaj, że dzielenie liczb stałoprzecinkowych w c++ nie uwzględnia ułamków). Następnie prześlij ja do `createPerspectiveMatrix` jako dodatkowy parametr i wykorzystaj przy renderowaniu sceny.
+
+----
+### Zadanie*
+Po dodaniu skalowania okna, poszerzanie kwadratowego okna będzie zmniejszać kąt widzenia na osi pionowej. Natomiast wydłużanie go będzie go zwiększać. Zaproponuj rozwiązanie, które sprawi, że poszerzanie kwadratowego okna będzie zwiększać kąt widzenia w osi poziomej i jednocześnie wydłużanie kwadratowego okna będzie zwiększać kąt widzenia w osi pionowej.
+
+
+
+## Macierz widoku
+Celem macierzy widoku jest wprowadzenie pojęcia kamery, jako obiektu, który możemy ustawić i poruszać nim w przestrzeni. Na taką macierz składa się pozycja kamery kierunek patrzenia oraz jej orientacja: wektory `cameraDir` oraz `cameraUp` i `cameraSide`. W tym celu potrzebujemy jeden wektor, który będzie określał pozycję początku układu współrzędnych (czyli pozycję kamery). Oraz 3 wektory ortonormalne, które będą rozpinać przestrzeń (odpowiedzialne za kierunek i orientację). Ponieważ te wektory są ortogonalne, możemy je rekonstruować za pomocą dwóch wektorów, jeden będzie nam wskazywać kierunek patrzenia (`cameraDir`), drugi górę (`cameraUp`).
+
+![](./img/camera.jpg)
+
+> Układ współrzędnych kamery
+
+W kodzie jest zaimplementowana obsługa klawiatury, klawisze **W** i **S** przesuwają kamerę do przodu i do tyłu, natomiast **A** i **D** obracają ją na boki. Robią to poprzez modyfikacje zmiennych globalnych `cameraDir` i `cameraPos`, jednak, żeby kamera faktycznie działała, trzeba uzupełnić funkcję `createCameraMatrix` i dodać jej wynik do transformacji obiektów.
+
+### Zadanie
+Uzupełnij funkcję `createCameraMatrix`. Najpierw oblicz wektor skierowany w bok za pomocą iloczynu wektorowego między `cameraDir` a wektorem $[0,1,0]$. Wektor może być długości innej niż 1, dlatego znormalizuj go. Zapisz wynik do `cameraSide`. Podobnie oblicz `cameraUp` jako znormalizowany iloczyn wektorowy między `cameraSide` i `cameraDir`.
+
+> Wektor normalizuje się za pomocą funkcji: `glm::normalize`
+
+Macierz kamery złożona jest z iloczynu macierzy obrotu i macierzy translacji. By otrzymać pierwszą z nich, korzystamy z ortonormalności bazy, dzięki temu wystarczy zapisać wektory `cameraSide`, `cameraUp` i `-cameraDir` wierszami.
+>Zauważ, że `cameraDir` musi być odwrócony tak jak na obrazku, ma być zwrócony do kamery, nie od niej. Macierz wygląda następująco:
+
+
+$$M_{VR}=\begin{bmatrix} cameraSide_x & cameraSide_y & cameraSide_z & 0\\cameraUp_x & cameraUp_y & cameraUp_z & 0\\-cameraDir_x & -cameraDir_y & -cameraDir_z & 0\\0 & 0 & 0 & 1 \end{bmatrix}$$
+
+Macierz translacji $M_{VT}$ otrzymujemy przez translacje o `-cameraPos`. Ostatecznie macierz widoku jest postaci
+$$M_V=M_{VR}*M_{VT}$$
+
+W macierzy `transformation` umieść pomnożone przez siebie macierze perspektywy (wynik funkcji `createPerspectiveMatrix`) i kamery (wynik funkcji `createCameraMatrix`) w odpowiedniej kolejności. Jako efektem otrzymamy pełen potok graficzny, czyli kamerę, którą możemy poruszać klawiszami, z poprawnym rzutowaniem perspektywicznym.
+
+### Zadanie
+
+Wyświetl dwa dodatkowe prostopadłościany w różnych pozycjach i orientacjach.
+
+### Zadanie*
+Zmodyfikuj ustawienia tak, żeby kamera zawsze była zwrócona w punkt wybrany punkt $p$ $(0,0,0)$. W funkcji `processInput` zakomentuj obsługę klawiszy **A** i **D**. Zamiast tego na końcu tej funkcji ustaw `cameraDir` jako znormalizowana różnicę między punktem $p$ a `cameraPos`. Jako obsługę klawiszy **R** i **F** dodaj przesuwanie kamery w górę i w dół.
+
+# Ładowanie modeli z użyciem assimp**
+
+W tym zadaniu przećwiczymy ładowanie modeli z plików, wykorzystamy do tego bibliotekę assimp (The Open Asset Import Library ), która zapewnia wspólny interfejs dla różnych typów plików.
+
+Funkcja `loadModelToContext` pobiera ścieżkę do pliku z modelem i wczytuje go przy użyciu importera assimp.
+
+```c++
+const aiScene* scene = import.ReadFile(path, aiProcess_TriangulateaiProcess_Triangulate | aiProcess_CalcTangentSpace);
+```
+
+Importer przyjmuje ścieżkę i flagi preprocesingu, które mówią, jakie operacje ma wykonać importer przed przekazaniem nam pliku. W naszym przypadku dokonuje triangularyzacji (zamienia wszystkie wielokąty na trójkąty) i oblicza przestrzeń styczną (o której będzie mowa później).
+
+> Wywołaj funkcję dla ścieżki do statku **./models/spaceship.obj** i zmiennej globalnej `Core::RenderContext sphereContext`. Dodaj breakpoint po załadowaniu sceny i obejrzyj jak wygląda struktura załadowanego obiektu.
+
+Załadowany obiekt posiada szereg pól jak na przykład tekstury, oświetlenia, materiały, węzły (*Node*) czy modele. Węzły odpowiadają za hierarchię elementów w modelu, co ułatwia jego animację, wykorzystamy to w późniejszych zajęciach. Nasze pliki składają się z tylko jednego modelu, dlatego nie musimy się na tym skupiać i wywołujemy tylko pierwszy model, do którego odwołujemy się za pomocą `scene->mMeshes[0]`. Wywołaj `context.initFromAiMesh` z nim jako argumentem.
+
+### Zadanie**
+
+Jeśli tego nie zrobiłeś wywołaj metodę `context.initFromAiMesh` z argumentem`scene->mMeshes[0]` w funkcji `init`, po wczytaniu modelu. Metoda nie jest kompletna, uzupełnij ją o ładowanie indeksów, wierzchołków, normalnych i współrzędnych tekstur do bufora. Współrzędne tekstur i indeksy zostały przekonwertowane do odpowiedniego formatu i znajdują się w zmiennych `std::vector textureCoord` i ` std::vector indices` odpowiednio. Pozostałe są dostępne jako atrybuty `aiMesh`, mianowicie `mesh->mVertices` zawiera wierzchołki a `mesh->mNormals` normalne.
+
+Dodatkowo `mesh->mNumVertices` zawiera liczbę wierzchołków.
+
+
+zawierają rozmiary buforów.
+
+Utwórz jedną duża tablicę/vector, która zawiera informacje o wierzchołkach, normalnych i współrzędnych tekstur. Powinna mieć ona format jak na poniższym obrazku:
+
+![](https://i.imgur.com/WLAQtGH.jpg)
+
+
+Gdy załadujesz kontekst, wykorzystaj w `renderScene` funkcję `Core::DrawContext(Core::RenderContext& context)` do narysowania obiektów. Rozmieść statek i kulę w przestrzeni za pomocą macierzy transformacji i obrotu.
\ No newline at end of file
diff --git a/cw 3/zlib.dll b/cw 3/zlib.dll
new file mode 100644
index 0000000..7e7c10e
Binary files /dev/null and b/cw 3/zlib.dll differ
diff --git a/cw 3/zlibd.dll b/cw 3/zlibd.dll
new file mode 100644
index 0000000..5f03c2c
Binary files /dev/null and b/cw 3/zlibd.dll differ
diff --git a/cw 4/Zadania 4.html b/cw 4/Zadania 4.html
new file mode 100644
index 0000000..e14983d
--- /dev/null
+++ b/cw 4/Zadania 4.html
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+ Zadania 4
+
+
+
+
+
+
+Ładowanie obiektów za pomocą assimpa
+W projekcie zaimplentowane jest ładowanie modeli z użyciem biblioteki assimp. Obiekty ładuje się za pomocą funkcji loadModelToContext(std::string path, Core::RenderContext& context)
pierwszym jej argumentem jest ścieżka, pod którą znajduje się model, drugim argumentem jest referencja do RenderContext
. Ta struktura przechowuje informacje o modelu, m.in. jego VAO czy liczba wierzchołku. Rysuje się go za pomocą funkcji Core::DrawContext(Core::RenderContext& context)
. Teraz przykładowo rysowana jest sfera ładowana z pliku.
+W trakcie poprzednich zadań zdefiniowaliśmy funkcje tworzące macierze widoku i projekcji. Aby narysować model, należy najpierw zdefiniować macierz modelu, przemnożyć ją przez macierz kamery i macierz widoku i wysłać ją do GPU i dopiero narysować model. Te operacje są bardzo powtarzalne i można je przenieść do osobnej funkcji. Dlatego w ex_4_1.hpp
znajduje funkcja drawObjectColor
która przyjmuje rysowany obiekt jako Core::RenderContext&
, macierz modelu jako glm::mat4
i kolor jako glm::vec3
. ### Zadanie Wszystkie obiekty rysowane przez drawObjectColor
rysują się na jeden kolor, napraw to. Wewnątrz funkcji prześlij kolor jako uniform
do GPU (za pomocą funkcji glUniform3f
) i tak zmodyfikuj shader fragmentów, żeby ustalić go kolorem wyjściowym.
+Korzystając z tej funkcji, stwórz układ słoneczny z przynajmniej jedną planetą, która posiada księżyc. Planeta powinna poruszać się wokół słońca a księżyc wokół planety.
+Zadanie*
+Rozbuduj układ planetarny do przynajmniej 5 planet i pasa asteroid. Ściągnij z internetu/stwórz kilka prostych modeli asteroid, z których zbudujesz pas asteroid.
+Zadanie
+Celem tego zadania jest dodanie statku, który będzie latać po układzie planetarnym.
+Załaduj model statku, który jest w pliku spaceship.obj
. Stwórz zmienne globalne spaceshipPos
oraz spaceshipDir
, które będą określać pozycję i kierunek, w którym statek się porusza. Później będziemy je zmieniać za pomocą przycisków, na razie wewnątrz funkcji processInput
przypisz do nich odpowiednio cameraPos+1.5*cameraDir+glm::vec3(0,-0.5f,0)
oraz cameraDir
. W ten sposób po prawidłowym ustawieniu macierzy statek będzie znajdował się zawsze przed kamerą.
+Przesuń i obróć statek w odpowiedni sposób. Przesunięcie zrealizujemy przez translację do spaceshipPos
natomiast macierz statku liczy się tak samo, jak macierz kamery, tylko zamiast cameraDir
bierzemy spaceshipDir
i na końcu trzeba tę macierz odwrócić (lub transponować, co jest tym samym, ponieważ mówimy o macierzy ortonormalnej).
+Możliwe, że model nie jest skierowany w stronę tej samej osi, co domyślnie w openGL, w tym wypadku musisz dodać dodatkową rotację o stały kąt, która naprawi ten problem.
+Zadanie
+Zadanie*
+W tej chwili klawisze ustawiają kamerę, do której podczepiony jest statek. Zmodyfikuj aplikację, żeby klawisze przesuwały statek, a kamera była do niego podczepiona. Aby to zrobić, wystarczy w obsłudze klawiatury modyfikować wektory spaceshipPos
i spaceshipDir
. Natomiast cameraPos
i cameraDir
uzależnić od wektorów spaceshipPos
i spaceshipDir
.
+Zadanie*
+W tej chwili szybkość poruszania się statku/kamery jest uzależniona od liczby klatek, co daje różne efekty na różnych komputerach i jest raczej niepożądane. Aby to naprawić, musimy obliczyć, ile czasu minęło między klatkami i od tego uzależnić przesunięcia oraz obroty. Utwórz zmienne globalne float lastFrameTime
oraz float deltaTime
, następnie w funkcji renderScene
dodaj oblicz deltaTime = time-lastFrameTime
i przypisz do zmiennej lastFrameTime
wartość time
. Nie chcemy, żeby wartość deltaTime
była zbyt duża, gdy nagle spadnie liczba klatek, dlatego ucinamy ją od góry przez 0.1
.
+Wykorzystaj deltaTime
w funkcji processInput
aby uniezależnić prędkość poruszania się od liczby klatek na sekundę.
+Zadanie*
+Podmień model statku na jakiś inny.
+Zadanie**
+dodaj obsługę myszki, która będzie obracać kamerą.
+Bufor głębokości
+Bufor głębokości zapisuje, w jakiej odległości od kamery znajduje dany piksel. Dzięki temu przy rysowaniu kolejnych obiektów można odrzucić te piksele, które znajdowałyby się za narysowanymi. Ten mechanizm jest automatycznie, żeby go uruchomić, wystarczy dodać instrukcję glEnable(GL_DEPTH_TEST)
, poza tym przed rysowaniem klatki należy wyczyścić bufor głębokości, co robimy w instrukcji glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
.
+Zadanie
+Sprawdź, co się stanie, gdy nie włączymy glEnable(GL_DEPTH_TEST)
oraz sprawdź co, się dzieje, gdy nie czyścimy żadnego bufora lub gdy czyścimy tylko bufor koloru czy tylko bufor głębokości. Dlaczego dzieje się to, co widzisz?
+Wizualizacja bufora głębokości
+W tej części zwizualizujemy jak wygląda bufor głębokości przy pomocy skali szarości. Zrealizujemy poprzez napisanie odpowiedniego shadera.
+
+Uwaga nie jest to faktycznie rysowanie bufora głębokości, to wymagałoby stworzenie FrameBufferObject renderowanie głębokości do niego i narysowanie wyniku na ekranie. Zrobimy to na późniejszych zajęciach przy okazji rysowania cieni.
+
+Wykorzystamy wbudowaną zmienną gl_FragCoord
we fragment shaderze. Zawiera ona informacje o pozycji fragmentu.
+Zadanie
+We fragment shaderze podmień wartości R G B w shaderze fragmentów na gl_FragCoord.z
.
+Zauważ, że obiekty są bardzo jasne i stają się ciemniejsze, dopiero gdy kamera podjedzie bardzo blisko. Wynika to z tego, że wartości z
w gl_FragCoord
nie są liniowe ze względu na rzutowanie perspektywiczne omówione na poprzednich zajęciach. Poniższy wykres prezentuje przykładową różnicę między faktyczną wartością a wartością w gl_FragCoord
.
+My chcielibyśmy wyświetlać je liniowo. W tym celu będziemy musieli wrócić do współrzędnych w przestrzeni świata. Zauważ, że wartości gl_FragCoord.z
są z zakresu od \([0,1]\) a nie \([-1,1]\) jak są zapisane współrzędne w przestrzeni ekranu. Dlatego pierwszym krokiem będzie przekonwertowanie ich (poprzez pomnożenie przez 2 i odjęcie 1). Współrzędne w przestrzeni ekranu obliczamy wzorem \[z'=-\frac{(n + f)}{(n - f)}- \frac{(2 n f)}{z(n - f)}.\]My chcemy obliczyć \(z\) po przekształceniu wzoru otrzymujemy: \[z=\frac{-2nf}{z'(n-f)+n+f}.\] ### Zadanie We fragment shaderze uwórz funkcję, która oblicza \(z\) i wyświetl zlinearyzowaną odległość. Pamiętaj, że wartość \(z\) jest z zakresu od \(n\) do \(f\), dlatego zmień podziel ją przez \(f\) przed rysowaniem.
+Zadanie*
+Wykorzystaj informację o odległości, żeby dodać do sceny efekt mgły. Zmieszaj kolor obiektu z kolorem tła, jako współczynnik weź wartość z poprzedniego zadania.
+Kreatywne wykorzystanie bufora głębokości
+Czasem chcielibyśmy, żeby niektóre wyświetlane elementy były inaczej traktowane przez bufor głębokości. Przykładowo chcielibyśmy stworzyć bardziej złożone tło dla naszej sceny. Chcemy wtedy, żeby to tło było ,,za’’ każdym innym obiektem w scenie. Możemy to osiągnąć poprzez namalowanie tła na początku, a następnie usunięcie zawartości bufora głębokości.
+Zadanie
+Dodaj jakiś rodzaj tła w sposób opisany powyżej. Mogą być to na przykład małe sfery udające gwiazdy. Prostokąt w przestrzeni ekranu, który będzie zmieniał kolory czy kręcący się prostopadłościan.
+
+
diff --git a/cw 4/Zadania 4.md b/cw 4/Zadania 4.md
new file mode 100644
index 0000000..04d0de0
--- /dev/null
+++ b/cw 4/Zadania 4.md
@@ -0,0 +1,74 @@
+## Ładowanie obiektów za pomocą assimpa
+
+W projekcie zaimplentowane jest ładowanie modeli z użyciem biblioteki assimp. Obiekty ładuje się za pomocą funkcji `loadModelToContext(std::string path, Core::RenderContext& context)` pierwszym jej argumentem jest ścieżka, pod którą znajduje się model, drugim argumentem jest referencja do `RenderContext`. Ta struktura przechowuje informacje o modelu, m.in. jego VAO czy liczba wierzchołku. Rysuje się go za pomocą funkcji `Core::DrawContext(Core::RenderContext& context)`. Teraz przykładowo rysowana jest sfera ładowana z pliku.
+
+W trakcie poprzednich zadań zdefiniowaliśmy funkcje tworzące macierze widoku i projekcji. Aby narysować model, należy najpierw zdefiniować macierz modelu, przemnożyć ją przez macierz kamery i macierz widoku i wysłać ją do GPU i dopiero narysować model. Te operacje są bardzo powtarzalne i można je przenieść do osobnej funkcji. Dlatego w `ex_4_1.hpp` znajduje funkcja `drawObjectColor` która przyjmuje rysowany obiekt jako `Core::RenderContext&`, macierz modelu jako `glm::mat4` i kolor jako `glm::vec3`.
+### Zadanie
+Wszystkie obiekty rysowane przez `drawObjectColor` rysują się na jeden kolor, napraw to. Wewnątrz funkcji prześlij kolor jako `uniform` do GPU (za pomocą funkcji `glUniform3f`) i tak zmodyfikuj shader fragmentów, żeby ustalić go kolorem wyjściowym.
+
+Korzystając z tej funkcji, stwórz układ słoneczny z przynajmniej jedną planetą, która posiada księżyc. Planeta powinna poruszać się wokół słońca a księżyc wokół planety.
+
+### Zadanie*
+Rozbuduj układ planetarny do przynajmniej 5 planet i pasa asteroid. Ściągnij z internetu/stwórz kilka prostych modeli asteroid, z których zbudujesz pas asteroid.
+
+### Zadanie
+Celem tego zadania jest dodanie statku, który będzie latać po układzie planetarnym.
+
+Załaduj model statku, który jest w pliku `spaceship.obj`. Stwórz zmienne globalne `spaceshipPos` oraz `spaceshipDir`, które będą określać pozycję i kierunek, w którym statek się porusza. Później będziemy je zmieniać za pomocą przycisków, na razie wewnątrz funkcji `processInput` przypisz do nich odpowiednio `cameraPos+1.5*cameraDir+glm::vec3(0,-0.5f,0)` oraz `cameraDir`. W ten sposób po prawidłowym ustawieniu macierzy statek będzie znajdował się zawsze przed kamerą.
+
+Przesuń i obróć statek w odpowiedni sposób. Przesunięcie zrealizujemy przez translację do `spaceshipPos` natomiast macierz statku liczy się tak samo, jak macierz kamery, tylko zamiast `cameraDir` bierzemy `spaceshipDir` i na końcu trzeba tę macierz odwrócić (lub transponować, co jest tym samym, ponieważ mówimy o macierzy ortonormalnej).
+
+Możliwe, że model nie jest skierowany w stronę tej samej osi, co domyślnie w openGL, w tym wypadku musisz dodać dodatkową rotację o stały kąt, która naprawi ten problem.
+
+### Zadanie
+
+### Zadanie*
+W tej chwili klawisze ustawiają kamerę, do której podczepiony jest statek. Zmodyfikuj aplikację, żeby klawisze przesuwały statek, a kamera była do niego podczepiona. Aby to zrobić, wystarczy w obsłudze klawiatury modyfikować wektory `spaceshipPos` i `spaceshipDir`. Natomiast `cameraPos` i `cameraDir` uzależnić od wektorów `spaceshipPos` i `spaceshipDir`.
+
+### Zadanie*
+W tej chwili szybkość poruszania się statku/kamery jest uzależniona od liczby klatek, co daje różne efekty na różnych komputerach i jest raczej niepożądane. Aby to naprawić, musimy obliczyć, ile czasu minęło między klatkami i od tego uzależnić przesunięcia oraz obroty. Utwórz zmienne globalne `float lastFrameTime` oraz `float deltaTime`, następnie w funkcji `renderScene` dodaj oblicz `deltaTime = time-lastFrameTime` i przypisz do zmiennej `lastFrameTime` wartość `time`. Nie chcemy, żeby wartość `deltaTime` była zbyt duża, gdy nagle spadnie liczba klatek, dlatego ucinamy ją od góry przez `0.1`.
+
+Wykorzystaj `deltaTime` w funkcji `processInput` aby uniezależnić prędkość poruszania się od liczby klatek na sekundę.
+
+### Zadanie*
+Podmień model statku na jakiś inny.
+
+### Zadanie**
+dodaj obsługę myszki, która będzie obracać kamerą.
+
+## Bufor głębokości
+
+Bufor głębokości zapisuje, w jakiej odległości od kamery znajduje dany piksel. Dzięki temu przy rysowaniu kolejnych obiektów można odrzucić te piksele, które znajdowałyby się za narysowanymi. Ten mechanizm jest automatycznie, żeby go uruchomić, wystarczy dodać instrukcję `glEnable(GL_DEPTH_TEST)`, poza tym przed rysowaniem klatki należy wyczyścić bufor głębokości, co robimy w instrukcji `glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)`.
+
+### Zadanie
+Sprawdź, co się stanie, gdy nie włączymy `glEnable(GL_DEPTH_TEST)` oraz sprawdź co, się dzieje, gdy nie czyścimy żadnego bufora lub gdy czyścimy tylko bufor koloru czy tylko bufor głębokości. Dlaczego dzieje się to, co widzisz?
+
+
+## Wizualizacja bufora głębokości
+
+W tej części zwizualizujemy jak wygląda bufor głębokości przy pomocy skali szarości. Zrealizujemy poprzez napisanie odpowiedniego shadera.
+
+> **Uwaga** nie jest to faktycznie rysowanie bufora głębokości, to wymagałoby stworzenie FrameBufferObject renderowanie głębokości do niego i narysowanie wyniku na ekranie. Zrobimy to na późniejszych zajęciach przy okazji rysowania cieni.
+
+Wykorzystamy wbudowaną zmienną `gl_FragCoord` we fragment shaderze. Zawiera ona informacje o pozycji fragmentu.
+
+### Zadanie
+We fragment shaderze podmień wartości R G B w shaderze fragmentów na `gl_FragCoord.z`.
+
+Zauważ, że obiekty są bardzo jasne i stają się ciemniejsze, dopiero gdy kamera podjedzie bardzo blisko. Wynika to z tego, że wartości `z` w `gl_FragCoord` nie są liniowe ze względu na rzutowanie perspektywiczne omówione na poprzednich zajęciach. Poniższy wykres prezentuje przykładową różnicę między faktyczną wartością a wartością w `gl_FragCoord`.
+![](./img/z_depth_graph2.jpg)
+
+My chcielibyśmy wyświetlać je liniowo. W tym celu będziemy musieli wrócić do współrzędnych w przestrzeni świata.
+Zauważ, że wartości `gl_FragCoord.z` są z zakresu od $[0,1]$ a nie $[-1,1]$ jak są zapisane współrzędne w przestrzeni ekranu. Dlatego pierwszym krokiem będzie przekonwertowanie ich (poprzez pomnożenie przez 2 i odjęcie 1). Współrzędne w przestrzeni ekranu obliczamy wzorem $$z'=-\frac{(n + f)}{(n - f)}- \frac{(2 n f)}{z(n - f)}.$$My chcemy obliczyć $z$ po przekształceniu wzoru otrzymujemy:
+$$z=\frac{-2nf}{z'(n-f)+n+f}.$$
+### Zadanie
+We fragment shaderze uwórz funkcję, która oblicza $z$ i wyświetl zlinearyzowaną odległość. Pamiętaj, że wartość $z$ jest z zakresu od $n$ do $f$, dlatego zmień podziel ją przez $f$ przed rysowaniem.
+
+### Zadanie*
+Wykorzystaj informację o odległości, żeby dodać do sceny efekt mgły. Zmieszaj kolor obiektu z kolorem tła, jako współczynnik weź wartość z poprzedniego zadania.
+
+## Kreatywne wykorzystanie bufora głębokości
+Czasem chcielibyśmy, żeby niektóre wyświetlane elementy były inaczej traktowane przez bufor głębokości. Przykładowo chcielibyśmy stworzyć bardziej złożone tło dla naszej sceny. Chcemy wtedy, żeby to tło było ,,za'' każdym innym obiektem w scenie. Możemy to osiągnąć poprzez namalowanie tła na początku, a następnie usunięcie zawartości bufora głębokości.
+
+### Zadanie
+Dodaj jakiś rodzaj tła w sposób opisany powyżej. Mogą być to na przykład małe sfery udające gwiazdy. Prostokąt w przestrzeni ekranu, który będzie zmieniał kolory czy kręcący się prostopadłościan.
diff --git a/cw 4/assimp-vc141-mt.dll b/cw 4/assimp-vc141-mt.dll
new file mode 100644
index 0000000..86f52a0
Binary files /dev/null and b/cw 4/assimp-vc141-mt.dll differ
diff --git a/cw 4/assimp-vc141-mtd.dll b/cw 4/assimp-vc141-mtd.dll
new file mode 100644
index 0000000..2e5fd66
Binary files /dev/null and b/cw 4/assimp-vc141-mtd.dll differ
diff --git a/cw 4/freeglut.dll b/cw 4/freeglut.dll
new file mode 100644
index 0000000..c768c15
Binary files /dev/null and b/cw 4/freeglut.dll differ
diff --git a/cw 4/glew32.dll b/cw 4/glew32.dll
new file mode 100644
index 0000000..8a49a3b
Binary files /dev/null and b/cw 4/glew32.dll differ
diff --git a/cw 4/grk-cw4.vcxproj b/cw 4/grk-cw4.vcxproj
new file mode 100644
index 0000000..078e268
--- /dev/null
+++ b/cw 4/grk-cw4.vcxproj
@@ -0,0 +1,110 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {D7858112-9412-4E7E-AB73-A911604592EC}
+ Win32Proj
+ grk-cw4
+ 10.0
+ grk-cw4
+
+
+
+ Application
+ true
+ Unicode
+ v143
+
+
+ Application
+ false
+ true
+ Unicode
+ v143
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+ $(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019;$(SolutionDir)dependencies\assimp;$(LibraryPath)
+ $(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\include;$(SolutionDir)dependencies\assimp\include;$(IncludePath)
+ $(ExecutablePath)
+
+
+ false
+ $(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019;$(SolutionDir)dependencies\assimp;$(LibraryPath)
+ $(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\include;$(SolutionDir)dependencies\assimp\include;$(IncludePath)
+
+
+
+
+
+ Level3
+ Disabled
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+
+
+ Console
+ true
+ opengl32.lib;freeglut.lib;glew32.lib;$(SolutionDir)\dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019\glfw3.lib;$(SolutionDir)\dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019\glfw3dll.lib;zlibd.lib;assimp-vc141-mtd.lib;%(AdditionalDependencies)
+ $(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019;%(AdditionalLibraryDirectories)
+
+
+
+
+ Level3
+
+
+ MaxSpeed
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+
+
+ Console
+ true
+ true
+ true
+ opengl32.lib;freeglut.lib;glew32.lib;$(SolutionDir)\dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019\glfw3.lib;$(SolutionDir)\dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019\glfw3dll.lib;zlibd.lib;assimp-vc141-mtd.lib;%(AdditionalDependencies)
+ $(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019;%(AdditionalLibraryDirectories)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cw 4/grk-cw4.vcxproj.filters b/cw 4/grk-cw4.vcxproj.filters
new file mode 100644
index 0000000..3c2fd19
--- /dev/null
+++ b/cw 4/grk-cw4.vcxproj.filters
@@ -0,0 +1,62 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+ {0a247bb8-2e8e-4a90-b0ef-17415b0941ba}
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Shader Files
+
+
+ Shader Files
+
+
+
\ No newline at end of file
diff --git a/cw 4/img/2.png b/cw 4/img/2.png
new file mode 100644
index 0000000..e0537ce
Binary files /dev/null and b/cw 4/img/2.png differ
diff --git a/cw 4/img/3.webp b/cw 4/img/3.webp
new file mode 100644
index 0000000..cda42cc
Binary files /dev/null and b/cw 4/img/3.webp differ
diff --git a/cw 4/img/384px-PerlinNoiseDotProducts.png b/cw 4/img/384px-PerlinNoiseDotProducts.png
new file mode 100644
index 0000000..eb610e2
Binary files /dev/null and b/cw 4/img/384px-PerlinNoiseDotProducts.png differ
diff --git a/cw 4/img/384px-PerlinNoiseInterpolated.png b/cw 4/img/384px-PerlinNoiseInterpolated.png
new file mode 100644
index 0000000..97caa53
Binary files /dev/null and b/cw 4/img/384px-PerlinNoiseInterpolated.png differ
diff --git a/cw 4/img/4.png b/cw 4/img/4.png
new file mode 100644
index 0000000..0d74746
Binary files /dev/null and b/cw 4/img/4.png differ
diff --git a/cw 4/img/5.webp b/cw 4/img/5.webp
new file mode 100644
index 0000000..2157419
Binary files /dev/null and b/cw 4/img/5.webp differ
diff --git a/cw 4/img/6.webp b/cw 4/img/6.webp
new file mode 100644
index 0000000..6171ecc
Binary files /dev/null and b/cw 4/img/6.webp differ
diff --git a/cw 4/img/7.webp b/cw 4/img/7.webp
new file mode 100644
index 0000000..c13c85d
Binary files /dev/null and b/cw 4/img/7.webp differ
diff --git a/cw 4/img/8.webp b/cw 4/img/8.webp
new file mode 100644
index 0000000..9c22d8c
Binary files /dev/null and b/cw 4/img/8.webp differ
diff --git a/cw 4/img/Figure_1.eps b/cw 4/img/Figure_1.eps
new file mode 100644
index 0000000..8f26308
--- /dev/null
+++ b/cw 4/img/Figure_1.eps
@@ -0,0 +1,1254 @@
+%!PS-Adobe-3.0 EPSF-3.0
+%%Title: Figure_1.eps
+%%Creator: Matplotlib v3.4.3, https://matplotlib.org/
+%%CreationDate: Thu Nov 3 12:06:06 2022
+%%Orientation: portrait
+%%BoundingBox: 75 223 537 569
+%%HiResBoundingBox: 75.600000 223.200000 536.400000 568.800000
+%%EndComments
+%%BeginProlog
+/mpldict 11 dict def
+mpldict begin
+/_d { bind def } bind def
+/m { moveto } _d
+/l { lineto } _d
+/r { rlineto } _d
+/c { curveto } _d
+/cl { closepath } _d
+/ce { closepath eofill } _d
+/box {
+ m
+ 1 index 0 r
+ 0 exch r
+ neg 0 r
+ cl
+ } _d
+/clipbox {
+ box
+ clip
+ newpath
+ } _d
+/sc { setcachedevice } _d
+%!PS-Adobe-3.0 Resource-Font
+%%Creator: Converted from TrueType to Type 3 by Matplotlib.
+10 dict begin
+/FontName /DejaVuSans def
+/PaintType 0 def
+/FontMatrix [0.00048828125 0 0 0.00048828125 0 0] def
+/FontBBox [-2090 -948 3673 2524] def
+/FontType 3 def
+/Encoding [/aogonek /minus /space /period /zero /one /two /five /seven /a /c /d /e /g /h /i /j /m /n /o /p /r /z] def
+/CharStrings 24 dict dup begin
+/.notdef 0 def
+/aogonek{1255 0 123 -395 1152 1147 sc
+702 563 m
+553 563 450 546 393 512 c
+336 478 307 420 307 338 c
+307 273 328 221 371 182 c
+414 144 473 125 547 125 c
+649 125 731 161 792 233 c
+854 306 885 402 885 522 c
+885 563 l
+702 563 l
+
+1069 639 m
+1069 0 l
+885 0 l
+885 170 l
+843 102 791 52 728 19 c
+665 -13 589 -29 498 -29 c
+383 -29 292 3 224 67 c
+157 132 123 218 123 326 c
+123 452 165 547 249 611 c
+334 675 460 707 627 707 c
+885 707 l
+885 725 l
+885 810 857 875 801 921 c
+746 968 668 991 567 991 c
+503 991 441 983 380 968 c
+319 953 261 930 205 899 c
+205 1069 l
+272 1095 338 1114 401 1127 c
+464 1140 526 1147 586 1147 c
+748 1147 869 1105 949 1021 c
+1029 937 1069 810 1069 639 c
+
+887 0 m
+1006 0 l
+976 -41 954 -76 939 -105 c
+925 -134 918 -159 918 -180 c
+918 -211 927 -234 945 -249 c
+964 -264 991 -272 1027 -272 c
+1048 -272 1069 -269 1090 -264 c
+1111 -259 1131 -252 1152 -242 c
+1152 -375 l
+1127 -382 1103 -387 1080 -390 c
+1057 -393 1036 -395 1016 -395 c
+935 -395 875 -380 836 -351 c
+798 -322 779 -277 779 -215 c
+779 -183 788 -149 805 -114 c
+823 -79 850 -41 887 0 c
+
+ce} _d
+/minus{1716 0 217 557 1499 727 sc
+217 727 m
+1499 727 l
+1499 557 l
+217 557 l
+217 727 l
+
+ce} _d
+/space{651 0 0 0 0 0 sc
+ce} _d
+/period{651 0 219 0 430 254 sc
+219 254 m
+430 254 l
+430 0 l
+219 0 l
+219 254 l
+
+ce} _d
+/zero{1303 0 135 -29 1167 1520 sc
+651 1360 m
+547 1360 469 1309 416 1206 c
+364 1104 338 950 338 745 c
+338 540 364 387 416 284 c
+469 182 547 131 651 131 c
+756 131 834 182 886 284 c
+939 387 965 540 965 745 c
+965 950 939 1104 886 1206 c
+834 1309 756 1360 651 1360 c
+
+651 1520 m
+818 1520 946 1454 1034 1321 c
+1123 1189 1167 997 1167 745 c
+1167 494 1123 302 1034 169 c
+946 37 818 -29 651 -29 c
+484 -29 356 37 267 169 c
+179 302 135 494 135 745 c
+135 997 179 1189 267 1321 c
+356 1454 484 1520 651 1520 c
+
+ce} _d
+/one{1303 0 225 0 1114 1493 sc
+254 170 m
+584 170 l
+584 1309 l
+225 1237 l
+225 1421 l
+582 1493 l
+784 1493 l
+784 170 l
+1114 170 l
+1114 0 l
+254 0 l
+254 170 l
+
+ce} _d
+/two{1303 0 150 0 1098 1520 sc
+393 170 m
+1098 170 l
+1098 0 l
+150 0 l
+150 170 l
+227 249 331 356 463 489 c
+596 623 679 709 713 748 c
+778 821 823 882 848 932 c
+874 983 887 1032 887 1081 c
+887 1160 859 1225 803 1275 c
+748 1325 675 1350 586 1350 c
+523 1350 456 1339 385 1317 c
+315 1295 240 1262 160 1217 c
+160 1421 l
+241 1454 317 1478 388 1495 c
+459 1512 523 1520 582 1520 c
+737 1520 860 1481 952 1404 c
+1044 1327 1090 1223 1090 1094 c
+1090 1033 1078 974 1055 919 c
+1032 864 991 800 930 725 c
+913 706 860 650 771 557 c
+682 465 556 336 393 170 c
+
+ce} _d
+/five{1303 0 158 -29 1124 1493 sc
+221 1493 m
+1014 1493 l
+1014 1323 l
+406 1323 l
+406 957 l
+435 967 465 974 494 979 c
+523 984 553 987 582 987 c
+749 987 881 941 978 850 c
+1075 759 1124 635 1124 479 c
+1124 318 1074 193 974 104 c
+874 15 733 -29 551 -29 c
+488 -29 424 -24 359 -13 c
+294 -2 227 14 158 35 c
+158 238 l
+218 205 280 181 344 165 c
+408 149 476 141 547 141 c
+662 141 754 171 821 232 c
+888 293 922 375 922 479 c
+922 583 888 665 821 726 c
+754 787 662 817 547 817 c
+493 817 439 811 385 799 c
+332 787 277 768 221 743 c
+221 1493 l
+
+ce} _d
+/seven{1303 0 168 0 1128 1493 sc
+168 1493 m
+1128 1493 l
+1128 1407 l
+586 0 l
+375 0 l
+885 1323 l
+168 1323 l
+168 1493 l
+
+ce} _d
+/a{1255 0 123 -29 1069 1147 sc
+702 563 m
+553 563 450 546 393 512 c
+336 478 307 420 307 338 c
+307 273 328 221 371 182 c
+414 144 473 125 547 125 c
+649 125 731 161 792 233 c
+854 306 885 402 885 522 c
+885 563 l
+702 563 l
+
+1069 639 m
+1069 0 l
+885 0 l
+885 170 l
+843 102 791 52 728 19 c
+665 -13 589 -29 498 -29 c
+383 -29 292 3 224 67 c
+157 132 123 218 123 326 c
+123 452 165 547 249 611 c
+334 675 460 707 627 707 c
+885 707 l
+885 725 l
+885 810 857 875 801 921 c
+746 968 668 991 567 991 c
+503 991 441 983 380 968 c
+319 953 261 930 205 899 c
+205 1069 l
+272 1095 338 1114 401 1127 c
+464 1140 526 1147 586 1147 c
+748 1147 869 1105 949 1021 c
+1029 937 1069 810 1069 639 c
+
+ce} _d
+/c{1126 0 113 -29 999 1147 sc
+999 1077 m
+999 905 l
+947 934 895 955 842 969 c
+790 984 737 991 684 991 c
+565 991 472 953 406 877 c
+340 802 307 696 307 559 c
+307 422 340 316 406 240 c
+472 165 565 127 684 127 c
+737 127 790 134 842 148 c
+895 163 947 184 999 213 c
+999 43 l
+948 19 894 1 839 -11 c
+784 -23 726 -29 664 -29 c
+495 -29 361 24 262 130 c
+163 236 113 379 113 559 c
+113 742 163 885 263 990 c
+364 1095 501 1147 676 1147 c
+733 1147 788 1141 842 1129 c
+896 1118 948 1100 999 1077 c
+
+ce} _d
+/d{1300 0 113 -29 1114 1556 sc
+930 950 m
+930 1556 l
+1114 1556 l
+1114 0 l
+930 0 l
+930 168 l
+891 101 842 52 783 19 c
+724 -13 654 -29 571 -29 c
+436 -29 325 25 240 133 c
+155 241 113 383 113 559 c
+113 735 155 877 240 985 c
+325 1093 436 1147 571 1147 c
+654 1147 724 1131 783 1098 c
+842 1066 891 1017 930 950 c
+
+303 559 m
+303 424 331 317 386 240 c
+442 163 519 125 616 125 c
+713 125 790 163 846 240 c
+902 317 930 424 930 559 c
+930 694 902 800 846 877 c
+790 954 713 993 616 993 c
+519 993 442 954 386 877 c
+331 800 303 694 303 559 c
+
+ce} _d
+/e{1260 0 113 -29 1151 1147 sc
+1151 606 m
+1151 516 l
+305 516 l
+313 389 351 293 419 226 c
+488 160 583 127 705 127 c
+776 127 844 136 910 153 c
+977 170 1043 196 1108 231 c
+1108 57 l
+1042 29 974 8 905 -7 c
+836 -22 765 -29 694 -29 c
+515 -29 374 23 269 127 c
+165 231 113 372 113 549 c
+113 732 162 878 261 985 c
+360 1093 494 1147 662 1147 c
+813 1147 932 1098 1019 1001 c
+1107 904 1151 773 1151 606 c
+
+967 660 m
+966 761 937 841 882 901 c
+827 961 755 991 664 991 c
+561 991 479 962 417 904 c
+356 846 320 764 311 659 c
+967 660 l
+
+ce} _d
+/g{1300 0 113 -426 1114 1147 sc
+930 573 m
+930 706 902 810 847 883 c
+792 956 715 993 616 993 c
+517 993 440 956 385 883 c
+330 810 303 706 303 573 c
+303 440 330 337 385 264 c
+440 191 517 154 616 154 c
+715 154 792 191 847 264 c
+902 337 930 440 930 573 c
+
+1114 139 m
+1114 -52 1072 -193 987 -286 c
+902 -379 773 -426 598 -426 c
+533 -426 472 -421 415 -411 c
+358 -402 302 -387 248 -367 c
+248 -188 l
+302 -217 355 -239 408 -253 c
+461 -267 514 -274 569 -274 c
+690 -274 780 -242 840 -179 c
+900 -116 930 -21 930 106 c
+930 197 l
+892 131 843 82 784 49 c
+725 16 654 0 571 0 c
+434 0 323 52 239 157 c
+155 262 113 400 113 573 c
+113 746 155 885 239 990 c
+323 1095 434 1147 571 1147 c
+654 1147 725 1131 784 1098 c
+843 1065 892 1016 930 950 c
+930 1120 l
+1114 1120 l
+1114 139 l
+
+ce} _d
+/h{1298 0 186 0 1124 1556 sc
+1124 676 m
+1124 0 l
+940 0 l
+940 670 l
+940 776 919 855 878 908 c
+837 961 775 987 692 987 c
+593 987 514 955 457 892 c
+400 829 371 742 371 633 c
+371 0 l
+186 0 l
+186 1556 l
+371 1556 l
+371 946 l
+415 1013 467 1064 526 1097 c
+586 1130 655 1147 733 1147 c
+862 1147 959 1107 1025 1027 c
+1091 948 1124 831 1124 676 c
+
+ce} _d
+/i{569 0 193 0 377 1556 sc
+193 1120 m
+377 1120 l
+377 0 l
+193 0 l
+193 1120 l
+
+193 1556 m
+377 1556 l
+377 1323 l
+193 1323 l
+193 1556 l
+
+ce} _d
+/j{569 0 -37 -426 377 1556 sc
+193 1120 m
+377 1120 l
+377 -20 l
+377 -163 350 -266 295 -330 c
+241 -394 154 -426 33 -426 c
+-37 -426 l
+-37 -270 l
+12 -270 l
+82 -270 130 -254 155 -221 c
+180 -189 193 -122 193 -20 c
+193 1120 l
+
+193 1556 m
+377 1556 l
+377 1323 l
+193 1323 l
+193 1556 l
+
+ce} _d
+/m{1995 0 186 0 1821 1147 sc
+1065 905 m
+1111 988 1166 1049 1230 1088 c
+1294 1127 1369 1147 1456 1147 c
+1573 1147 1663 1106 1726 1024 c
+1789 943 1821 827 1821 676 c
+1821 0 l
+1636 0 l
+1636 670 l
+1636 777 1617 857 1579 909 c
+1541 961 1483 987 1405 987 c
+1310 987 1234 955 1179 892 c
+1124 829 1096 742 1096 633 c
+1096 0 l
+911 0 l
+911 670 l
+911 778 892 858 854 909 c
+816 961 757 987 678 987 c
+584 987 509 955 454 891 c
+399 828 371 742 371 633 c
+371 0 l
+186 0 l
+186 1120 l
+371 1120 l
+371 946 l
+413 1015 463 1065 522 1098 c
+581 1131 650 1147 731 1147 c
+812 1147 881 1126 938 1085 c
+995 1044 1038 984 1065 905 c
+
+ce} _d
+/n{1298 0 186 0 1124 1147 sc
+1124 676 m
+1124 0 l
+940 0 l
+940 670 l
+940 776 919 855 878 908 c
+837 961 775 987 692 987 c
+593 987 514 955 457 892 c
+400 829 371 742 371 633 c
+371 0 l
+186 0 l
+186 1120 l
+371 1120 l
+371 946 l
+415 1013 467 1064 526 1097 c
+586 1130 655 1147 733 1147 c
+862 1147 959 1107 1025 1027 c
+1091 948 1124 831 1124 676 c
+
+ce} _d
+/o{1253 0 113 -29 1141 1147 sc
+627 991 m
+528 991 450 952 393 875 c
+336 798 307 693 307 559 c
+307 425 335 319 392 242 c
+449 165 528 127 627 127 c
+725 127 803 166 860 243 c
+917 320 946 426 946 559 c
+946 692 917 797 860 874 c
+803 952 725 991 627 991 c
+
+627 1147 m
+787 1147 913 1095 1004 991 c
+1095 887 1141 743 1141 559 c
+1141 376 1095 232 1004 127 c
+913 23 787 -29 627 -29 c
+466 -29 340 23 249 127 c
+158 232 113 376 113 559 c
+113 743 158 887 249 991 c
+340 1095 466 1147 627 1147 c
+
+ce} _d
+/p{1300 0 186 -426 1188 1147 sc
+371 168 m
+371 -426 l
+186 -426 l
+186 1120 l
+371 1120 l
+371 950 l
+410 1017 458 1066 517 1098 c
+576 1131 647 1147 729 1147 c
+865 1147 975 1093 1060 985 c
+1145 877 1188 735 1188 559 c
+1188 383 1145 241 1060 133 c
+975 25 865 -29 729 -29 c
+647 -29 576 -13 517 19 c
+458 52 410 101 371 168 c
+
+997 559 m
+997 694 969 800 913 877 c
+858 954 781 993 684 993 c
+587 993 510 954 454 877 c
+399 800 371 694 371 559 c
+371 424 399 317 454 240 c
+510 163 587 125 684 125 c
+781 125 858 163 913 240 c
+969 317 997 424 997 559 c
+
+ce} _d
+/r{842 0 186 0 842 1147 sc
+842 948 m
+821 960 799 969 774 974 c
+750 980 723 983 694 983 c
+590 983 510 949 454 881 c
+399 814 371 717 371 590 c
+371 0 l
+186 0 l
+186 1120 l
+371 1120 l
+371 946 l
+410 1014 460 1064 522 1097 c
+584 1130 659 1147 748 1147 c
+761 1147 775 1146 790 1144 c
+805 1143 822 1140 841 1137 c
+842 948 l
+
+ce} _d
+/z{1075 0 88 0 987 1120 sc
+113 1120 m
+987 1120 l
+987 952 l
+295 147 l
+987 147 l
+987 0 l
+88 0 l
+88 168 l
+780 973 l
+113 973 l
+113 1120 l
+
+ce} _d
+end readonly def
+
+/BuildGlyph {
+ exch begin
+ CharStrings exch
+ 2 copy known not {pop /.notdef} if
+ true 3 1 roll get exec
+ end
+} _d
+
+/BuildChar {
+ 1 index /Encoding get exch get
+ 1 index /BuildGlyph get exec
+} _d
+
+FontName currentdict end definefont pop
+end
+%%EndProlog
+mpldict begin
+75.6 223.2 translate
+460.8 345.6 0 0 clipbox
+gsave
+0 0 m
+460.8 0 l
+460.8 345.6 l
+0 345.6 l
+cl
+1.000 setgray
+fill
+grestore
+gsave
+57.6 38.016 m
+414.72 38.016 l
+414.72 304.128 l
+57.6 304.128 l
+cl
+1.000 setgray
+fill
+grestore
+0.800 setlinewidth
+1 setlinejoin
+0 setlinecap
+[] 0 setdash
+0.000 setgray
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+0 0 m
+0 -3.5 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+73.8327 38.016 o
+grestore
+/DejaVuSans 10.000 selectfont
+gsave
+
+58.512415 23.422250 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /two glyphshow
+14.741211 0 m /zero glyphshow
+21.103516 0 m /period glyphshow
+24.282227 0 m /zero glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+0 0 m
+0 -3.5 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+116.55 38.016 o
+grestore
+gsave
+
+101.230118 23.422250 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /one glyphshow
+14.741211 0 m /seven glyphshow
+21.103516 0 m /period glyphshow
+24.282227 0 m /five glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+0 0 m
+0 -3.5 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+159.268 38.016 o
+grestore
+gsave
+
+143.947821 23.422250 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /one glyphshow
+14.741211 0 m /five glyphshow
+21.103516 0 m /period glyphshow
+24.282227 0 m /zero glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+0 0 m
+0 -3.5 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+201.986 38.016 o
+grestore
+gsave
+
+186.665525 23.422250 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /one glyphshow
+14.741211 0 m /two glyphshow
+21.103516 0 m /period glyphshow
+24.282227 0 m /five glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+0 0 m
+0 -3.5 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+244.704 38.016 o
+grestore
+gsave
+
+229.383228 23.422250 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /one glyphshow
+14.741211 0 m /zero glyphshow
+21.103516 0 m /period glyphshow
+24.282227 0 m /zero glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+0 0 m
+0 -3.5 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+287.421 38.016 o
+grestore
+gsave
+
+275.280619 23.422250 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /seven glyphshow
+14.741211 0 m /period glyphshow
+17.919922 0 m /five glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+0 0 m
+0 -3.5 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+330.139 38.016 o
+grestore
+gsave
+
+317.998322 23.422250 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /five glyphshow
+14.741211 0 m /period glyphshow
+17.919922 0 m /zero glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+0 0 m
+0 -3.5 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+372.857 38.016 o
+grestore
+gsave
+
+360.716026 23.422250 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /two glyphshow
+14.741211 0 m /period glyphshow
+17.919922 0 m /five glyphshow
+grestore
+gsave
+
+178.370937 9.750375 translate
+0.000000 rotate
+0.000000 0 m /z glyphshow
+5.249023 0 m /space glyphshow
+8.427734 0 m /p glyphshow
+14.775391 0 m /r glyphshow
+18.886719 0 m /z glyphshow
+24.135742 0 m /e glyphshow
+30.288086 0 m /d glyphshow
+36.635742 0 m /space glyphshow
+39.814453 0 m /h glyphshow
+46.152344 0 m /o glyphshow
+52.270508 0 m /m glyphshow
+62.011719 0 m /o glyphshow
+68.129883 0 m /g glyphshow
+74.477539 0 m /e glyphshow
+80.629883 0 m /n glyphshow
+86.967773 0 m /i glyphshow
+89.746094 0 m /z glyphshow
+94.995117 0 m /a glyphshow
+101.123047 0 m /c glyphshow
+106.621094 0 m /j glyphshow
+109.399414 0 m /aogonek glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 50.112 o
+grestore
+gsave
+
+19.959375 46.315125 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /one glyphshow
+14.741211 0 m /period glyphshow
+17.919922 0 m /zero glyphshow
+24.282227 0 m /zero glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 80.352 o
+grestore
+gsave
+
+19.959375 76.555125 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /zero glyphshow
+14.741211 0 m /period glyphshow
+17.919922 0 m /seven glyphshow
+24.282227 0 m /five glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 110.592 o
+grestore
+gsave
+
+19.959375 106.795125 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /zero glyphshow
+14.741211 0 m /period glyphshow
+17.919922 0 m /five glyphshow
+24.282227 0 m /zero glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 140.832 o
+grestore
+gsave
+
+19.959375 137.035125 translate
+0.000000 rotate
+0.000000 0 m /minus glyphshow
+8.378906 0 m /zero glyphshow
+14.741211 0 m /period glyphshow
+17.919922 0 m /two glyphshow
+24.282227 0 m /five glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 171.072 o
+grestore
+gsave
+
+28.334375 167.275125 translate
+0.000000 rotate
+0.000000 0 m /zero glyphshow
+6.362305 0 m /period glyphshow
+9.541016 0 m /zero glyphshow
+15.903320 0 m /zero glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 201.312 o
+grestore
+gsave
+
+28.334375 197.515125 translate
+0.000000 rotate
+0.000000 0 m /zero glyphshow
+6.362305 0 m /period glyphshow
+9.541016 0 m /two glyphshow
+15.903320 0 m /five glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 231.552 o
+grestore
+gsave
+
+28.334375 227.755125 translate
+0.000000 rotate
+0.000000 0 m /zero glyphshow
+6.362305 0 m /period glyphshow
+9.541016 0 m /five glyphshow
+15.903320 0 m /zero glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 261.792 o
+grestore
+gsave
+
+28.334375 257.995125 translate
+0.000000 rotate
+0.000000 0 m /zero glyphshow
+6.362305 0 m /period glyphshow
+9.541016 0 m /seven glyphshow
+15.903320 0 m /five glyphshow
+grestore
+gsave
+/o {
+gsave
+newpath
+translate
+0.8 setlinewidth
+1 setlinejoin
+
+0 setlinecap
+
+-0 0 m
+-3.5 0 l
+
+gsave
+0.000 setgray
+fill
+grestore
+stroke
+grestore
+} bind def
+57.6 292.032 o
+grestore
+gsave
+
+28.334375 288.235125 translate
+0.000000 rotate
+0.000000 0 m /one glyphshow
+6.362305 0 m /period glyphshow
+9.541016 0 m /zero glyphshow
+15.903320 0 m /zero glyphshow
+grestore
+gsave
+
+13.881250 122.822000 translate
+90.000000 rotate
+0.000000 0 m /z glyphshow
+5.249023 0 m /space glyphshow
+8.427734 0 m /p glyphshow
+14.775391 0 m /o glyphshow
+20.893555 0 m /space glyphshow
+24.072266 0 m /h glyphshow
+30.410156 0 m /o glyphshow
+36.528320 0 m /m glyphshow
+46.269531 0 m /o glyphshow
+52.387695 0 m /g glyphshow
+58.735352 0 m /e glyphshow
+64.887695 0 m /n glyphshow
+71.225586 0 m /i glyphshow
+74.003906 0 m /z glyphshow
+79.252930 0 m /a glyphshow
+85.380859 0 m /c glyphshow
+90.878906 0 m /j glyphshow
+93.657227 0 m /i glyphshow
+grestore
+1.500 setlinewidth
+2 setlinecap
+0.122 0.467 0.706 setrgbcolor
+gsave
+357.12 266.112 57.6 38.016 clipbox
+73.832727 292.032 m
+104.411412 290.780736 l
+131.086435 289.469535 l
+154.508406 288.09731 l
+174.677326 286.701851 l
+192.894414 285.224164 l
+209.159672 283.684395 l
+223.473099 282.113711 l
+236.485305 280.467946 l
+248.196291 278.767974 l
+258.606056 277.043937 l
+268.36521 275.206208 l
+277.473755 273.256657 l
+285.281079 271.368662 l
+292.437792 269.427684 l
+298.943895 267.456451 l
+305.449998 265.252299 l
+311.305491 263.033379 l
+316.510373 260.840794 l
+321.715256 258.405032 l
+326.269528 256.040834 l
+330.8238 253.422545 l
+334.727462 250.943512 l
+338.631124 248.212935 l
+342.534786 245.190481 l
+345.787837 242.413472 l
+349.040889 239.364908 l
+352.293941 236.002909 l
+355.546992 232.276518 l
+358.149433 228.991428 l
+360.751875 225.394448 l
+363.354316 221.438951 l
+365.956757 217.068522 l
+368.559198 212.214258 l
+371.16164 206.791106 l
+373.764081 200.692835 l
+375.715912 195.596536 l
+377.667743 189.975415 l
+379.619574 183.744 l
+381.571405 176.797196 l
+383.523236 169.004308 l
+385.475066 160.200737 l
+387.426897 150.176234 l
+389.378728 138.657882 l
+391.330559 125.284881 l
+392.63178 115.105433 l
+393.933001 103.701873 l
+395.234221 90.839273 l
+396.535442 76.218475 l
+397.836662 59.452541 l
+398.487273 50.112 l
+398.487273 50.112 l
+stroke
+grestore
+0.800 setlinewidth
+0 setlinejoin
+0.000 setgray
+gsave
+57.6 38.016 m
+57.6 304.128 l
+stroke
+grestore
+gsave
+414.72 38.016 m
+414.72 304.128 l
+stroke
+grestore
+gsave
+57.6 38.016 m
+414.72 38.016 l
+stroke
+grestore
+gsave
+57.6 304.128 m
+414.72 304.128 l
+stroke
+grestore
+
+end
+showpage
diff --git a/cw 4/img/PerlinNoiseDotProducts.png b/cw 4/img/PerlinNoiseDotProducts.png
new file mode 100644
index 0000000..8d68c33
Binary files /dev/null and b/cw 4/img/PerlinNoiseDotProducts.png differ
diff --git a/cw 4/img/PerlinNoiseGradientGrid.png b/cw 4/img/PerlinNoiseGradientGrid.png
new file mode 100644
index 0000000..3841843
Binary files /dev/null and b/cw 4/img/PerlinNoiseGradientGrid.png differ
diff --git a/cw 4/img/PerlinNoiseInterpolated.png b/cw 4/img/PerlinNoiseInterpolated.png
new file mode 100644
index 0000000..c535de9
Binary files /dev/null and b/cw 4/img/PerlinNoiseInterpolated.png differ
diff --git a/cw 4/img/blending1.webp b/cw 4/img/blending1.webp
new file mode 100644
index 0000000..4d9e4ec
Binary files /dev/null and b/cw 4/img/blending1.webp differ
diff --git a/cw 4/img/camera.jpg b/cw 4/img/camera.jpg
new file mode 100644
index 0000000..edb497c
Binary files /dev/null and b/cw 4/img/camera.jpg differ
diff --git a/cw 4/img/capture.webm b/cw 4/img/capture.webm
new file mode 100644
index 0000000..34357e5
Binary files /dev/null and b/cw 4/img/capture.webm differ
diff --git a/cw 4/img/coordinate_systems.jpg b/cw 4/img/coordinate_systems.jpg
new file mode 100644
index 0000000..be4c999
Binary files /dev/null and b/cw 4/img/coordinate_systems.jpg differ
diff --git a/cw 4/img/cubemaps_sampling.png b/cw 4/img/cubemaps_sampling.png
new file mode 100644
index 0000000..2e897a0
Binary files /dev/null and b/cw 4/img/cubemaps_sampling.png differ
diff --git a/cw 4/img/gamma_correction_brightness.png b/cw 4/img/gamma_correction_brightness.png
new file mode 100644
index 0000000..52e33b4
Binary files /dev/null and b/cw 4/img/gamma_correction_brightness.png differ
diff --git a/cw 4/img/lighting_result.png b/cw 4/img/lighting_result.png
new file mode 100644
index 0000000..3bbca23
Binary files /dev/null and b/cw 4/img/lighting_result.png differ
diff --git a/cw 4/img/noise_examples.jpg b/cw 4/img/noise_examples.jpg
new file mode 100644
index 0000000..e7c4878
Binary files /dev/null and b/cw 4/img/noise_examples.jpg differ
diff --git a/cw 4/img/shadow_mapping_projection.png b/cw 4/img/shadow_mapping_projection.png
new file mode 100644
index 0000000..b1843e7
Binary files /dev/null and b/cw 4/img/shadow_mapping_projection.png differ
diff --git a/cw 4/img/shadows1.bmp b/cw 4/img/shadows1.bmp
new file mode 100644
index 0000000..2ca100f
Binary files /dev/null and b/cw 4/img/shadows1.bmp differ
diff --git a/cw 4/img/spotlight.png b/cw 4/img/spotlight.png
new file mode 100644
index 0000000..d5a54a8
Binary files /dev/null and b/cw 4/img/spotlight.png differ
diff --git a/cw 4/img/stride_offest.jpg b/cw 4/img/stride_offest.jpg
new file mode 100644
index 0000000..216771f
Binary files /dev/null and b/cw 4/img/stride_offest.jpg differ
diff --git a/cw 4/img/stride_offest_2_2.jpg b/cw 4/img/stride_offest_2_2.jpg
new file mode 100644
index 0000000..d52cd14
Binary files /dev/null and b/cw 4/img/stride_offest_2_2.jpg differ
diff --git a/cw 4/img/struktura.jpg b/cw 4/img/struktura.jpg
new file mode 100644
index 0000000..4f93e04
Binary files /dev/null and b/cw 4/img/struktura.jpg differ
diff --git a/cw 4/img/sun.png b/cw 4/img/sun.png
new file mode 100644
index 0000000..ce2a691
Binary files /dev/null and b/cw 4/img/sun.png differ
diff --git a/cw 4/img/textures.png b/cw 4/img/textures.png
new file mode 100644
index 0000000..d8b23b7
Binary files /dev/null and b/cw 4/img/textures.png differ
diff --git a/cw 4/img/z_depth_graph.jpg b/cw 4/img/z_depth_graph.jpg
new file mode 100644
index 0000000..a5e6181
Binary files /dev/null and b/cw 4/img/z_depth_graph.jpg differ
diff --git a/cw 4/img/z_depth_graph2.jpg b/cw 4/img/z_depth_graph2.jpg
new file mode 100644
index 0000000..449d66b
Binary files /dev/null and b/cw 4/img/z_depth_graph2.jpg differ
diff --git a/cw 4/shaders/shader_2_1.frag b/cw 4/shaders/shader_2_1.frag
new file mode 100644
index 0000000..a3516a2
--- /dev/null
+++ b/cw 4/shaders/shader_2_1.frag
@@ -0,0 +1,9 @@
+#version 430 core
+
+in vec4 color;
+
+out vec4 out_color;
+void main()
+{
+ out_color = color;
+}
diff --git a/cw 4/shaders/shader_2_1.vert b/cw 4/shaders/shader_2_1.vert
new file mode 100644
index 0000000..380464c
--- /dev/null
+++ b/cw 4/shaders/shader_2_1.vert
@@ -0,0 +1,14 @@
+#version 430 core
+
+layout(location = 0) in vec4 vertexPosition;
+layout(location = 1) in vec4 vertexColor;
+
+uniform mat4 transformation;
+
+out vec4 color;
+
+void main()
+{
+ color = vertexColor;
+ gl_Position = transformation * vertexPosition;
+}
diff --git a/cw 4/shaders/shader_3_1.frag b/cw 4/shaders/shader_3_1.frag
new file mode 100644
index 0000000..a4d72cf
--- /dev/null
+++ b/cw 4/shaders/shader_3_1.frag
@@ -0,0 +1,8 @@
+#version 430 core
+
+
+out vec4 out_color;
+void main()
+{
+ out_color = vec4(0.9,0.3,1.0, 1.);
+}
diff --git a/cw 4/shaders/shader_3_1.vert b/cw 4/shaders/shader_3_1.vert
new file mode 100644
index 0000000..f487279
--- /dev/null
+++ b/cw 4/shaders/shader_3_1.vert
@@ -0,0 +1,12 @@
+#version 430 core
+
+layout(location = 0) in vec3 vertexPosition;
+layout(location = 1) in vec3 vertexNormal;
+layout(location = 2) in vec2 vertexTexCoord;
+
+uniform mat4 transformation;
+
+void main()
+{
+ gl_Position = transformation * vec4(vertexPosition, 1.0);
+}
diff --git a/cw 4/shaders/shader_3_2.frag b/cw 4/shaders/shader_3_2.frag
new file mode 100644
index 0000000..c560fba
--- /dev/null
+++ b/cw 4/shaders/shader_3_2.frag
@@ -0,0 +1,9 @@
+#version 430 core
+
+uniform vec3 objectColor;
+in vec3 normal;
+
+void main()
+{
+ gl_FragColor = vec4(normal, 1. );
+}
diff --git a/cw 4/shaders/shader_3_2.vert b/cw 4/shaders/shader_3_2.vert
new file mode 100644
index 0000000..73e0d12
--- /dev/null
+++ b/cw 4/shaders/shader_3_2.vert
@@ -0,0 +1,14 @@
+#version 430 core
+
+layout(location = 0) in vec3 vertexPosition;
+layout(location = 1) in vec3 vertexNormal;
+layout(location = 2) in vec2 vertexTexCoord;
+
+uniform mat4 transformation;
+out vec3 normal;
+
+void main()
+{
+ normal=vertexNormal;
+ gl_Position = transformation * vec4(vertexPosition, 1.0);
+}
diff --git a/cw 4/shaders/shader_4_1.frag b/cw 4/shaders/shader_4_1.frag
new file mode 100644
index 0000000..ade2821
--- /dev/null
+++ b/cw 4/shaders/shader_4_1.frag
@@ -0,0 +1,14 @@
+#version 430 core
+
+out vec4 fragColor;
+
+float linearizeDepth(float depth, float near, float far) {
+ return (-2.0 * near * far) / ((far - near) * depth - (far + near));
+}
+
+void main()
+{
+ float linearDepth = linearizeDepth(gl_FragCoord.z, 0.05, 20.0);
+
+ fragColor = vec4(1- linearDepth / 20.0, 1- linearDepth / 20.0, 1- linearDepth / 20.0, 1.0);
+}
\ No newline at end of file
diff --git a/cw 4/shaders/shader_4_1.vert b/cw 4/shaders/shader_4_1.vert
new file mode 100644
index 0000000..f487279
--- /dev/null
+++ b/cw 4/shaders/shader_4_1.vert
@@ -0,0 +1,12 @@
+#version 430 core
+
+layout(location = 0) in vec3 vertexPosition;
+layout(location = 1) in vec3 vertexNormal;
+layout(location = 2) in vec2 vertexTexCoord;
+
+uniform mat4 transformation;
+
+void main()
+{
+ gl_Position = transformation * vec4(vertexPosition, 1.0);
+}
diff --git a/cw 4/src/Box.cpp b/cw 4/src/Box.cpp
new file mode 100644
index 0000000..28445d3
--- /dev/null
+++ b/cw 4/src/Box.cpp
@@ -0,0 +1,55 @@
+
+
+// dane 36 wierzcholkow i kolorow opisujace model pudelka
+const float box[] = {
+
+ // points colors
+ 0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
+ 0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
+ -0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
+
+ 0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
+ -0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
+ -0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
+
+ 0.25f, 0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
+ -0.25f, 0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
+ 0.25f, -0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
+
+ 0.25f, -0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
+ -0.25f, 0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
+ -0.25f, -0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
+
+ -0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
+ -0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
+ -0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
+
+ -0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
+ -0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
+ -0.25f, 0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
+
+ 0.25f, 0.25f, 0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
+ 0.25f, -0.25f, -0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
+ 0.25f, -0.25f, 0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
+
+ 0.25f, 0.25f, 0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
+ 0.25f, 0.25f, -0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
+ 0.25f, -0.25f, -0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
+
+ 0.25f, 0.25f, -0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ 0.25f, 0.25f, 0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ -0.25f, 0.25f, 0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+
+ 0.25f, 0.25f, -0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ -0.25f, 0.25f, 0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ -0.25f, 0.25f, -0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+
+ 0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ -0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ 0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+
+ 0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ -0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ -0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+};
+
diff --git a/cw 4/src/Camera.cpp b/cw 4/src/Camera.cpp
new file mode 100644
index 0000000..90cc40c
--- /dev/null
+++ b/cw 4/src/Camera.cpp
@@ -0,0 +1,31 @@
+#include "Camera.h"
+
+glm::mat4 Core::createPerspectiveMatrix(float zNear, float zFar, float frustumScale)
+{
+ glm::mat4 perspective;
+ perspective[0][0] = 1.f;
+ perspective[1][1] = frustumScale;
+ perspective[2][2] = (zFar + zNear) / (zNear - zFar);
+ perspective[3][2] = (2 * zFar * zNear) / (zNear - zFar);
+ perspective[2][3] = -1;
+ perspective[3][3] = 0;
+
+ return perspective;
+}
+
+glm::mat4 Core::createViewMatrix( glm::vec3 position, glm::vec3 forward, glm::vec3 up )
+{
+ glm::vec3 side = glm::cross(forward, up);
+
+ // Trzeba pamietac o minusie przy ustawianiu osi Z kamery.
+ // Wynika to z tego, ze standardowa macierz perspektywiczna zaklada, ze "z przodu" jest ujemna (a nie dodatnia) czesc osi Z.
+ glm::mat4 cameraRotation;
+ cameraRotation[0][0] = side.x; cameraRotation[1][0] = side.y; cameraRotation[2][0] = side.z;
+ cameraRotation[0][1] = up.x; cameraRotation[1][1] = up.y; cameraRotation[2][1] = up.z;
+ cameraRotation[0][2] = -forward.x; cameraRotation[1][2] = -forward.y; cameraRotation[2][2] = -forward.z;
+
+ glm::mat4 cameraTranslation;
+ cameraTranslation[3] = glm::vec4(-position, 1.0f);
+
+ return cameraRotation * cameraTranslation;
+}
diff --git a/cw 4/src/Camera.h b/cw 4/src/Camera.h
new file mode 100644
index 0000000..54c29b3
--- /dev/null
+++ b/cw 4/src/Camera.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "glm.hpp"
+
+namespace Core
+{
+ glm::mat4 createPerspectiveMatrix(float zNear = 0.1f, float zFar = 100.0f, float frustumScale = 1.f);
+
+ // position - pozycja kamery
+ // forward - wektor "do przodu" kamery (jednostkowy)
+ // up - wektor "w gore" kamery (jednostkowy)
+ // up i forward musza byc ortogonalne!
+ glm::mat4 createViewMatrix(glm::vec3 position, glm::vec3 forward, glm::vec3 up);
+}
\ No newline at end of file
diff --git a/cw 4/src/Render_Utils.cpp b/cw 4/src/Render_Utils.cpp
new file mode 100644
index 0000000..18f71f9
--- /dev/null
+++ b/cw 4/src/Render_Utils.cpp
@@ -0,0 +1,128 @@
+#include "Render_Utils.h"
+
+#include
+
+#include "glew.h"
+#include "freeglut.h"
+#include
+#include
+#include
+
+
+
+void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
+ vertexArray = 0;
+ vertexBuffer = 0;
+ vertexIndexBuffer = 0;
+
+ std::vector textureCoord;
+ std::vector indices;
+ //tex coord must be converted to 2d vecs
+ for (unsigned int i = 0; i < mesh->mNumVertices; i++)
+ {
+ if (mesh->mTextureCoords[0] != nullptr) {
+ textureCoord.push_back(mesh->mTextureCoords[0][i].x);
+ textureCoord.push_back(mesh->mTextureCoords[0][i].y);
+ }
+ else {
+ textureCoord.push_back(0.0f);
+ textureCoord.push_back(0.0f);
+ }
+ }
+ if (mesh->mTextureCoords[0] == nullptr) {
+ std::cout << "no uv coords\n";
+ }
+ for (unsigned int i = 0; i < mesh->mNumFaces; i++)
+ {
+ aiFace face = mesh->mFaces[i];
+ // retrieve all indices of the face and store them in the indices vector
+ for (unsigned int j = 0; j < face.mNumIndices; j++)
+ indices.push_back(face.mIndices[j]);
+ }
+
+ unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
+ unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
+ unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
+ unsigned int vertexTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
+ unsigned int vertexBiTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
+
+ unsigned int vertexElementBufferSize = sizeof(unsigned int) * indices.size();
+ size = indices.size();
+
+ glGenVertexArrays(1, &vertexArray);
+ glBindVertexArray(vertexArray);
+
+
+ glGenBuffers(1, &vertexIndexBuffer);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
+
+ glGenBuffers(1, &vertexBuffer);
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
+ //std::cout << vertexBuffer;
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+ glEnableVertexAttribArray(2);
+ glEnableVertexAttribArray(3);
+ glEnableVertexAttribArray(4);
+
+ glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize + vertexBiTangentBufferSize, NULL, GL_STATIC_DRAW);
+
+ glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
+
+ glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
+
+ glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
+
+ glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, vertexTangentBufferSize, mesh->mTangents);
+
+ glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
+
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
+ glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
+ glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize));
+ glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize));
+
+}
+
+void Core::DrawVertexArray(const float * vertexArray, int numVertices, int elementSize )
+{
+ glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
+ glEnableVertexAttribArray(0);
+
+ glDrawArrays(GL_TRIANGLES, 0, numVertices);
+}
+
+void Core::DrawVertexArrayIndexed( const float * vertexArray, const int * indexArray, int numIndexes, int elementSize )
+{
+ glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
+ glEnableVertexAttribArray(0);
+
+ glDrawElements(GL_TRIANGLES, numIndexes, GL_UNSIGNED_INT, indexArray);
+}
+
+
+void Core::DrawVertexArray( const VertexData & data )
+{
+ int numAttribs = std::min(VertexData::MAX_ATTRIBS, data.NumActiveAttribs);
+ for(int i = 0; i < numAttribs; i++)
+ {
+ glVertexAttribPointer(i, data.Attribs[i].Size, GL_FLOAT, false, 0, data.Attribs[i].Pointer);
+ glEnableVertexAttribArray(i);
+ }
+ glDrawArrays(GL_TRIANGLES, 0, data.NumVertices);
+}
+
+void Core::DrawContext(Core::RenderContext& context)
+{
+
+ glBindVertexArray(context.vertexArray);
+ glDrawElements(
+ GL_TRIANGLES, // mode
+ context.size, // count
+ GL_UNSIGNED_INT, // type
+ (void*)0 // element array buffer offset
+ );
+ glBindVertexArray(0);
+}
diff --git a/cw 4/src/Render_Utils.h b/cw 4/src/Render_Utils.h
new file mode 100644
index 0000000..7901f23
--- /dev/null
+++ b/cw 4/src/Render_Utils.h
@@ -0,0 +1,71 @@
+#pragma once
+#include "glm.hpp"
+#include "glew.h"
+#include "objload.h"
+#include
+#include
+#include
+
+#define BUFFER_OFFSET(i) ((char *)NULL + (i))
+
+namespace Core
+{
+ struct RenderContext
+ {
+ GLuint vertexArray;
+ GLuint vertexBuffer;
+ GLuint vertexIndexBuffer;
+ int size = 0;
+
+
+ void initFromAssimpMesh(aiMesh* mesh);
+ };
+
+ // vertexArray - jednowymiarowa tablica zawierajaca wartosci opisujace pozycje kolejnych wierzcholkow w jednym ciagu (x1, y1, z1, w1, x2, y2, z2, w2, ...)
+ // numVertices - liczba wierzcholkow do narysowania
+ // elementSize - liczba wartosci opisujacych pojedynczy wierzcholek (np. 3 gdy wierzcholek opisany jest trojka (x, y, z))
+ void DrawVertexArray(const float * vertexArray, int numVertices, int elementSize);
+
+ // indexArray - jednowymiarowa tablica zawierajaca indeksy wierzcholkow kolejnych trojkatow w jednym ciagu (t1_i1, t1_i2, t1_i3, t2_i1, t2_i2, t2_i3, ...)
+ // numIndexes - liczba indeksow w tablicy indexArray
+ void DrawVertexArrayIndexed(const float * vertexArray, const int * indexArray, int numIndexes, int elementSize);
+
+
+ struct VertexAttribute
+ {
+ const void * Pointer;
+ int Size;
+ };
+
+ struct VertexData
+ {
+ static const int MAX_ATTRIBS = 8;
+ VertexAttribute Attribs[MAX_ATTRIBS];
+ int NumActiveAttribs;
+ int NumVertices;
+ };
+
+ // Ta funkcja sluzy do rysowania trojkatow, ktorych wierzcholki moga byc opisane wiecej niz jednym atrybutem.
+ // Funkcja przyjmuje jako parametr strukture, w ktorej nalezy zawrzec wszystkie potrzebne dane.
+ //
+ // Przykladowe wywolanie funkcji - narysowanie trojkata jak na pierwszych zajeciach:
+ /*
+
+ const float vertices[] = {
+ 0.25f, 0.25f, 0.0f, 1.0f,
+ 0.25f, -0.25f, 0.0f, 1.0f,
+ -0.25f, -0.25f, 0.0f, 1.0f
+ };
+
+ Core::VertexData vertexData;
+ vertexData.NumActiveAttribs = 1; // Liczba uzywanych atrybutow wierzcholka
+ vertexData.Attribs[0].Pointer = vertices; // Wskaznik na dane zerowego atrybutu
+ vertexData.Attribs[0].Size = 4; // Wielkosc zerowego atrybutu (ilosc liczb opisujacych ten atrybut w pojedynczym wierzcholku)
+ vertexData.NumVertices = 3; // Liczba wierzcholkow do narysowania
+ Core::DrawVertexArray(vertexData);
+
+ */
+ void DrawVertexArray(const VertexData & data);
+
+ void DrawContext(RenderContext& context);
+}
\ No newline at end of file
diff --git a/cw 4/src/Shader_Loader.cpp b/cw 4/src/Shader_Loader.cpp
new file mode 100644
index 0000000..6e118e9
--- /dev/null
+++ b/cw 4/src/Shader_Loader.cpp
@@ -0,0 +1,102 @@
+#include "Shader_Loader.h"
+#include
+#include
+#include
+
+using namespace Core;
+
+Shader_Loader::Shader_Loader(void){}
+Shader_Loader::~Shader_Loader(void){}
+
+std::string Shader_Loader::ReadShader(char *filename)
+{
+
+ std::string shaderCode;
+ std::ifstream file(filename, std::ios::in);
+
+ if (!file.good())
+ {
+ std::cout << "Can't read file " << filename << std::endl;
+ std::terminate();
+ }
+
+ file.seekg(0, std::ios::end);
+ shaderCode.resize((unsigned int)file.tellg());
+ file.seekg(0, std::ios::beg);
+ file.read(&shaderCode[0], shaderCode.size());
+ file.close();
+ return shaderCode;
+}
+
+GLuint Shader_Loader::CreateShader(GLenum shaderType, std::string
+ source, char* shaderName)
+{
+
+ int compile_result = 0;
+
+ GLuint shader = glCreateShader(shaderType);
+ const char *shader_code_ptr = source.c_str();
+ const int shader_code_size = source.size();
+
+ glShaderSource(shader, 1, &shader_code_ptr, &shader_code_size);
+ glCompileShader(shader);
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result);
+
+ //sprawdz bledy
+ if (compile_result == GL_FALSE)
+ {
+
+ int info_log_length = 0;
+ glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);
+ std::vector shader_log(info_log_length);
+ glGetShaderInfoLog(shader, info_log_length, NULL, &shader_log[0]);
+ std::cout << "ERROR compiling shader: " << shaderName << std::endl << &shader_log[0] << std::endl;
+ return 0;
+ }
+
+ return shader;
+}
+
+GLuint Shader_Loader::CreateProgram(char* vertexShaderFilename,
+ char* fragmentShaderFilename)
+{
+
+ //wczytaj shadery
+ std::string vertex_shader_code = ReadShader(vertexShaderFilename);
+ std::string fragment_shader_code = ReadShader(fragmentShaderFilename);
+
+ GLuint vertex_shader = CreateShader(GL_VERTEX_SHADER, vertex_shader_code, "vertex shader");
+ GLuint fragment_shader = CreateShader(GL_FRAGMENT_SHADER, fragment_shader_code, "fragment shader");
+
+ int link_result = 0;
+ //stworz shader
+ GLuint program = glCreateProgram();
+ glAttachShader(program, vertex_shader);
+ glAttachShader(program, fragment_shader);
+
+ glLinkProgram(program);
+ glGetProgramiv(program, GL_LINK_STATUS, &link_result);
+ //sprawdz bledy w linkerze
+ if (link_result == GL_FALSE)
+ {
+
+ int info_log_length = 0;
+ glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length);
+ std::vector program_log(info_log_length);
+ glGetProgramInfoLog(program, info_log_length, NULL, &program_log[0]);
+ std::cout << "Shader Loader : LINK ERROR" << std::endl << &program_log[0] << std::endl;
+ return 0;
+ }
+
+ glDetachShader(program, vertex_shader);
+ glDetachShader(program, fragment_shader);
+ glDeleteShader(vertex_shader);
+ glDeleteShader(fragment_shader);
+
+ return program;
+}
+
+void Shader_Loader::DeleteProgram( GLuint program )
+{
+ glDeleteProgram(program);
+}
diff --git a/cw 4/src/Shader_Loader.h b/cw 4/src/Shader_Loader.h
new file mode 100644
index 0000000..1fb9757
--- /dev/null
+++ b/cw 4/src/Shader_Loader.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "glew.h"
+#include "freeglut.h"
+#include
+
+namespace Core
+{
+
+ class Shader_Loader
+ {
+ private:
+
+ std::string ReadShader(char *filename);
+ GLuint CreateShader(GLenum shaderType,
+ std::string source,
+ char* shaderName);
+
+ public:
+
+ Shader_Loader(void);
+ ~Shader_Loader(void);
+ GLuint CreateProgram(char* VertexShaderFilename,
+ char* FragmentShaderFilename);
+
+ void DeleteProgram(GLuint program);
+
+ };
+}
\ No newline at end of file
diff --git a/cw 4/src/ex_4_1.hpp b/cw 4/src/ex_4_1.hpp
new file mode 100644
index 0000000..c6c6e81
--- /dev/null
+++ b/cw 4/src/ex_4_1.hpp
@@ -0,0 +1,234 @@
+#include "glew.h"
+#include
+#include "glm.hpp"
+#include "ext.hpp"
+#include
+#include
+
+#include "Shader_Loader.h"
+#include "Render_Utils.h"
+#include "Camera.h"
+
+#include "Box.cpp"
+#include
+#include
+#include
+#include
+
+
+
+GLuint program;
+Core::Shader_Loader shaderLoader;
+
+Core::RenderContext shipContext;
+Core::RenderContext sphereContext;
+Core::RenderContext starContext;
+
+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(-4.f, 0.f, 0.f);
+glm::vec3 spaceshipDir = glm::vec3(1.f, 0.f, 0.f);
+GLuint VAO, VBO;
+
+float aspectRatio = 1.f;
+float lastTime = -1.f;
+float deltaTime = 0.f;
+
+void updateDeltaTime(float time) {
+ if (lastTime < 0) {
+ lastTime = time;
+ return;
+ }
+
+ deltaTime = time - lastTime;
+ if (deltaTime > 0.1) deltaTime = 0.1;
+ lastTime = time;
+}
+
+glm::vec3 lightColor = glm::vec3(0.9, 0.7, 0.8);
+
+glm::mat4 createCameraMatrix()
+{
+ glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
+ glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraDir));
+ //glm::vec3 cameraUp = glm::vec3(0.f, 1.f, 0.f);
+ glm::mat4 cameraRotrationMatrix = glm::mat4({
+ cameraSide.x,cameraSide.y,cameraSide.z,0,
+ cameraUp.x,cameraUp.y,cameraUp.z ,0,
+ -cameraDir.x,-cameraDir.y,-cameraDir.z,0,
+ 0.,0.,0.,1.,
+ });
+
+ cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix);
+
+ glm::mat4 cameraMatrix = cameraRotrationMatrix * glm::translate(-cameraPos);
+
+ //glm::mat4 cameraMatrix = glm::mat4({
+ //1.,0.,0.,cameraPos.x,
+ //0.,1.,0.,cameraPos.y,
+ //0.,0.,1.,cameraPos.z,
+ //0.,0.,0.,1.,
+ //});
+
+ //cameraMatrix = glm::transpose(cameraMatrix);
+ //return Core::createViewMatrix(cameraPos, cameraDir, cameraUp);
+
+ return cameraMatrix;
+}
+
+glm::mat4 createPerspectiveMatrix()
+{
+
+ glm::mat4 perspectiveMatrix;
+ float n = 0.05;
+ float f = 20.;
+ float a1 = glm::min(aspectRatio, 1.f);
+ float a2 = glm::min(1 / aspectRatio, 1.f);
+ perspectiveMatrix = glm::mat4({
+ 1,0.,0.,0.,
+ 0.,aspectRatio,0.,0.,
+ 0.,0.,(f + n) / (n - f),2 * f * n / (n - f),
+ 0.,0.,-1.,0.,
+ });
+
+
+ perspectiveMatrix = glm::transpose(perspectiveMatrix);
+
+ return perspectiveMatrix;
+}
+
+void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, glm::vec3 scale) {
+
+ glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
+ glm::mat4 scaleMatrix = glm::scale(glm::mat4(1.0f), scale);
+ glm::mat4 transformation = viewProjectionMatrix * modelMatrix * scaleMatrix;
+ glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
+ //glUniform3f(glGetUniformLocation(program, "objectColor"), color.x, color.y, color.z);
+ Core::DrawContext(context);
+}
+
+
+
+void renderScene(GLFWwindow* window)
+{
+ glClear(GL_COLOR_BUFFER_BIT);
+ glClear(GL_DEPTH_BUFFER_BIT);
+ glm::vec3 starPosition = cameraPos + 5.0f * cameraDir + glm::vec3(0,3,0);
+ glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
+
+
+ glm::mat4 transformation;
+ float time = glfwGetTime();
+ updateDeltaTime(time);
+ glm::vec3 sunPosition = glm::vec3(0, 0, 0);
+ glm::vec3 earthPosition = glm::vec3(0, 3 * cos(time), 4 * sin(time));
+ glm::vec3 moonPosition = glm::vec3(0, 3 * cos(time) + cos(time * 2), 4 * sin(time) + sin(time * 2));
+
+
+ glUseProgram(program);
+ drawObjectColor(sphereContext, glm::translate(starPosition), glm::vec3(0, 0.0, 0), glm::vec3(0.1, 0.1, 0.1));
+ glClear(GL_DEPTH_BUFFER_BIT);
+ //float additionalRotationAngle = glm::radians(180.0f);
+ //glm::mat4 additionalRotation = glm::rotate(glm::mat4(1.0f), additionalRotationAngle, spaceshipDir);
+
+ //glm::mat4 shipRotationMatrix = glm::inverse(createCameraMatrix(spaceshipDir)) ;
+ //glm::mat4 shipPositionMatrix = glm::translate(spaceshipPos) * shipRotationMatrix* additionalRotation;
+ 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({
+ spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
+ spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
+ -spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0,
+ 0.,0.,0.,1.,
+ });
+ drawObjectColor(sphereContext, glm::translate(sunPosition), glm::vec3(0.9, 0.9, 0.1), glm::vec3(1, 1, 1));
+ drawObjectColor(sphereContext, glm::translate(earthPosition), glm::vec3(0.1, 0.2, 0.1), glm::vec3(0.5, 0.5, 0.5));
+ drawObjectColor(sphereContext, glm::translate(moonPosition), glm::vec3(0.1, 0.1, 0.1), glm::vec3(0.2, 0.2, 0.2));
+ drawObjectColor(shipContext, glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi()), glm::vec3(0.3, 0.3, 0.5), (glm::vec3(0.2f)));
+ glUseProgram(0);
+ glfwSwapBuffers(window);
+}
+void framebuffer_size_callback(GLFWwindow* window, int width, int height)
+{
+ aspectRatio = width / float(height);
+ glViewport(0, 0, width, height);
+}
+void loadModelToContext(std::string path, Core::RenderContext& context)
+{
+ Assimp::Importer import;
+ const aiScene * scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace);
+
+ if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
+ {
+ std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
+ return;
+ }
+ context.initFromAssimpMesh(scene->mMeshes[0]);
+}
+
+void init(GLFWwindow* window)
+{
+ glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
+
+ glEnable(GL_DEPTH_TEST);
+ program = shaderLoader.CreateProgram("shaders/shader_4_1.vert", "shaders/shader_4_1.frag");
+
+ loadModelToContext("./models/sphere.obj", sphereContext);
+ loadModelToContext("./models/spaceship.obj", shipContext);
+}
+
+void shutdown(GLFWwindow* window)
+{
+ shaderLoader.DeleteProgram(program);
+}
+
+//obsluga wejscia
+void processInput(GLFWwindow* window)
+{
+ glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
+ glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
+ float angleSpeed = 0.05f * deltaTime * 60;
+ float moveSpeed = 0.05f * deltaTime * 60;
+ if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
+ angleSpeed *= 3;
+ moveSpeed *= 3;
+ }
+ if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
+ glfwSetWindowShouldClose(window, true);
+ }
+ 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));
+
+ cameraPos = spaceshipPos - 0.3f * spaceshipDir + glm::vec3(0, 1, 0) * 0.1f;
+ cameraDir = spaceshipDir;
+
+
+}
+
+
+
+// funkcja jest glowna petla
+void renderLoop(GLFWwindow* window) {
+ while (!glfwWindowShouldClose(window))
+ {
+ processInput(window);
+
+ renderScene(window);
+ glfwPollEvents();
+ }
+}
+//}
\ No newline at end of file
diff --git a/cw 4/src/main.cpp b/cw 4/src/main.cpp
new file mode 100644
index 0000000..2549797
--- /dev/null
+++ b/cw 4/src/main.cpp
@@ -0,0 +1,47 @@
+#include "glew.h"
+
+#include
+#include "glm.hpp"
+#include "ext.hpp"
+#include
+#include
+
+#include "ex_4_1.hpp"
+
+
+
+int main(int argc, char** argv)
+{
+ // inicjalizacja glfw
+ glfwInit();
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+
+#ifdef __APPLE__
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
+#endif
+
+ // tworzenie okna za pomoca glfw
+ GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL);
+ if (window == NULL)
+ {
+ std::cout << "Failed to create GLFW window" << std::endl;
+ glfwTerminate();
+ return -1;
+ }
+ glfwMakeContextCurrent(window);
+
+ // ladowanie OpenGL za pomoca glew
+ glewInit();
+ glViewport(0, 0, 500, 500);
+
+ init(window);
+
+ // uruchomienie glownej petli
+ renderLoop(window);
+
+ shutdown(window);
+ glfwTerminate();
+ return 0;
+}
diff --git a/cw 4/src/objload.h b/cw 4/src/objload.h
new file mode 100644
index 0000000..004ab4e
--- /dev/null
+++ b/cw 4/src/objload.h
@@ -0,0 +1,291 @@
+/* Copyright (c) 2012, Gerhard Reitmayr
+ All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#ifndef OBJLOAD_H_
+#define OBJLOAD_H_
+
+#include
+#include
+#include
+#include
+#include
+#include