Skip to content

Commit

Permalink
New visuals for Wormholes: (#2097)
Browse files Browse the repository at this point in the history
* new wormhole rendering for 3d viewports

* change wormhole radar represenation

* remove old wormhole images

---------

Co-authored-by: aBlueShadow <falter@mxdreamer>
  • Loading branch information
aBlueShadow and aBlueShadow authored May 12, 2024
1 parent 9bdaae8 commit 9441d79
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 46 deletions.
Binary file added resources/radar/wormHole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/wormHole1.png
Binary file not shown.
Binary file removed resources/wormHole2.png
Binary file not shown.
Binary file removed resources/wormHole3.png
Binary file not shown.
Binary file added resources/wormHole3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 16 additions & 39 deletions src/spaceObjects/wormHole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,61 +54,43 @@ WormHole::WormHole()
pathPlanner->addAvoidObject(this, (DEFAULT_COLLISION_RADIUS * AVOIDANCE_MULTIPLIER) );

setRadarSignatureInfo(0.9, 0.0, 0.0);

// Choose a texture to show on radar
radar_visual = irandom(1, 3);
registerMemberReplication(&radar_visual);

// Create some overlaying clouds
for(int n=0; n<cloud_count; n++)
{
clouds[n].size = random(1024, 1024 * 4);
clouds[n].texture = irandom(1, 3);
clouds[n].offset = glm::vec2(0, 0);
}
}

void WormHole::draw3DTransparent()
{
ShaderRegistry::ScopedShader shader(ShaderRegistry::Shaders::Billboard);

std::array<VertexAndTexCoords, 4> quad{
static std::array<VertexAndTexCoords, 4> quad{
glm::vec3{}, {0.f, 1.f},
glm::vec3{}, {1.f, 1.f},
glm::vec3{}, {1.f, 0.f},
glm::vec3{}, {0.f, 0.f}
};

textureManager.getTexture("wormHole3d.png")->bind();
ShaderRegistry::ScopedShader shader(ShaderRegistry::Shaders::Billboard);

auto model_matrix = getModelMatrix();
auto modeldata_matrix = glm::rotate(model_matrix, glm::radians(120.f), {1.f, 0.f, 0.f});

glUniformMatrix4fv(shader.get().uniform(ShaderRegistry::Uniforms::Model), 1, GL_FALSE, glm::value_ptr(modeldata_matrix));
glUniform4f(shader.get().uniform(ShaderRegistry::Uniforms::Color), 1.f, 1.f, 1.f, 5000.f);
gl::ScopedVertexAttribArray positions(shader.get().attribute(ShaderRegistry::Attributes::Position));
gl::ScopedVertexAttribArray texcoords(shader.get().attribute(ShaderRegistry::Attributes::Texcoords));

for(int n=0; n<cloud_count; n++)
{
NebulaCloud& cloud = clouds[n];

auto position = glm::vec3(getPosition().x, getPosition().y, 0) + glm::vec3(cloud.offset.x, cloud.offset.y, 0);
float size = cloud.size;

float distance = glm::length(camera_position - position);
float alpha = 1.0f - (distance / 10000.0f);
if (alpha < 0.0f)
continue;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

textureManager.getTexture("wormHole" + string(cloud.texture) + ".png")->bind();
glUniform4f(shader.get().uniform(ShaderRegistry::Uniforms::Color), alpha * 0.8f, alpha * 0.8f, alpha * 0.8f, 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)));

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<uint16_t> indices = { 0, 2, 1, 0, 3, 2 };
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, std::begin(indices));
}
std::initializer_list<uint16_t> indices = { 0, 2, 1, 0, 3, 2 };
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, std::begin(indices));
glBlendFunc(GL_ONE, GL_ONE);
}

void WormHole::drawOnRadar(sp::RenderTarget& renderer, glm::vec2 position, float scale, float rotation, bool long_range)
{
renderer.drawRotatedSpriteBlendAdd("wormHole" + string(radar_visual) + ".png", position, getRadius() * scale * 3.0f, getRotation() - rotation);
renderer.drawRotatedSpriteBlendAdd("radar/wormHole.png", position, getRadius() * scale * 3.0f, getRotation() - rotation);
}

// Draw a line toward the target position
Expand Down Expand Up @@ -179,8 +161,3 @@ void WormHole::onTeleportation(ScriptSimpleCallback callback)
{
this->on_teleportation = callback;
}

glm::mat4 WormHole::getModelMatrix() const
{
return glm::identity<glm::mat4>();
}
7 changes: 0 additions & 7 deletions src/spaceObjects/wormHole.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class WormHole : public SpaceObject, public Updatable
float update_delta = 0.0f;
P<PathPlannerManager> pathPlanner;

int radar_visual;
static const int cloud_count = 5;
NebulaCloud clouds[cloud_count];

ScriptSimpleCallback on_teleportation;

public:
Expand All @@ -33,9 +29,6 @@ class WormHole : public SpaceObject, public Updatable
void onTeleportation(ScriptSimpleCallback callback);

virtual string getExportLine() override { return "WormHole():setPosition(" + string(getPosition().x, 0) + ", " + string(getPosition().y, 0) + "):setTargetPosition(" + string(target_position.x, 0) + ", " + string(target_position.y, 0) + ")"; }

protected:
glm::mat4 getModelMatrix() const override;
};

#endif//WORM_HOLE_H

0 comments on commit 9441d79

Please sign in to comment.