Skip to content

Commit

Permalink
Added texture mapping
Browse files Browse the repository at this point in the history
and the USSR flag :D
  • Loading branch information
MichaelMoroz committed Aug 30, 2019
1 parent 037826e commit c30a7eb
Show file tree
Hide file tree
Showing 12 changed files with 3,729 additions and 3 deletions.
796 changes: 796 additions & 0 deletions game_folder/shaders/compute/Final_step.glsl_error.txt

Large diffs are not rendered by default.

821 changes: 821 additions & 0 deletions game_folder/shaders/compute/Illumination_step.glsl_error.txt

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions game_folder/shaders/compute/MRRM1.glsl_error.txt

Large diffs are not rendered by default.

833 changes: 833 additions & 0 deletions game_folder/shaders/compute/MRRM3.glsl_error.txt

Large diffs are not rendered by default.

809 changes: 809 additions & 0 deletions game_folder/shaders/compute/Shading_step.glsl_error.txt

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions game_folder/shaders/compute/distance_estimators.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ uniform int FRACTAL_ITER;
uniform int MARBLE_MODE;
uniform float time;

layout(rgba8, binding = 3) uniform image2D color_flag;

///Original MM distance estimators

float s1 = sin(iFracAng1), c1 = cos(iFracAng1), s2 = sin(iFracAng2), c2 = cos(iFracAng2);
Expand Down Expand Up @@ -161,10 +163,15 @@ float de_flag(vec4 p)
vec4 col_flag(vec4 p)
{
vec3 f_pos = iFlagPos + vec3(1.5, 4, 0)*iFlagScale;
float d1 = de_box(p - vec4(f_pos, 0), vec3(1.5, 0.8, 0.08)*iMarbleRad);
vec4 d_pos = p - vec4(f_pos, 0);
vec3 fsize = vec3(1.5, 0.8, 0.08)*iMarbleRad;
float d1 = de_box(d_pos, fsize);
float d2 = de_capsule(p - vec4(iFlagPos + vec3(0, iFlagScale*2.4, 0), 0), iMarbleRad*2.4, iMarbleRad*0.18);
if (d1 < d2) {
return vec4(1.0, 0.2, 0.1, d1);
vec2 color_flag_s = vec2(imageSize(color_flag));
vec2 texture_coord = d_pos.xy*vec2(0.45,-0.4)/fsize.xy + vec2(0.45,0.5);
vec3 flagcolor = imageLoad(color_flag, ivec2(texture_coord*color_flag_s)).xyz;
return vec4(flagcolor, d1);
} else {
return vec4(0.9, 0.9, 0.1, d2);
}
Expand Down
Binary file added game_folder/shaders/textures/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions game_folder/shaders/textures/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add textures here, they can be used in compute shaders.
Only .png is supported
2 changes: 2 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ int main(int argc, char *argv[]) {
fullscreen = true;

Renderer rend(resolution->width, resolution->height, "shaders/compute/MAIN.cfg");
rend.LoadExternalTextures("shaders/textures/");

rend.camera.SetAspectRatio((float)window.getSize().x / (float)window.getSize().y);

sf::RenderTexture renderTexture;
Expand Down
16 changes: 16 additions & 0 deletions src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ std::string Renderer::GetConfigFolder()
return config_folder;
}

void Renderer::LoadExternalTextures(std::string texture_folder)
{
std::vector<fs::path> images = GetFilesInFolder(texture_folder, ".png");
for (auto &path : images)
{
sf::Texture textr;
textr.loadFromFile(path.string());
input_textures.push_back(textr);
}
}

void Renderer::Render()
{
int stages = global_size.size();
Expand Down Expand Up @@ -225,6 +236,11 @@ void Renderer::Render()
{
glBindImageTexture(tex_id++, main_textures[j], 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
}

for (auto &extr_text : input_textures)
{
glBindImageTexture(tex_id++, extr_text.getNativeHandle(), 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
}

shader_pipeline[i].setCamera(camera.GetGLdata());
shader_pipeline[i].Run(global_size[i]);
Expand Down
2 changes: 2 additions & 0 deletions src/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Renderer
void LoadShader(std::string shader_file);
std::vector<std::string> GetConfigurationsList();
std::string GetConfigFolder();
void LoadExternalTextures(std::string texture_folder);

void Render();
std::vector<ComputeShader> shader_pipeline;
Expand All @@ -48,4 +49,5 @@ class Renderer
std::vector<vec2> global_size;
std::vector<GLuint> main_textures;
std::vector<std::vector<GLuint>> shader_textures;
std::vector<sf::Texture> input_textures;
};
2 changes: 1 addition & 1 deletion src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct MainSettings
};

static const MainSettings default_settings = { sf::Vector2i(1280, 800),
sf::Vector2i(2560, 1440), 4, 2, 2, "English", true, true, true, 0.05, 2.7, 3, 2.2, 75, 1, 1, 0.005, false, 0.005, 0.7 };
sf::Vector2i(2560, 1440), 4, 2, 2, "English", true, true, true, 0.05, 2.7, 3, 2.2, 90, 1, 1, 0.005, false, 0.005, 0.7 };


class AllSettings
Expand Down

0 comments on commit c30a7eb

Please sign in to comment.