diff --git a/resources/Nebula1.png b/resources/Nebula1.png index a222707a8c..43eef76472 100644 Binary files a/resources/Nebula1.png and b/resources/Nebula1.png differ diff --git a/resources/Nebula2.png b/resources/Nebula2.png index ae63caec84..8dbcc0ec34 100644 Binary files a/resources/Nebula2.png and b/resources/Nebula2.png differ diff --git a/resources/Nebula3.png b/resources/Nebula3.png index 90f66f3df5..b4cc3d9935 100644 Binary files a/resources/Nebula3.png and b/resources/Nebula3.png differ diff --git a/resources/shaders/nebula.shader b/resources/shaders/nebula.shader new file mode 100644 index 0000000000..9a6c4909d8 --- /dev/null +++ b/resources/shaders/nebula.shader @@ -0,0 +1,32 @@ +[vertex] +uniform vec4 color; +uniform mat4 view; +uniform mat4 projection; +uniform mat4 model; + +attribute vec3 position; +attribute vec2 texcoords; + +varying vec2 fragtexcoords; +varying vec4 fragcolor; + +void main() +{ + fragtexcoords = texcoords; + gl_Position = projection * ((view * model * vec4(position, 1.0)) + vec4((texcoords.x - 0.5) * color.a, (texcoords.y - 0.5) * color.a, 0.0, 0.0)); + fragcolor = vec4(color.rgb, 1.0); +} + +[fragment] +uniform sampler2D textureMap; + +varying vec4 fragcolor; +varying vec2 fragtexcoords; + +void main() +{ + vec4 texColor = texture2D(textureMap, fragtexcoords.st); + texColor.rgb *= texColor.a; // Pre-multiply alpha channel + + gl_FragColor = texColor * fragcolor; +} diff --git a/src/shaderRegistry.cpp b/src/shaderRegistry.cpp index 0bc8c7e094..936e73dad1 100644 --- a/src/shaderRegistry.cpp +++ b/src/shaderRegistry.cpp @@ -26,6 +26,7 @@ namespace ShaderRegistry "shaders/basic", "shaders/basicColor", "shaders/billboard", + "shaders/nebula", "shaders/objectShader", "shaders/objectShader:ILLUMINATION", "shaders/objectShader:SPECULAR", diff --git a/src/shaderRegistry.h b/src/shaderRegistry.h index c4dbf0e995..20e71388df 100644 --- a/src/shaderRegistry.h +++ b/src/shaderRegistry.h @@ -29,6 +29,7 @@ namespace ShaderRegistry Basic = 0, BasicColor, Billboard, + Nebula, Object, ObjectIllumination, ObjectSpecular, diff --git a/src/spaceObjects/nebula.cpp b/src/spaceObjects/nebula.cpp index 0108b6bfab..f1a6242ab3 100644 --- a/src/spaceObjects/nebula.cpp +++ b/src/spaceObjects/nebula.cpp @@ -59,7 +59,7 @@ Nebula::Nebula() void Nebula::draw3DTransparent() { - ShaderRegistry::ScopedShader shader(ShaderRegistry::Shaders::Billboard); + ShaderRegistry::ScopedShader shader(ShaderRegistry::Shaders::Nebula); std::array quad{ glm::vec3{}, {0.f, 1.f}, @@ -71,7 +71,13 @@ void Nebula::draw3DTransparent() gl::ScopedVertexAttribArray positions(shader.get().attribute(ShaderRegistry::Attributes::Position)); gl::ScopedVertexAttribArray texcoords(shader.get().attribute(ShaderRegistry::Attributes::Texcoords)); - for(int n=0; n 1.0f) // Clamp alpha to 1.0 for clouds further away than the limit + alpha = 1.0f; - // setup our quad. + // Setup quad vertices with the current position for (auto& point : quad) { point.vertex = position; } textureManager.getTexture("Nebula" + string(cloud.texture) + ".png")->bind(); - glUniform4f(shader.get().uniform(ShaderRegistry::Uniforms::Color), alpha * 0.8f, alpha * 0.8f, alpha * 0.8f, size); + // Update uniforms for each cloud + glUniform4f(shader.get().uniform(ShaderRegistry::Uniforms::Color), alpha, alpha, alpha, size); auto model_matrix = glm::translate(getModelMatrix(), {cloud.offset.x, cloud.offset.y, 0}); glUniformMatrix4fv(shader.get().uniform(ShaderRegistry::Uniforms::Model), 1, GL_FALSE, glm::value_ptr(model_matrix)); - glVertexAttribPointer(positions.get(), 3, GL_FLOAT, GL_FALSE, sizeof(VertexAndTexCoords), (GLvoid*)quad.data()); - glVertexAttribPointer(texcoords.get(), 2, GL_FLOAT, GL_FALSE, sizeof(VertexAndTexCoords), (GLvoid*)((char*)quad.data() + sizeof(glm::vec3))); std::initializer_list indices = { 0, 3, 2, 0, 2, 1 }; glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, std::begin(indices)); } + + // Restore blending after the loop + glBlendFunc(GL_ONE, GL_ONE); + glBlendEquation(GL_FUNC_ADD); } void Nebula::drawOnRadar(sp::RenderTarget& renderer, glm::vec2 position, float scale, float rotation, bool long_range)