add fog
This commit is contained in:
parent
9eeb0a4227
commit
f31ed04dd6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,6 +5,7 @@ uniform vec3 lightDir;
|
|||||||
|
|
||||||
in vec3 interpNormal;
|
in vec3 interpNormal;
|
||||||
in vec2 interpTexCoord;
|
in vec2 interpTexCoord;
|
||||||
|
in float visibility;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@ -12,5 +13,5 @@ void main()
|
|||||||
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
|
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
|
||||||
vec3 normal = normalize(interpNormal);
|
vec3 normal = normalize(interpNormal);
|
||||||
float diffuse = max(dot(normal, -lightDir), 0.0);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,18 @@ uniform mat4 modelMatrix;
|
|||||||
|
|
||||||
out vec3 interpNormal;
|
out vec3 interpNormal;
|
||||||
out vec2 interpTexCoord;
|
out vec2 interpTexCoord;
|
||||||
|
out float visibility;
|
||||||
|
|
||||||
|
const float density = 0.15;
|
||||||
|
const float gradient = 1.5;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
||||||
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
||||||
interpTexCoord = vertexTexCoord;
|
interpTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
|
float distance = length(gl_Position.xyz);
|
||||||
|
visibility = exp(-pow((distance*density),gradient));
|
||||||
|
visibility = clamp(visibility, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ void renderScene()
|
|||||||
perspectiveMatrix = Core::createPerspectiveMatrix();
|
perspectiveMatrix = Core::createPerspectiveMatrix();
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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 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;
|
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.5f) * glm::mat4_cast(glm::inverse(rotation)) * shipInitialTransformation;
|
||||||
|
Loading…
Reference in New Issue
Block a user