Add support for fog into the scene shader
This commit is contained in:
parent
ccdf4ab3c9
commit
95d6981461
|
@ -27,6 +27,9 @@ uniform vec3 specular_color;
|
||||||
uniform vec3 emissive_color;
|
uniform vec3 emissive_color;
|
||||||
uniform vec3 backlight_color;
|
uniform vec3 backlight_color;
|
||||||
|
|
||||||
|
uniform vec3 fog_color;
|
||||||
|
uniform float fog_strength;
|
||||||
|
|
||||||
uniform bool isIlluminated;
|
uniform bool isIlluminated;
|
||||||
uniform bool isTextured;
|
uniform bool isTextured;
|
||||||
uniform bool isVertexColored;
|
uniform bool isVertexColored;
|
||||||
|
@ -138,7 +141,15 @@ vec3 phong(vec3 basecolor, vec3 nnormal) {
|
||||||
return basecolor + specular_color * specular_component;
|
return basecolor + specular_color * specular_component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float near = 0.1;
|
||||||
|
const float far = 5000.0;
|
||||||
|
float linearDepth() {
|
||||||
|
float z = gl_FragCoord.z * 2.0 - 1.0;
|
||||||
|
return (2.0 * near * far) / (far + near - z * (far - near));
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
vec3 nnormal = get_nnormal(); // normalized normal
|
vec3 nnormal = get_nnormal(); // normalized normal
|
||||||
vec4 c = vec4(vec3(1.0), opacity);
|
vec4 c = vec4(vec3(1.0), opacity);
|
||||||
if (isVertexColored) c *= color;
|
if (isVertexColored) c *= color;
|
||||||
|
@ -152,8 +163,9 @@ void main() {
|
||||||
}
|
}
|
||||||
if (backlight_strength > 0.05)
|
if (backlight_strength > 0.05)
|
||||||
c.rgb += backlight_color * clamp((dot(normalize(vertex), nnormal) + backlight_strength) / backlight_strength, 0, 1);
|
c.rgb += backlight_color * clamp((dot(normalize(vertex), nnormal) + backlight_strength) / backlight_strength, 0, 1);
|
||||||
//c.rgb = diffuse_color;
|
|
||||||
//c.rgb = emissive_color;
|
float fog = linearDepth()/1500;
|
||||||
//c.rgb = specular_color;
|
c.rgb = mix(c.rgb, fog_color, pow(fog,1.2)*fog_strength);
|
||||||
|
|
||||||
color_out = c;
|
color_out = c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ sf::SoundBuffer* buffer;
|
||||||
Gloom::Shader* current_shader = nullptr;
|
Gloom::Shader* current_shader = nullptr;
|
||||||
Gloom::Shader* prev_shader = nullptr; // The last shader to glDrawElements
|
Gloom::Shader* prev_shader = nullptr; // The last shader to glDrawElements
|
||||||
|
|
||||||
|
// uniforms in the scene
|
||||||
|
vec3 fog_color = vec3(0);
|
||||||
|
float fog_strength = 0;
|
||||||
|
|
||||||
// the framebuffer we render the scene to before post-processing
|
// the framebuffer we render the scene to before post-processing
|
||||||
GLuint framebufferID = 0;
|
GLuint framebufferID = 0;
|
||||||
|
@ -246,14 +249,18 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
|
||||||
case GEOMETRY:
|
case GEOMETRY:
|
||||||
if (transparent_nodes!=nullptr && node->has_transparancy()) {
|
if (transparent_nodes!=nullptr && node->has_transparancy()) {
|
||||||
// defer to sorted pass later on
|
// defer to sorted pass later on
|
||||||
//transparent_nodes->emplace_back(node, s, glm::length(vec3(node->MVP[3])));
|
|
||||||
//transparent_nodes->push_back({node, s, glm::length(vec3(node->MVP[3]))});
|
|
||||||
transparent_nodes->emplace_back(node, s, glm::length(vec3(node->MVP*vec4(0,0,0,1))));
|
transparent_nodes->emplace_back(node, s, glm::length(vec3(node->MVP*vec4(0,0,0,1))));
|
||||||
//transparent_nodes->push_back({node, s, glm::length(vec3(node->MVP*vec4(0,0,0,1)))});
|
|
||||||
}
|
}
|
||||||
else if(node->vertexArrayObjectID != -1) {
|
else if(node->vertexArrayObjectID != -1) {
|
||||||
if (node->opacity <= 0.05) break;
|
if (node->opacity <= 0.05) break;
|
||||||
// load uniforms
|
|
||||||
|
// load scene uniforms
|
||||||
|
if (shader_changed) { // guaranteed at start of every frame, due to post_shader
|
||||||
|
glUniform3fv(s->location("fog_color"), 1, glm::value_ptr(fog_color));
|
||||||
|
glUniform1f( s->location("fog_strength"), fog_strength);
|
||||||
|
}
|
||||||
|
|
||||||
|
// load material uniforms
|
||||||
um4fv(MVP);
|
um4fv(MVP);
|
||||||
um4fv(MV);
|
um4fv(MV);
|
||||||
um4fv(MVnormal);
|
um4fv(MVnormal);
|
||||||
|
|
Loading…
Reference in New Issue