Compare commits

..

No commits in common. "master" and "v1.0.0" have entirely different histories.

78 changed files with 30 additions and 212 deletions

View File

@ -1,6 +0,0 @@
Slightly adapted version (by Joey de Vries) of Cyborg model.
From: 3dregenerator
Downloaded at: http://tf3dm.com/3d-model/cyborg-78.html
For Personal Use Only.

Binary file not shown.

Binary file not shown.

View File

@ -1,14 +0,0 @@
# Blender MTL File: 'cyborg.blend'
# Material Count: 1
newmtl Cyborg
Ns 92.156863
Ka 0.000000 0.000000 0.000000
Kd 0.512000 0.512000 0.512000
Ks 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd cyborg_diffuse.png
map_Bump cyborg_normal.png
map_Ks cyborg_specular.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1020 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 562 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 846 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 386 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 621 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 840 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 570 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 640 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 976 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 513 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 729 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -1,79 +0,0 @@
# Blender MTL File: 'nanosuit.blend'
# Material Count: 6
newmtl Arm
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump arm_showroom_ddn.png
map_Ka arm_showroom_refl.png
map_Kd arm_dif.png
map_Ks arm_showroom_spec.png
newmtl Body
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd body_dif.png
map_Bump body_showroom_ddn.png
map_Ka body_showroom_refl.png
map_Ks body_showroom_spec.png
newmtl Glass
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump glass_ddn.png
map_Ka glass_refl.png
map_Kd glass_dif.png
newmtl Hand
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump hand_showroom_ddn.png
map_Ka hand_showroom_refl.png
map_Kd hand_dif.png
map_Ks hand_showroom_spec.png
newmtl Helmet
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump helmet_showroom_ddn.png
map_Ka helmet_showroom_refl.png
map_Kd helmet_diff.png
map_Ks helmet_showroom_spec.png
newmtl Leg
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump leg_showroom_ddn.png
map_Ka leg_showroom_refl.png
map_Kd leg_dif.png
map_Ks leg_showroom_spec.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 MiB

View File

@ -1,13 +0,0 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl Mars
Ns 96.078443
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.0 0.0 0.0
Ni 1.000000
d 1.000000
illum 2
map_Kd mars.png

View File

@ -1,2 +0,0 @@
From TurboSquid, by Gerhald3D: https://www.turbosquid.com/3d-models/realistic-mars-photorealistic-2k-3d-1277433
Slightly modified by Joey de Vries: keep only planet layer, assign diffuse texture to material slot, desaturated texture somewhat.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -1,16 +0,0 @@
# Blender 3.1.0 MTL File: 'None'
# www.blender.org
newmtl trashbag
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd diffuse.jpg
map_Ns roughness.jpg
map_Ks specular.jpg
map_Bump -bm 1.000000 normal.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 KiB

View File

@ -189,9 +189,6 @@
<ClCompile Include="settingpage.cpp">
<Filter>Source Files\Qt Widgets\Pages\Setting Page</Filter>
</ClCompile>
<ClCompile Include="terrain.cpp">
<Filter>Source Files\OpenGL Abstractions</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="camera.h">

View File

@ -229,7 +229,7 @@ void SceneViewer::paintGL() {
_dirLight->updateShader(_shaderProgram, 0);
}
_shaderProgram.setUniform("dirlightnr", _dirLight != nullptr && _dirLightOn ? 1 : 0);
_shaderProgram.setUniform("dirlightnr", _dirLight != nullptr ? 1 : 0);
// Render objects
for (auto object : _objects) {

View File

@ -162,7 +162,7 @@ SettingPage::SettingPage(QWidget* parent) :
});
_dirLightTheta = new ModelAttributeSlide("Rotate\u03B8", 0, 360, 3600, _mainWidget);
_dirLightTheta->setValue(270);
_dirLightTheta->setValue(0);
_dirLightTheta->setEnabled(false);
_mainLayout->addWidget(_dirLightTheta);
_dirLightTheta->show();
@ -170,15 +170,15 @@ SettingPage::SettingPage(QWidget* parent) :
// Calculate direction vector by theta and phi
float theta = _dirLightTheta->val(); // theta angle
float phi = _dirLightPhi->val(); // phi angle
float x = sin(glm::radians(phi)) * cos(glm::radians(theta));
float y = sin(glm::radians(phi)) * sin(glm::radians(theta));
float z = cos(glm::radians(phi));
glm::vec3 dir = glm::normalize(glm::vec3(x, y, z));
float x = sin(theta) * cos(phi);
float y = sin(theta) * sin(phi);
float z = cos(theta);
glm::vec3 dir = glm::vec3(x, y, z);
emit onSettingsChanged(QPair<QString, QString>("dirLightDir", QString::number(dir.x) + "," + QString::number(dir.y) + "," + QString::number(dir.z)));
});
_dirLightPhi = new ModelAttributeSlide("Rotate\u03C6", 0, 360, 3600, _mainWidget);
_dirLightPhi->setValue(90);
_dirLightPhi->setValue(0);
_dirLightPhi->setEnabled(false);
_mainLayout->addWidget(_dirLightPhi);
_dirLightPhi->show();
@ -186,10 +186,10 @@ SettingPage::SettingPage(QWidget* parent) :
// Calculate direction vector by theta and phi
float theta = _dirLightTheta->val(); // theta angle
float phi = _dirLightPhi->val(); // phi angle
float x = sin(glm::radians(phi)) * cos(glm::radians(theta));
float y = sin(glm::radians(phi)) * sin(glm::radians(theta));
float z = cos(glm::radians(phi));
glm::vec3 dir = glm::normalize(glm::vec3(x, y, z));
float x = sin(theta) * cos(phi);
float y = sin(theta) * sin(phi);
float z = cos(theta);
glm::vec3 dir = glm::vec3(x, y, z);
emit onSettingsChanged(QPair<QString, QString>("dirLightDir", QString::number(dir.x) + "," + QString::number(dir.y) + "," + QString::number(dir.z)));
});
}

View File

@ -6,7 +6,6 @@
#include "terrain.h"
#include "utils.h"
#include "vertex.h"
#include "logger.h"
Terrain::Terrain(std::string path){
// Convert '\ ' to '/' for Windows
@ -138,23 +137,14 @@ void Terrain::render() {
}
float Terrain::GetHeight(float px, float pz) {
float fx = px + double(height) / 2;
float fz = pz + double(width) / 2;
float fx = px + height / 2;
float fz = pz + width / 2;
int x = ((int)fx) % height;
int z = ((int)fz) % width;
int gx = (x + 1) % height;
int gz = (z + 1) % width;
// prevent retrieving out of bounds
if (x < 0) x = 0;
if (z < 0) z = 0;
if (gx < 0) gx = 0;
if (gz < 0) gz = 0;
if (x > height - 1) x = height - 1;
if (z > width - 1) z = width - 1;
if (gx > height - 1) gx = height - 1;
if (gz > width - 1) gz = width - 1;
float ans = (x - fx) * (Point[gx][gz] - Point[x][z]) + Point[x][z];
//float ans = Point[x][z];
@ -163,34 +153,16 @@ float Terrain::GetHeight(float px, float pz) {
}
glm::vec3 Terrain::GetNormal(glm::vec3 pos) {
// construct a triangle with its geometry center at pos
glm::vec3 p1 = pos + glm::vec3(-1.0f, 0.0f, -0.57735f);
glm::vec3 p2 = pos + glm::vec3(1.0f, 0.0f, -0.57735f);
glm::vec3 p3 = pos + glm::vec3(0.0f, 0.0f, 1.1547f);
// calculate the height
p1.y = GetHeight(p1.x, p1.z);
p2.y = GetHeight(p2.x, p2.z);
p3.y = GetHeight(p3.x, p3.z);
float fx = pos.x;
float fz = pos.z;
// calculate the normal
glm::vec3 v1 = p2 - p1;
glm::vec3 v2 = p3 - p1;
glm::vec3 normal = glm::normalize(glm::cross(v1, v2));
glm::vec3 point1(fx - 1, GetHeight(fx - 1, fz - 1), fz - 1);
glm::vec3 point2(fx + 1, GetHeight(fx + 1, fz + 1), fz + 1);
// make the normal point up
if (normal.y < 0.0f) {
normal = -normal;
}
//glm::vec3 point1(fx - 1, GetHeight(fx - 1, fz - 1), fz - 1);
//glm::vec3 point2(fx + 1, GetHeight(fx + 1, fz + 1), fz + 1);
//glm::vec3 l1 = pos - point1;
//glm::vec3 l2 = point2 - point1;
//glm::vec3 ans = glm::normalize(glm::cross(l1, l2));
return normal;
glm::vec3 l1 = pos - point1;
glm::vec3 l2 = point2 - point1;
glm::vec3 ans = glm::normalize(glm::cross(l1, l2));
return ans;
}
HitRecord Terrain::hit(const Ray& ray) {
@ -221,38 +193,17 @@ HitRecord Terrain::hit(const Ray& ray) {
glm::vec3 startPosition = lastRayPosition;
glm::vec3 endPosition = orig;
// Binary search with 64 steps. Try to find the exact collision point
float threshold = 0.1f;
glm::vec3 mid;
while(true) {
mid = (startPosition + endPosition) * 0.5f;
map_height = GetHeight(mid.x, mid.z);
if (abs(mid.y - map_height) < threshold) {
break;
}
else if (mid.y - endPosition.y < 0.001f) {
// if no more space to search, return
break;
}
Logger::debug("Current height difference: " + std::to_string(abs(mid.y - map_height)));
if (mid.y > map_height)
{
startPosition = mid;
}
// Binary search with 32 steps. Try to find the exact collision point
for (int i = 0; i < 32; i++)
{
// Binary search pass
glm::vec3 middlePoint = (startPosition + endPosition) * 0.5f;
if (middlePoint.y < height)
endPosition = middlePoint;
else
{
endPosition = mid;
}
startPosition = middlePoint;
}
//{
// // Binary search pass
// glm::vec3 middlePoint = (startPosition + endPosition) * 0.5f;
// if (middlePoint.y < height)
// endPosition = middlePoint;
// else
// startPosition = middlePoint;
//}
glm::vec3 position = mid;
glm::vec3 position = (startPosition + endPosition) * 0.5f;
glm::vec3 normal = GetNormal(position);
// If t > 200, consider the ray as not hitted

View File

Before

Width:  |  Height:  |  Size: 1.8 MiB

After

Width:  |  Height:  |  Size: 1.8 MiB

View File

Before

Width:  |  Height:  |  Size: 5.8 MiB

After

Width:  |  Height:  |  Size: 5.8 MiB

View File

Before

Width:  |  Height:  |  Size: 14 MiB

After

Width:  |  Height:  |  Size: 14 MiB

View File

Before

Width:  |  Height:  |  Size: 4.2 MiB

After

Width:  |  Height:  |  Size: 4.2 MiB

View File

Before

Width:  |  Height:  |  Size: 5.2 MiB

After

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 381 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

View File

Before

Width:  |  Height:  |  Size: 723 KiB

After

Width:  |  Height:  |  Size: 723 KiB

View File

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 274 KiB

View File

Before

Width:  |  Height:  |  Size: 462 KiB

After

Width:  |  Height:  |  Size: 462 KiB

View File

Before

Width:  |  Height:  |  Size: 588 KiB

After

Width:  |  Height:  |  Size: 588 KiB

View File

Before

Width:  |  Height:  |  Size: 525 KiB

After

Width:  |  Height:  |  Size: 525 KiB

View File

Before

Width:  |  Height:  |  Size: 338 KiB

After

Width:  |  Height:  |  Size: 338 KiB