From: Terri00 Date: Fri, 21 Jun 2019 15:16:54 +0000 (+0100) Subject: Auto-gradient entities X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=3f00a0d13c793ba837e00526feed18fc6360783f;p=tar-legacy.git Auto-gradient entities --- diff --git a/MCDV/GradientMap.hpp b/MCDV/GradientMap.hpp index 1ca3c8a..2a36639 100644 --- a/MCDV/GradientMap.hpp +++ b/MCDV/GradientMap.hpp @@ -60,8 +60,8 @@ public: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); free(data); } @@ -70,4 +70,67 @@ public: glActiveTexture(GL_TEXTURE0 + slot); glBindTexture(GL_TEXTURE_2D, this->texture_id); }*/ +}; + +class WGradientTexture : public Texture{ +public: + WGradientTexture(std::vector& tarcol) { + std::map colorMap; + + for (auto && i : tarcol) { + colorMap.insert({ i->m_origin.y, kv::tryGetStringValue(i->m_keyvalues, "_light", "128 128 128 255") }); + } + + // Fill with blank color + if (colorMap.size() < 1) { + colorMap.insert({ 0.0f, Color255("128 128 128 255") }); + } + + // Copy first to last + if (colorMap.size() < 2) { + colorMap.insert({ 949.4342231f , colorMap.begin()->second }); + } + + std::map::iterator it_end = colorMap.end(); + it_end--; + + float dy = it_end->first - colorMap.begin()->first; + + std::map::iterator it = colorMap.begin(); + std::map::iterator it_next = colorMap.begin(); + it_next++; + + glGenTextures(1, &this->texture_id); + unsigned char* data = (unsigned char*)malloc(2048 * 4); + + for (int i = 0; i < 2048; i++) { + float pc = (float)i / (float)2048; + float absdist = colorMap.begin()->first + (pc * dy); + + if (absdist > it_next->first) { + if (it_next != colorMap.end()) { + it++; + it_next++; + } + } + + float subpc = remap(absdist, it->first, it_next->first, 0, 1); + + data[i * 4 + 0] = lerpT(it->second.r, it_next->second.r, subpc); + data[i * 4 + 1] = lerpT(it->second.g, it_next->second.g, subpc); + data[i * 4 + 2] = lerpT(it->second.b, it_next->second.b, subpc); + data[i * 4 + 3] = lerpT(it->second.a, it_next->second.a, subpc); + } + + glBindTexture(GL_TEXTURE_2D, this->texture_id); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2048, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + free(data); + } }; \ No newline at end of file diff --git a/MCDV/layer0.png b/MCDV/layer0.png index dcdcd65..0bb5b28 100644 Binary files a/MCDV/layer0.png and b/MCDV/layer0.png differ diff --git a/MCDV/main2.cpp b/MCDV/main2.cpp index c54ace4..231e4e5 100644 --- a/MCDV/main2.cpp +++ b/MCDV/main2.cpp @@ -78,7 +78,7 @@ uint32_t g_msaa_mul = 1; void render_to_png(int x, int y, const char* filepath); void save_to_dds(int x, int y, const char* filepath, IMG imgmode = IMG::MODE_DXT1); -//#define _DEBUG +#define _DEBUG int app(int argc, const char** argv) { #ifndef _DEBUG diff --git a/MCDV/sample_stuff/de_tavr_test.vmx b/MCDV/sample_stuff/de_tavr_test.vmx index 8e357a0..787a3cd 100644 --- a/MCDV/sample_stuff/de_tavr_test.vmx +++ b/MCDV/sample_stuff/de_tavr_test.vmx @@ -2,7 +2,7 @@ versioninfo { "editorversion" "400" "editorbuild" "8075" - "mapversion" "357" + "mapversion" "379" "formatversion" "100" "prefab" "0" } @@ -44,7 +44,7 @@ viewsettings world { "id" "1" - "mapversion" "357" + "mapversion" "379" "classname" "worldspawn" "detailmaterial" "detail/detailsprites" "detailvbsp" "detail.vbsp" @@ -2636,10 +2636,80 @@ world } } entity +{ + "id" "3061" + "classname" "tar_color" + "_light" "0 255 0 255" + "origin" "-393 -64 48" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity +{ + "id" "3159" + "classname" "tar_color" + "_light" "255 255 0 255" + "origin" "-393 -64 208" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity +{ + "id" "3165" + "classname" "tar_color" + "_light" "198 57 149 255" + "origin" "-393 -64 224" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity +{ + "id" "3004" + "classname" "tar_color" + "_light" "255 0 0 255" + "origin" "-393 -64 80" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity +{ + "id" "3026" + "classname" "tar_color" + "_light" "0 0 255 255" + "origin" "-393 -64 104.5" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity { "id" "2969" "classname" "tar_max" - "origin" "-368.448 -11.867 140.175" + "origin" "-368.448 16 128" editor { "color" "127 224 0" @@ -2652,7 +2722,7 @@ entity { "id" "2971" "classname" "tar_min" - "origin" "-344.583 -139.156 33" + "origin" "-344.583 640 -192" editor { "color" "127 224 0" @@ -2667,7 +2737,7 @@ entity "classname" "tar_config" "aoSize" "1000" "background" "grid.png" - "colorScheme" "7" + "colorScheme" "-2" "customCol0" "104 15 15" "customCol1" "64 166 38" "customCol2" "44 199 199" @@ -2687,7 +2757,7 @@ entity "zColCover2" "85 85 85 170" "zColObjective" "0 128 255 255" "zColOutline" "204 204 204 255" - "origin" "-240 592 33" + "origin" "-352 -144 33" editor { "color" "127 224 0" diff --git a/MCDV/tar_config.hpp b/MCDV/tar_config.hpp index 1adf93a..b7af349 100644 --- a/MCDV/tar_config.hpp +++ b/MCDV/tar_config.hpp @@ -84,13 +84,18 @@ public: // Load color scheme gradient // TODO: Entity based gradients std::string schemeNum = kv::tryGetStringValue(kvs, "colorScheme", "0"); - if (schemeNum == "-1" || schemeNum == "-2") { + if (schemeNum == "-1") { this->m_texture_gradient = new GradientTexture( kv::tryGetStringValue(kvs, "customCol0", "39 56 79 255"), kv::tryGetStringValue(kvs, "customCol1", "77 74 72 255"), kv::tryGetStringValue(kvs, "customCol2", "178 113 65 255") ); - } else { + } + else if (schemeNum == "-2") { + // Do thi thening + this->m_texture_gradient = new WGradientTexture(v->get_entities_by_classname("tar_color")); + } + else { this->m_texture_gradient = new Texture("textures/gradients/gradientmap_" + schemeNum + ".png", true); }