prototype of engine lights
This commit is contained in:
parent
69e858e2b9
commit
e7fd0f5fa2
@ -57,7 +57,7 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
struct PointLight {
|
struct PointLight {
|
||||||
vec3 position;
|
vec3 position;
|
||||||
vec3 color;
|
vec3 color;
|
||||||
|
float intensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NR_POINT_LIGHTS 2
|
#define NR_POINT_LIGHTS 3
|
||||||
|
|
||||||
uniform vec3 objectColor;
|
uniform vec3 objectColor;
|
||||||
uniform vec3 lightPos;
|
uniform vec3 lightPos;
|
||||||
@ -32,14 +33,14 @@ void main()
|
|||||||
vec3 V = normalize(cameraPos-fragPos);
|
vec3 V = normalize(cameraPos-fragPos);
|
||||||
vec3 R = reflect(-lightDir,normal);
|
vec3 R = reflect(-lightDir,normal);
|
||||||
|
|
||||||
float dist = 1 + distance(fragPos, pointLights[i].position) / 50;
|
float dist = distance(fragPos, pointLights[i].position) / 5;
|
||||||
float distance = (1/dist) * (1/dist);
|
float distance = (1/dist) * (1/dist);
|
||||||
|
|
||||||
float spec = pow(max(0,dot(R,V)),2);
|
float spec = pow(max(0,dot(R,V)),2);
|
||||||
float diff = max(0,dot(normal,normalize(lightDir)));
|
float diff = max(0,dot(normal,normalize(lightDir)));
|
||||||
|
|
||||||
vec3 diffuse = pointLights[i].color * diff * distance;
|
vec3 diffuse = pointLights[i].color * diff * distance * pointLights[i].intensity;
|
||||||
vec3 specular = spec * pointLights[i].color * (1/dist);
|
vec3 specular = spec * pointLights[i].color * (pointLights[i].intensity/dist);
|
||||||
|
|
||||||
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * pointLights[i].color;
|
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * pointLights[i].color;
|
||||||
fragColor += mix(texture,texture*diffuse+vec3(1)*specular,0.9);
|
fragColor += mix(texture,texture*diffuse+vec3(1)*specular,0.9);
|
||||||
|
47
src/main.cpp
47
src/main.cpp
@ -56,12 +56,19 @@ glm::vec3 cameraDir;
|
|||||||
|
|
||||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||||
|
|
||||||
|
glm::vec3 sunPos = glm::vec3(10.0f, 0.0f, -5.0f);
|
||||||
|
glm::vec3 sunPos2 = glm::vec3(25.0f, -1.0f, 10.0f);
|
||||||
|
glm::vec3 engineLight = cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0);
|
||||||
|
|
||||||
|
|
||||||
struct Light {
|
struct Light {
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 color;
|
glm::vec3 color;
|
||||||
|
float intensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int engineLightTimer;
|
||||||
|
|
||||||
//wczytywanie skyboxa (musi byc jpg!)
|
//wczytywanie skyboxa (musi byc jpg!)
|
||||||
std::vector<std::string> faces
|
std::vector<std::string> faces
|
||||||
{
|
{
|
||||||
@ -84,7 +91,13 @@ void keyboard(unsigned char key, int x, int y)
|
|||||||
{
|
{
|
||||||
case 'z': cameraAngle -= angleSpeed; break;
|
case 'z': cameraAngle -= angleSpeed; break;
|
||||||
case 'x': cameraAngle += angleSpeed; break;
|
case 'x': cameraAngle += angleSpeed; break;
|
||||||
case 'w': cameraPos += cameraDir * moveSpeed; break;
|
case 'w':
|
||||||
|
{
|
||||||
|
cameraPos += cameraDir * moveSpeed;
|
||||||
|
lights[2].intensity = 0.001;
|
||||||
|
engineLightTimer = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
||||||
case 'd': cameraPos += glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
case 'd': cameraPos += glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||||
case 'a': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
case 'a': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||||
@ -237,8 +250,7 @@ void renderScene()
|
|||||||
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||||
|
|
||||||
//ustalanie pozycji s³oñc (lightPos)
|
//ustalanie pozycji s³oñc (lightPos)
|
||||||
glm::vec3 sunPos = glm::vec3(10.0f, 0.0f, -5.0f);
|
|
||||||
glm::vec3 sunPos2 = glm::vec3(25.0f, -1.0f, 10.0f);
|
|
||||||
|
|
||||||
//rysowanie s³oñc
|
//rysowanie s³oñc
|
||||||
glm::mat4 sunModelMatrix = glm::mat4(1.0f);
|
glm::mat4 sunModelMatrix = glm::mat4(1.0f);
|
||||||
@ -250,27 +262,36 @@ void renderScene()
|
|||||||
sunModelMatrix2 = glm::translate(sunModelMatrix2, sunPos2);
|
sunModelMatrix2 = glm::translate(sunModelMatrix2, sunPos2);
|
||||||
drawObjectTexture(programSun, sphereContext, sunModelMatrix2, glm::vec3(0.9f, 0.9f, 2.0f), sunTexture);
|
drawObjectTexture(programSun, sphereContext, sunModelMatrix2, glm::vec3(0.9f, 0.9f, 2.0f), sunTexture);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glUseProgram(programTex);
|
glUseProgram(programTex);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lights[0].position = sunPos;
|
lights[0].position = sunPos;
|
||||||
lights[1].position = sunPos2;
|
lights[1].position = sunPos2;
|
||||||
|
|
||||||
|
lights[2].position = cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0);
|
||||||
|
lights[2].color = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
for (int i = 0; i < lights.size(); i++)
|
for (int i = 0; i < lights.size(); i++)
|
||||||
{
|
{
|
||||||
std::string col = "pointLights[" + std::to_string(i) + "].color";
|
std::string col = "pointLights[" + std::to_string(i) + "].color";
|
||||||
std::string pos = "pointLights[" + std::to_string(i) + "].position";
|
std::string pos = "pointLights[" + std::to_string(i) + "].position";
|
||||||
|
std::string ins = "pointLights[" + std::to_string(i) + "].intensity";
|
||||||
glUniform3f(glGetUniformLocation(programTex, col.c_str()), lights[i].color.x, lights[i].color.y, lights[i].color.z);
|
glUniform3f(glGetUniformLocation(programTex, col.c_str()), lights[i].color.x, lights[i].color.y, lights[i].color.z);
|
||||||
glUniform3f(glGetUniformLocation(programTex, pos.c_str()), lights[i].position.x, lights[i].position.y, lights[i].position.z);
|
glUniform3f(glGetUniformLocation(programTex, pos.c_str()), lights[i].position.x, lights[i].position.y, lights[i].position.z);
|
||||||
|
glUniform1f(glGetUniformLocation(programTex, ins.c_str()), lights[i].intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||||
|
|
||||||
|
|
||||||
//rysowanie statku
|
//rysowanie statku
|
||||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.6f + 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 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
|
||||||
drawFromAssimpModel(programTex, corvette, shipModelMatrix, glm::vec3(1));
|
drawFromAssimpModel(programTex, corvette, shipModelMatrix, glm::vec3(1));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//rysowanie Ziemi z ksiê¿ycem
|
//rysowanie Ziemi z ksiê¿ycem
|
||||||
glm::mat4 earth = drawPlanet(time / 5.0f, sunPos*glm::vec3(1.5f,1,1), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(-10.5f, 0.0f, -10.5f), glm::vec3(0.5f, 0.5f, 0.5f));
|
glm::mat4 earth = drawPlanet(time / 5.0f, sunPos*glm::vec3(1.5f,1,1), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(-10.5f, 0.0f, -10.5f), glm::vec3(0.5f, 0.5f, 0.5f));
|
||||||
glm::mat4 moon = drawMoon(earth, time/2.0f, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0, 1, 1), glm::vec3(1.5f, 1.0f, 1.0f), glm::vec3(0.3f, 0.3f, 0.3f));
|
glm::mat4 moon = drawMoon(earth, time/2.0f, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0, 1, 1), glm::vec3(1.5f, 1.0f, 1.0f), glm::vec3(0.3f, 0.3f, 0.3f));
|
||||||
@ -278,6 +299,8 @@ void renderScene()
|
|||||||
drawObjectTexture(programTex, sphereContext, earth, glm::vec3(0.8f, 0.8f, 0.8f), earthTexture);
|
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, moon, glm::vec3(0.9f, 1.0f, 0.9f), moonTexture);
|
||||||
|
|
||||||
|
if (engineLightTimer < 50) engineLightTimer++;
|
||||||
|
else lights[2].intensity = 0.0001;
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
@ -309,15 +332,23 @@ void init()
|
|||||||
skyboxTexture = loadCubemap(faces);
|
skyboxTexture = loadCubemap(faces);
|
||||||
|
|
||||||
Light l1;
|
Light l1;
|
||||||
l1.position = glm::vec3(0.0f, 0.0f, 0.0f);
|
l1.position = sunPos;
|
||||||
l1.color = glm::vec3(0.8f, 0.8f, 0.7f);
|
l1.color = glm::vec3(0.8f, 0.8f, 0.7f);
|
||||||
|
l1.intensity = 3;
|
||||||
lights.push_back(l1);
|
lights.push_back(l1);
|
||||||
|
|
||||||
Light l2;
|
Light l2;
|
||||||
l2.position = glm::vec3(5.0f, -1.0f, 10.0f);
|
l2.position = sunPos2;
|
||||||
l2.color = glm::vec3(0.5f, 0.5f, 0.5f);
|
l2.color = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||||
|
l2.intensity = 3;
|
||||||
lights.push_back(l2);
|
lights.push_back(l2);
|
||||||
|
|
||||||
|
Light l3;
|
||||||
|
l3.position = engineLight;
|
||||||
|
l3.color = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||||
|
l3.intensity = 0.0001;
|
||||||
|
lights.push_back(l3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdown()
|
void shutdown()
|
||||||
|
Loading…
Reference in New Issue
Block a user