Commit 0d6c3a56 authored by Georg Schaefer's avatar Georg Schaefer
Browse files

replace point sprites with quads generated via geometry shader

parent 4df261c2
......@@ -7,7 +7,7 @@ out vec4 frag_color;
uniform sampler2D albedo_texture;
void main() {
vec4 color = texture(albedo_texture, gl_PointCoord);
vec4 color = texture(albedo_texture, gl_TexCoord[0].st);
if (color.a <= 0.f) {
discard;
}
......
#version 330
layout(points) in;
layout(triangle_strip, max_vertices = 6) out;
in float _size_[];
in vec3 _color_[];
out vec3 color_;
uniform mat4 projection;
void main() {
float half_size = _size_[0] * 0.5f;
gl_TexCoord[0].st = vec2(0.f);
gl_Position = gl_in[0].gl_Position;
gl_Position.xy += vec2(-half_size);
gl_Position = projection * gl_Position;
color_ = _color_[0];
EmitVertex();
gl_TexCoord[0].st = vec2(1.f, 0.f);
gl_Position = gl_in[0].gl_Position;
gl_Position.xy += vec2(half_size, -half_size);
gl_Position = projection * gl_Position;
color_ = _color_[0];
EmitVertex();
gl_TexCoord[0].st = vec2(1.f, 1.f);
gl_Position = gl_in[0].gl_Position;
gl_Position.xy += vec2(half_size);
gl_Position = projection * gl_Position;
color_ = _color_[0];
EmitVertex();
gl_TexCoord[0].st = vec2(1.f, 1.f);
gl_Position = gl_in[0].gl_Position;
gl_Position.xy += vec2(half_size);
gl_Position = projection * gl_Position;
color_ = _color_[0];
EmitVertex();
gl_TexCoord[0].st = vec2(0.f);
gl_Position = gl_in[0].gl_Position;
gl_Position.xy += vec2(-half_size);
gl_Position = projection * gl_Position;
color_ = _color_[0];
EmitVertex();
gl_TexCoord[0].st = vec2(0.f, 1.f);
gl_Position = gl_in[0].gl_Position;
gl_Position.xy += vec2(-half_size, half_size);
gl_Position = projection * gl_Position;
color_ = _color_[0];
EmitVertex();
EndPrimitive();
}
......@@ -4,14 +4,14 @@ in vec3 _position;
in float _size;
in vec3 _color;
out vec3 color_;
out float _size_;
out vec3 _color_;
uniform mat4 projection;
uniform mat4 view;
void main() {
vec4 position = projection * view * vec4(_position, 1.f);
vec4 position = view * vec4(_position, 1.f);
gl_Position = position;
gl_PointSize = _size / position.z;
color_ = _color;
_size_ = _size;
_color_ = _color;
}
......@@ -294,6 +294,11 @@ namespace gdw {
throw std::runtime_error("could not load shader/starfield.vs");
}
starfield_program_.attach_shader(vertex_shader);
auto geometry_shader = shader_manager.load("shader/starfield.gs", GL_GEOMETRY_SHADER);
if (!geometry_shader) {
throw std::runtime_error("could not load shader/starfield.gs");
}
starfield_program_.attach_shader(geometry_shader);
fragment_shader = shader_manager.load("shader/starfield.fs", GL_FRAGMENT_SHADER);
if (!fragment_shader) {
throw std::runtime_error("could not load shader/starfield.fs");
......@@ -315,10 +320,6 @@ namespace gdw {
}
generate_starfield();
glEnable(GL_PROGRAM_POINT_SIZE);
glEnable(GL_POINT_SPRITE);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
}
void rendering_system::update(float delta_time) {
......@@ -817,11 +818,11 @@ namespace gdw {
void rendering_system::generate_starfield() {
static std::vector<star_vertex> stars;
for (auto i = 0; i < 100000; ++i) {
for (auto i = 0; i < 10000; ++i) {
static const auto white = glm::vec3(1.f);
static const auto yellow = glm::vec3(1.f, 1.f, 0.8f);
auto alpha = glm::gaussRand(0.f, 1.f);
star_vertex v = {glm::sphericalRand(500.f), glm::gaussRand(10.f, 50.f), glm::lerp(white, yellow, alpha)};
star_vertex v = {glm::sphericalRand(500.f), glm::gaussRand(1.f, 2.f), glm::lerp(white, yellow, alpha)};
stars.emplace_back(v);
}
starfield_vbo_.bind();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment