Using only assimp-based models, working on improving shaders
14
models/Asteroid_4_LOW_MODEL_.mtl
Normal file
@ -0,0 +1,14 @@
|
||||
# Blender MTL File: 'Asteroid_4_LOW_MODEL_.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl ASTEROID_LOW_POLY_4_
|
||||
Ns 225.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.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd textures\\asteroid_diffuse.png
|
||||
map_Bump textures\\asteroid_normal.png
|
60383
models/Asteroid_4_LOW_MODEL_.obj
Normal file
BIN
models/textures/Erath/2k_earth_clouds.jpg
Normal file
After Width: | Height: | Size: 943 KiB |
BIN
models/textures/Erath/2k_earth_daymap.jpg
Normal file
After Width: | Height: | Size: 452 KiB |
BIN
models/textures/Erath/2k_earth_nightmap.jpg
Normal file
After Width: | Height: | Size: 249 KiB |
BIN
models/textures/Erath/2k_earth_normal_map.tif
Normal file
BIN
models/textures/Erath/2k_earth_specular_map.jpg
Normal file
After Width: | Height: | Size: 282 KiB |
BIN
models/textures/Erath/2k_earth_specular_map.tif
Normal file
BIN
models/textures/Erath/2k_earth_with_clouds.jpg
Normal file
After Width: | Height: | Size: 1.8 MiB |
BIN
models/textures/Jupiter/2k_jupiter.jpg
Normal file
After Width: | Height: | Size: 487 KiB |
BIN
models/textures/Mars/2k_mars.jpg
Normal file
After Width: | Height: | Size: 733 KiB |
BIN
models/textures/Mercury/2k_mercury.jpg
Normal file
After Width: | Height: | Size: 852 KiB |
BIN
models/textures/Moon/2k_moon.jpg
Normal file
After Width: | Height: | Size: 1.0 MiB |
BIN
models/textures/Neptune/2k_neptune.jpg
Normal file
After Width: | Height: | Size: 236 KiB |
BIN
models/textures/Saturn/2k_saturn.jpg
Normal file
After Width: | Height: | Size: 195 KiB |
BIN
models/textures/Saturn/2k_saturn_ring_alpha.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
models/textures/Sun/2k_sun.jpg
Normal file
After Width: | Height: | Size: 803 KiB |
BIN
models/textures/Uranus/2k_uranus.jpg
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
models/textures/Venus/2k_venus_atmosphere.jpg
Normal file
After Width: | Height: | Size: 224 KiB |
BIN
models/textures/Venus/2k_venus_surface.jpg
Normal file
After Width: | Height: | Size: 864 KiB |
BIN
models/textures/asteroid_diffuse.png
Normal file
After Width: | Height: | Size: 21 MiB |
BIN
models/textures/asteroid_normal.png
Normal file
After Width: | Height: | Size: 34 MiB |
@ -5,7 +5,7 @@ layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 cameraPos;
|
||||
uniform sampler2D colorTexture;
|
||||
uniform sampler2D diffuseTexture;
|
||||
uniform vec3 colorTex;
|
||||
in vec3 interpNormal;
|
||||
in vec3 fragPos;
|
||||
@ -16,7 +16,7 @@ void main()
|
||||
vec3 normal = normalize(interpNormal);
|
||||
vec3 V = normalize(cameraPos-fragPos);
|
||||
float coef = pow(max(0,dot(normal,V)),2);
|
||||
vec4 textureColor = texture2D(colorTexture, -vTexCoord);
|
||||
vec4 textureColor = texture2D(diffuseTexture, -vTexCoord);
|
||||
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * colorTex;
|
||||
FragColor = vec4(texture + texture * coef, 1.0);
|
||||
|
||||
|
@ -9,12 +9,14 @@ struct PointLight {
|
||||
float intensity;
|
||||
};
|
||||
|
||||
#define NR_POINT_LIGHTS 5
|
||||
#define MAX_POINT_LIGHTS 64
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 cameraPos;
|
||||
uniform sampler2D colorTexture;
|
||||
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||
uniform sampler2D diffuseTexture;
|
||||
uniform sampler2D normalTexture;
|
||||
uniform PointLight pointLights[MAX_POINT_LIGHTS];
|
||||
uniform int LightsCount;
|
||||
|
||||
in vec3 interpNormal;
|
||||
in vec3 fragPos;
|
||||
@ -25,10 +27,10 @@ in vec2 vTexCoord;
|
||||
void main()
|
||||
{
|
||||
vec3 fragColor = vec3(0,0,0);
|
||||
vec4 textureColor = texture2D(colorTexture, vTexCoord);
|
||||
vec4 textureColor = texture2D(diffuseTexture, vTexCoord);
|
||||
vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * textureColor;
|
||||
vec3 normal = normalize(interpNormal);
|
||||
for(int i = 0; i < NR_POINT_LIGHTS; i++)
|
||||
for(int i = 0; i < LightsCount; i++)
|
||||
{
|
||||
vec3 lightDir = normalize(pointLights[i].position - fragPos);
|
||||
|
||||
|
103
src/main.cpp
@ -44,19 +44,10 @@ static GLubyte* g_particule_color_data;
|
||||
GLuint particle_vertex_buffer;
|
||||
GLuint particles_position_buffer;
|
||||
GLuint particles_color_buffer;
|
||||
double partX = -6;
|
||||
double partY = 0;
|
||||
double partXdir = 0;
|
||||
double partYdir = 0;
|
||||
double partAdir = 0;
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
Core::RenderContext armContext;
|
||||
std::vector<Core::Node> arm;
|
||||
int ballIndex;
|
||||
bool bothEngines = true;
|
||||
|
||||
|
||||
GLuint textureShip_normals;
|
||||
GLuint sunTexture;
|
||||
GLuint earthTexture;
|
||||
@ -64,16 +55,16 @@ GLuint moonTexture;
|
||||
GLuint skyboxTexture;
|
||||
GLuint shipTexture;
|
||||
GLuint particleTexture;
|
||||
obj::Model sphereModel;
|
||||
obj::Model cubeModel;
|
||||
obj::Model shipModel;
|
||||
|
||||
Core::RenderContext sphereContext;
|
||||
Core::RenderContext cubeContext;
|
||||
Core::RenderContext shipContext;
|
||||
//Core::RenderContext sphereContext;
|
||||
|
||||
//Core::RenderContext shipContext;
|
||||
|
||||
//assimp
|
||||
std::shared_ptr<Model> cube;
|
||||
std::shared_ptr<Model> sphere;
|
||||
std::shared_ptr<Model> corvette;
|
||||
std::shared_ptr<Model> asteroid;
|
||||
//std::vector<Core::RenderContext> corvetteMeshes;
|
||||
std::shared_ptr<Model> crewmate;
|
||||
|
||||
@ -264,6 +255,22 @@ void drawFromAssimpModel(GLuint program, std::shared_ptr<Model> model, glm::mat4
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void drawFromAssimpTexture(GLuint program, std::shared_ptr<Model> model, glm::mat4 modelMatrix, glm::vec3 color, GLuint texID)
|
||||
{
|
||||
glUseProgram(program);
|
||||
|
||||
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniform3f(glGetUniformLocation(program, "colorTex"), color.x, color.y, color.z);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
|
||||
Core::SetActiveTexture(texID, "diffuseTexture", program, 0);
|
||||
|
||||
model->Draw(program);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
//Skybox
|
||||
unsigned int loadCubemap(std::vector<std::string> faces)
|
||||
{
|
||||
@ -296,7 +303,7 @@ unsigned int loadCubemap(std::vector<std::string> faces)
|
||||
|
||||
return textureID;
|
||||
}
|
||||
void drawSkybox(GLuint program, Core::RenderContext context, GLuint texID)
|
||||
void drawSkybox(GLuint program, std::shared_ptr<Model> cubeModel, GLuint texID)
|
||||
{
|
||||
glUseProgram(program);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
@ -307,7 +314,7 @@ void drawSkybox(GLuint program, Core::RenderContext context, GLuint texID)
|
||||
glUniform1i(glGetUniformLocation(program, "skybox"), 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
|
||||
Core::DrawContext(context);
|
||||
cubeModel->Draw(program);
|
||||
glDepthFunc(GL_LESS);
|
||||
//glDepthMask(GL_TRUE);
|
||||
glUseProgram(0);
|
||||
@ -381,7 +388,7 @@ void drawObjectTexture(GLuint program, Core::RenderContext context, glm::mat4 mo
|
||||
glUniform3f(glGetUniformLocation(program, "colorTex"), texture.x, texture.y, texture.z);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
|
||||
Core::SetActiveTexture(texID, "colorTexture", program, 0);
|
||||
Core::SetActiveTexture(texID, "diffuseTexture", program, 0);
|
||||
|
||||
Core::DrawContext(context);
|
||||
glUseProgram(0);
|
||||
@ -442,6 +449,7 @@ void renderScene()
|
||||
glm::mat4 crewmateModelMatrix = glm::translate(glm::vec3(0, 1, 1)) * glm::rotate(time / 2, glm::vec3(1, 0, 1)) * glm::scale(glm::vec3(0.01));
|
||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.7f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
|
||||
|
||||
glm::mat4 testModelMatrix = glm::translate(glm::vec3(1, 0, 0));
|
||||
|
||||
glUseProgram(programTex);
|
||||
|
||||
@ -454,6 +462,8 @@ void renderScene()
|
||||
glm::mat4 engineRight = glm::translate(shipModelMatrix, glm::vec3(-450, 0, -1500));
|
||||
lights[3].position = glm::vec3(engineRight[3][0], engineRight[3][1], engineRight[3][2]);
|
||||
|
||||
|
||||
glUniform1i(glGetUniformLocation(programTex,"LightsCount"), lights.size());
|
||||
for (int i = 0; i < lights.size(); i++)
|
||||
{
|
||||
std::string col = "pointLights[" + std::to_string(i) + "].color";
|
||||
@ -469,16 +479,18 @@ void renderScene()
|
||||
drawFromAssimpModel(programTex, corvette, shipModelMatrix, glm::vec3(1));
|
||||
drawFromAssimpModel(programTex, crewmate, crewmateModelMatrix, glm::vec3(1));
|
||||
|
||||
drawFromAssimpModel(programTex, asteroid, testModelMatrix, glm::vec3(1));
|
||||
|
||||
//rysowanie Ziemi z ksiezycem
|
||||
drawObjectTexture(programTex, sphereContext, earth, glm::vec3(0.8f, 0.8f, 0.8f), earthTexture);
|
||||
drawObjectTexture(programTex, sphereContext, moon, glm::vec3(0.9f, 1.0f, 0.9f), moonTexture);
|
||||
drawObjectTexture(programTex, sphereContext, planet1, glm::vec3(0.4f, 0.2f, 0.9f), moonTexture);
|
||||
drawFromAssimpTexture(programTex, sphere, earth, glm::vec3(0.8f, 0.8f, 0.8f), earthTexture);
|
||||
drawFromAssimpTexture(programTex, sphere, moon, glm::vec3(0.9f, 1.0f, 0.9f), moonTexture);
|
||||
drawFromAssimpTexture(programTex, sphere, planet1, glm::vec3(0.4f, 0.2f, 0.9f), moonTexture);
|
||||
|
||||
glUseProgram(programSun);
|
||||
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
|
||||
drawObjectTexture(programSun, sphereContext, sunModelMatrix, glm::vec3(3.5f, 3.8f, 3.8f), sunTexture);
|
||||
drawObjectTexture(programSun, sphereContext, sunModelMatrix2, glm::vec3(0.9f, 0.9f, 2.0f), sunTexture);
|
||||
drawFromAssimpTexture(programSun, sphere, sunModelMatrix, glm::vec3(3.5f, 3.8f, 3.8f), sunTexture);
|
||||
drawFromAssimpTexture(programSun, sphere, sunModelMatrix2, glm::vec3(0.9f, 0.9f, 2.0f), sunTexture);
|
||||
|
||||
//particlepart
|
||||
glUseProgram(programParticle);
|
||||
@ -505,36 +517,7 @@ void renderScene()
|
||||
lights[2].intensity = 0.00001;
|
||||
lights[3].intensity = 0.00001;
|
||||
}
|
||||
/*
|
||||
if (cameraPos[0] < partX)
|
||||
{
|
||||
partXdir = 1;
|
||||
}
|
||||
else if (cameraPos[0] > partX)
|
||||
{
|
||||
partXdir = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
partXdir = 0;
|
||||
}
|
||||
if (cameraPos[2] < partY)
|
||||
{
|
||||
partYdir = 1;
|
||||
}
|
||||
else if (cameraPos[2] > partY)
|
||||
{
|
||||
partYdir = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
partYdir = 0;
|
||||
}
|
||||
if (cameraDir[0] < 0)
|
||||
{
|
||||
partAdir = cameraDir[0] * -1;
|
||||
}
|
||||
*/
|
||||
|
||||
for (int i = 0; i < newparticles; i++) {
|
||||
int particleIndex = FindUnusedParticle();
|
||||
ParticlesContainer[particleIndex].life = 2.0f;
|
||||
@ -554,7 +537,7 @@ void renderScene()
|
||||
|
||||
|
||||
float spread = 0.8;
|
||||
glm::vec3 maindir = -1 * cameraDir; //glm::vec3(partXdir*partAdir, -0.3f, partYdir*partAdir);
|
||||
glm::vec3 maindir = -1 * cameraDir;
|
||||
glm::vec3 randomdir = glm::vec3(
|
||||
(rand() % 2000 - 1000.0f) / 5000.0f,
|
||||
(rand() % 2000 - 1000.0f) / 5000.0f,
|
||||
@ -616,7 +599,7 @@ void renderScene()
|
||||
|
||||
SortParticles();
|
||||
drawParticles(ParticlesCount, transformation);
|
||||
drawSkybox(programSkybox, cubeContext, skyboxTexture);
|
||||
drawSkybox(programSkybox, cube, skyboxTexture);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
@ -748,12 +731,14 @@ void init()
|
||||
|
||||
corvette = std::make_shared<Model>("models/Corvette-F3.obj");
|
||||
crewmate = std::make_shared<Model>("models/space_humster.obj");
|
||||
asteroid = std::make_shared<Model>("models/Asteroid_4_LOW_MODEL_.obj");
|
||||
//shipModel = obj::loadModelFromFile("models/spaceship.obj");
|
||||
sphereModel = obj::loadModelFromFile("models/sphere.obj");
|
||||
cubeModel = obj::loadModelFromFile("models/cube.obj");
|
||||
//sphereModel = obj::loadModelFromFile("models/sphere.obj");
|
||||
sphere = std::make_shared<Model>("models/sphere.obj");
|
||||
cube = std::make_shared<Model>("models/cube.obj");
|
||||
|
||||
sphereContext.initFromOBJ(sphereModel);
|
||||
cubeContext.initFromOBJ(cubeModel);
|
||||
//sphereContext.initFromOBJ(sphereModel);
|
||||
//cubeContext.initFromOBJ(cubeModel);
|
||||
//shipContext.initFromOBJ(shipModel);
|
||||
shipTexture = Core::LoadTexture("textures/spaceship.png");
|
||||
sunTexture = Core::LoadTexture("textures/sun.png");
|
||||
|
17
src/mesh.h
@ -69,17 +69,24 @@ public:
|
||||
string number;
|
||||
string name = textures[i].type;
|
||||
if (name == "texture_diffuse")
|
||||
number = std::to_string(diffuseNr++);
|
||||
glUniform1i(glGetUniformLocation(program, "diffuseTexture"), i);
|
||||
//number = std::to_string(diffuseNr++);
|
||||
|
||||
else if (name == "texture_specular")
|
||||
number = std::to_string(specularNr++); // transfer unsigned int to stream
|
||||
glUniform1i(glGetUniformLocation(program, "specularTexture"), i);
|
||||
//number = std::to_string(specularNr++); // transfer unsigned int to stream
|
||||
|
||||
else if (name == "texture_normal")
|
||||
number = std::to_string(normalNr++); // transfer unsigned int to stream
|
||||
glUniform1i(glGetUniformLocation(program, "normalTexture"), i);
|
||||
//number = std::to_string(normalNr++); // transfer unsigned int to stream
|
||||
|
||||
else if (name == "texture_height")
|
||||
number = std::to_string(heightNr++); // transfer unsigned int to stream
|
||||
glUniform1i(glGetUniformLocation(program, "heightTexture"), i);
|
||||
//number = std::to_string(heightNr++); // transfer unsigned int to stream
|
||||
|
||||
// now set the sampler to the correct texture unit
|
||||
//glUniform1i(glGetUniformLocation(program, (name + number).c_str()), i);
|
||||
glUniform1i(glGetUniformLocation(program, "colorTexture"), i);
|
||||
//glUniform1i(glGetUniformLocation(program, "colorTexture"), i);
|
||||
// and finally bind the texture
|
||||
glBindTexture(GL_TEXTURE_2D, textures[i].id);
|
||||
}
|
||||
|