This commit is contained in:
Łukasz Śliwiński 2022-02-02 21:07:30 +01:00
parent 9eeb0a4227
commit f31ed04dd6
8 changed files with 11 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,7 @@ uniform vec3 lightDir;
in vec3 interpNormal;
in vec2 interpTexCoord;
in float visibility;
void main()
{
@ -12,5 +13,5 @@ void main()
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
vec3 normal = normalize(interpNormal);
float diffuse = max(dot(normal, -lightDir), 0.0);
gl_FragColor = vec4(color * diffuse, 1.0);
gl_FragColor = mix(vec4(0.0f, 0.2f, 0.5f, 1.0f), vec4(color * diffuse, 1.0), visibility);
}

View File

@ -9,10 +9,18 @@ uniform mat4 modelMatrix;
out vec3 interpNormal;
out vec2 interpTexCoord;
out float visibility;
const float density = 0.15;
const float gradient = 1.5;
void main()
{
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
interpTexCoord = vertexTexCoord;
float distance = length(gl_Position.xyz);
visibility = exp(-pow((distance*density),gradient));
visibility = clamp(visibility, 0.0, 1.0);
}

View File

@ -111,7 +111,7 @@ void renderScene()
perspectiveMatrix = Core::createPerspectiveMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
glClearColor(0.0f, 0.2f, 0.5f, 1.0f);
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0,-0.25f,0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0,1,0)) * glm::scale(glm::vec3(0.25f));
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.5f) * glm::mat4_cast(glm::inverse(rotation)) * shipInitialTransformation;