From: Terri00 Date: Wed, 27 Mar 2019 18:55:05 +0000 (+0000) Subject: 2.0.5: current code. config entity update, AA X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=063be7ca1ae514910c31435c7fa4705884fc6466;p=tar-legacy.git 2.0.5: current code. config entity update, AA --- diff --git a/AutoRadar_installer/FileSystemHelper.h b/AutoRadar_installer/FileSystemHelper.h index 4c15f7d..4e5fe4d 100644 --- a/AutoRadar_installer/FileSystemHelper.h +++ b/AutoRadar_installer/FileSystemHelper.h @@ -1,3 +1,4 @@ +#pragma once #include #include #include diff --git a/MCDV/Shader.hpp b/MCDV/Shader.hpp index 3d5ac10..f0b48ac 100644 --- a/MCDV/Shader.hpp +++ b/MCDV/Shader.hpp @@ -37,6 +37,8 @@ public: void setVec3(const std::string &name, glm::vec3 vector) const; void setVec3(const std::string &name, float v1, float v2, float v3) const; + void setVec4(const std::string &name, float v1, float v2, float v3, float v4) const; + void setVec4(const std::string &name, glm::vec4 vector) const; unsigned int getUniformLocation(const std::string &name) const; }; @@ -165,4 +167,16 @@ void Shader::setVec3(const std::string &name, glm::vec3 vector) const void Shader::setVec3(const std::string &name, float v1, float v2, float v3) const { glUniform3f(glGetUniformLocation(this->programID, name.c_str()), v1, v2, v3); +} + +void Shader::setVec4(const std::string &name, float v1, float v2, float v3, float v4) const +{ + glUniform4f(glGetUniformLocation(this->programID, name.c_str()), v1, v2, v3, v4); +} + +void Shader::setVec4(const std::string &name, glm::vec4 vector) const +{ + glUniform4fv(glGetUniformLocation(this->programID, name.c_str()), + 1, + glm::value_ptr(vector)); } \ No newline at end of file diff --git a/MCDV/dds.hpp b/MCDV/dds.hpp index 0ea1ee0..d0971a3 100644 --- a/MCDV/dds.hpp +++ b/MCDV/dds.hpp @@ -127,6 +127,51 @@ uint8_t* compressImageDXT1(uint8_t* buf_RGB, uint32_t w, uint32_t h, uint32_t* c return outBuffer; } +/* +imageData: Pointer to image data +compressedSize: Pointer to final data size +w: image width +h: image height +mode: compression mode to use +*/ +uint8_t* compressImageDXT5(uint8_t* buf_RGB, uint32_t w, uint32_t h, uint32_t* cSize) { + *cSize = ((w / 4) * (h / 4)) * BLOCK_SIZE_DXT5; + + //Create output buffer + uint8_t* outBuffer = (uint8_t*)malloc(*cSize); + + int blocks_x = w / 4; + int blocks_y = h / 4; + + std::cout << "Compressing DXT1 from RGB buffer\n"; + + //Fill + for (int y = 0; y < blocks_y; y++) { + for (int x = 0; x < blocks_x; x++) { + + int blockindex = x + (y * blocks_x); + int globalX = x * 4; + int globalY = y * 4; + + uint8_t* src = new uint8_t[64]; //Create source RGBA buffer + for (int _y = 0; _y < 4; _y++) { + for (int _x = 0; _x < 4; _x++) { + src[(_x + (_y * 4)) * 4 + 0] = buf_RGB[(globalX + _x + ((h - (globalY + _y)) * w)) * 3 + 0]; + src[(_x + (_y * 4)) * 4 + 1] = buf_RGB[(globalX + _x + ((h - (globalY + _y)) * w)) * 3 + 1]; + src[(_x + (_y * 4)) * 4 + 2] = buf_RGB[(globalX + _x + ((h - (globalY + _y)) * w)) * 3 + 2]; + src[(_x + (_y * 4)) * 4 + 3] = 0xFF; + } + } + + stb_compress_dxt_block((unsigned char*)outBuffer + (blockindex * BLOCK_SIZE_DXT5), src, 1, STB_DXT_HIGHQUAL); + + free(src); + } + } + + return outBuffer; +} + bool dds_write(uint8_t* imageData, const char* filename, uint32_t w, uint32_t h, IMG mode) { DDS_HEADER header = DDS_HEADER(); header.dwSize = DDS_HEADER_SIZE; @@ -147,13 +192,12 @@ bool dds_write(uint8_t* imageData, const char* filename, uint32_t w, uint32_t h, break; case IMG::MODE_DXT5: - header.dwPitchOrLinearSize = __max(1, ((w + 3) / 4)) * BLOCK_SIZE_DXT5; - + header.dwPitchOrLinearSize = SwapEndian(__max(1, ((w + 3) / 4)) * BLOCK_SIZE_DXT5); header.ddspf.dwFlags |= DDPF_FOURCC; header.ddspf.dwFlags |= DDPF_ALPHA; header.ddspf.dwFourCC = SwapEndian((uint32_t)'DXT5'); header.dwFlags |= DDSD_LINEARSIZE; - throw new std::exception("DXT5 Not implemented"); + break; case IMG::MODE_RGB888: header.dwPitchOrLinearSize = w * (BBP_RGB888 / 8); @@ -201,6 +245,11 @@ bool dds_write(uint8_t* imageData, const char* filename, uint32_t w, uint32_t h, uint8_t* outputBuffer = compressImageDXT1(imageData, w, h, &size); output.write((char*)outputBuffer, size); } + else if (mode == IMG::MODE_DXT5) { + uint32_t size; + uint8_t* outputBuffer = compressImageDXT5(imageData, w, h, &size); + output.write((char*)outputBuffer, size); + } else { output.write((char*)imageData, final_image_size); diff --git a/MCDV/interpolation.h b/MCDV/interpolation.h index a0a0bd6..3601366 100644 --- a/MCDV/interpolation.h +++ b/MCDV/interpolation.h @@ -2,6 +2,7 @@ #include #include #include +#include //Linear interpolation between two floats, given time static float lerpf(float a, float b, float f) { @@ -29,3 +30,16 @@ inline float remap(float value, float low1, float high1, float low2, float high2 { return low2 + (value - low1) * (high2 - low2) / (high1 - low1); } + +glm::vec4 parseVec4(std::string src) { + glm::vec4 out = glm::vec4(0, 0, 0, 1); + std::vector strings; + strings = split(src); + + if (strings.size() >= 1) out.r = (float)::atoi(strings[0].c_str()) / 255.0f; + if (strings.size() >= 2) out.g = (float)::atoi(strings[1].c_str()) / 255.0f; + if (strings.size() >= 3) out.b = (float)::atoi(strings[2].c_str()) / 255.0f; + if (strings.size() >= 4) out.a = (float)::atoi(strings[3].c_str()) / 255.0f; + + return out; +} \ No newline at end of file diff --git a/MCDV/main.cpp b/MCDV/main.cpp index 07ef936..1a747be 100644 --- a/MCDV/main.cpp +++ b/MCDV/main.cpp @@ -29,6 +29,9 @@ #include "dds.hpp" #include "GradientMap.hpp" +// Experimental +//#define TAR_EXPERIMENTAL + /* Grabs the currently bound framebuffer and saves it to a .png */ void render_to_png(int x, int y, const char* filepath){ void* data = malloc(4 * x * y); @@ -42,12 +45,12 @@ void render_to_png(int x, int y, const char* filepath){ } /* Grabs the currently bound framebuffer and saves it to a .dds */ -void save_to_dds(int x, int y, const char* filepath) { +void save_to_dds(int x, int y, const char* filepath, IMG imgmode = IMG::MODE_DXT1) { void* data = malloc(4 * x * y); glReadPixels(0, 0, x, y, GL_RGB, GL_UNSIGNED_BYTE, data); - dds_write((uint8_t*)data, filepath, x, y, IMG::MODE_DXT1); + dds_write((uint8_t*)data, filepath, x, y, imgmode); free(data); } @@ -315,8 +318,10 @@ int app(int argc, const char** argv) { std::cout << "Loading map file...\n"; vmf::vmf vmf_main(m_mapfile_path + ".vmf"); + //vmf_main.setup_main(); + //vmf_main.genVMFReferences(); // Load all our func_instances - std::cout << "Generating Meshes...\n"; + //std::cout << "Generating Meshes...\n"; vmf_main.ComputeGLMeshes(); vmf_main.ComputeDisplacements(); @@ -464,6 +469,36 @@ int app(int argc, const char** argv) { } } +#ifdef TAR_EXPERIMENTAL + // Render instances (experimental) + for (auto && sub_vmf : vmf_main.findEntitiesByClassName("func_instance")) { + std::string mapname = kv::tryGetStringValue(sub_vmf->keyValues, "file", ""); + + if (mapname == "") continue; //Something went wrong... + + model = glm::mat4(); + + // do transforms + model = glm::translate(model, glm::vec3(-sub_vmf->origin.x, sub_vmf->origin.z, sub_vmf->origin.y)); + + // upload + shader_depth.setMatrix("model", model); + + for (auto && solid : vmf_main.subvmf_references[mapname]->getAllBrushesInVisGroup("tar_cover")) { + shader_depth.setFloat("write_cover", solid->temp_mark ? 1.0f : 1.0f); + if (!solid->containsDisplacements) + solid->mesh->Draw(); + else { + for (auto && f : solid->faces) { + if (f.displacement != NULL) { + f.displacement->glMesh->Draw(); + } + } + } + } + } +#endif // TAR_EXPERIMENTAL + // Render props std::cout << "Rendering props\n"; shader_depth.setFloat("write_cover", 1.0f); @@ -660,6 +695,13 @@ int app(int argc, const char** argv) { shader_comp_main.setInt("cmdl_outline_enable", tar_cfg_enableOutline); shader_comp_main.setInt("cmdl_outline_size", tar_cfg_outlineSize); + shader_comp_main.setVec4("outline_color", parseVec4(kv::tryGetStringValue(tar_config->keyValues, "zColOutline", "255 255 255 255"))); + shader_comp_main.setVec4("ao_color", parseVec4(kv::tryGetStringValue(tar_config->keyValues, "zColAO", "255 255 255 255"))); + + shader_comp_main.setVec4("buyzone_color", parseVec4(kv::tryGetStringValue(tar_config->keyValues, "zColBuyzone", "255 255 255 255"))); + shader_comp_main.setVec4("objective_color", parseVec4(kv::tryGetStringValue(tar_config->keyValues, "zColObjective", "255 255 255 255"))); + shader_comp_main.setVec4("cover_color", parseVec4(kv::tryGetStringValue(tar_config->keyValues, "zColCover", "255 255 255 255"))); + /* Bind texture samplers */ tex_background.bindOnSlot(0); shader_comp_main.setInt("tex_background", 0); @@ -683,7 +725,7 @@ int app(int argc, const char** argv) { #pragma region auto_export_game - if (!m_onlyOutputMasks) save_to_dds(m_renderWidth, m_renderHeight, filesys->create_output_filepath("resource/overviews/" + m_mapfile_name + "_radar.dds", true).c_str()); + if (!m_onlyOutputMasks) save_to_dds(m_renderWidth, m_renderHeight, filesys->create_output_filepath("resource/overviews/" + m_mapfile_name + "_radar.dds", true).c_str(), IMG::MODE_DXT1); if (m_outputMasks) render_to_png(m_renderWidth, m_renderHeight, filesys->create_output_filepath("resource/overviews/" + m_mapfile_name + ".resources/raw.png", true).c_str()); #pragma region generate_radar_txt diff --git a/MCDV/sample_stuff/de_tavr_test.vmx b/MCDV/sample_stuff/de_tavr_test.vmx index 8157769..d12829c 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" "155" + "mapversion" "175" "formatversion" "100" "prefab" "0" } @@ -56,7 +56,7 @@ viewsettings world { "id" "1" - "mapversion" "155" + "mapversion" "175" "classname" "worldspawn" "detailmaterial" "detail/detailsprites" "detailvbsp" "detail.vbsp" @@ -2778,6 +2778,95 @@ world } } entity +{ + "id" "1369" + "classname" "tar_config" + "aoSize" "8" + "colorScheme" "-1" + "customCol0" "39 56 79" + "customCol1" "77 74 72" + "customCol2" "178 113 65" + "enableAO" "1" + "enableOutline" "1" + "outlineWidth" "2" + "vgroup_cover" "tar_cover" + "vgroup_layout" "tar_layout" + "vgroup_negative" "tar_mask" + "zColAO" "0 0 0 255" + "zColBuyzone" "46 211 57 170" + "zColCover" "179 179 179 255" + "zColObjective" "196 75 44 255" + "zColOutline" "204 204 204 153" + "origin" "-386.122 479.551 33" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity +{ + "id" "1220" + "classname" "func_instance" + "angles" "-0 0 0" + "file" "instancetest.vmf" + "origin" "1024 320 0" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity +{ + "id" "1291" + "classname" "func_instance" + "angles" "-0 0 0" + "file" "instancetest.vmf" + "origin" "1088 2048 128" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity +{ + "id" "1300" + "classname" "func_instance" + "angles" "-0 -60 0" + "file" "instancetest.vmf" + "origin" "1920 2112 128" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity +{ + "id" "1309" + "classname" "func_instance" + "angles" "-0 -135 0" + "file" "instancetest.vmf" + "origin" "-1472 64 128" + editor + { + "color" "220 30 220" + "visgroupshown" "1" + "visgroupautoshown" "1" + "logicalpos" "[0 0]" + } +} +entity { "id" "1185" "classname" "prop_static" @@ -2922,31 +3011,6 @@ entity } } entity -{ - "id" "484" - "classname" "tar_config" - "aoSize" "10" - "colorScheme" "-1" - "customCol0" "62 39 129" - "customCol1" "94 162 202" - "customCol2" "207 136 213" - "enableAO" "1" - "enableOutline" "1" - "enableShadows" "1" - "outlineWidth" "2" - "vgroup_cover" "tar_cover" - "vgroup_layout" "tar_layout" - "vgroup_negative" "tar_mask" - "origin" "-320 576 32" - editor - { - "color" "220 30 220" - "visgroupshown" "1" - "visgroupautoshown" "1" - "logicalpos" "[0 0]" - } -} -entity { "id" "397" "classname" "func_detail" diff --git a/MCDV/shaders/depth.fs b/MCDV/shaders/depth.fs index 6bf36d5..6bc0196 100644 --- a/MCDV/shaders/depth.fs +++ b/MCDV/shaders/depth.fs @@ -19,7 +19,7 @@ float remap(float value, float low1, float high1, float low2, float high2) void main() { - float height = pow(remap(FragPos.y, HEIGHT_MIN, HEIGHT_MAX, 0, 1), 2.2); + float height = remap(FragPos.y, HEIGHT_MIN, HEIGHT_MAX, 0, 1);// pow(, 2.2); FragColor = vec4(write_playable, height, write_cover, 1); } \ No newline at end of file diff --git a/MCDV/shaders/ss_comp_main.fs b/MCDV/shaders/ss_comp_main.fs index 66a8959..97b47a1 100644 --- a/MCDV/shaders/ss_comp_main.fs +++ b/MCDV/shaders/ss_comp_main.fs @@ -27,6 +27,13 @@ uniform int cmdl_ao_size; uniform int cmdl_outline_enable; uniform int cmdl_outline_size; +uniform vec4 outline_color;// = vec4(0.8, 0.8, 0.8, 0.6); +uniform vec4 ao_color;// = vec4(0.0, 0.0, 0.0, 1.0); + +uniform vec4 buyzone_color;// = vec4(0.180, 0.828, 0.225, 0.667); +uniform vec4 objective_color;// = vec4(0.770, 0.295, 0.171, 1.000); +uniform vec4 cover_color;// = vec4(0.700, 0.700, 0.700, 1.000); + // SAMPLER UNIFORMS // Image Inputs _______________________________________________________________________________ // ( Standard generated maps from the engine ) @@ -214,12 +221,6 @@ float kernel_ao_basic(sampler2D sampler, int channelID, int sample_size) // SHADER PROGRAM // ____________________________________________________________________________________________ // ( Write all your shader code & functions here ) -vec4 outline_color = vec4(0.8, 0.8, 0.8, 0.6); -vec4 ao_color = vec4(0.0, 0.0, 0.0, 1.0); - -vec4 buyzone_color = vec4(0.180, 0.828, 0.225, 0.667); -vec4 objective_color = vec4(0.770, 0.295, 0.171, 1.000); -vec4 cover_color = vec4(0.700, 0.700, 0.700, 1.000); void main() { @@ -228,12 +229,12 @@ void main() vec4 sObjectives = vec4(texture(tex_objectives, TexCoords)); vec4 final = sBackground; - final = blend_normal(final, ao_color, kernel_filter_glow(tex_playspace, 3, 16, 0)); // Drop shadow + final = blend_normal(final, vec4(0,0,0,1), kernel_filter_glow(tex_playspace, 3, 16, 0)); // Drop shadow final = blend_normal(final, sample_gradient(get_playspace_height(sPlayspace)), get_playspace(sPlayspace)); // Playspace final = blend_normal(final, cover_color, sPlayspace.b); // Cover if(cmdl_shadows_enable == 1) final = blend_normal(final, vec4(0,0,0,1), trace_shadow(tex_playspace, 0) * 0.2); // Shadows - if(cmdl_ao_enable == 1) final = blend_normal(final, vec4(0,0,0,1), kernel_ao_basic(tex_playspace, 0, cmdl_ao_size) * 0.9); // AO + if(cmdl_ao_enable == 1) final = blend_normal(final, ao_color, kernel_ao_basic(tex_playspace, 0, cmdl_ao_size) * 0.9 * sPlayspace.a); // AO if(cmdl_outline_enable == 1) final = blend_normal(final, outline_color, kernel_filter_outline(tex_playspace, 3, cmdl_outline_size)); // Outline diff --git a/MCDV/vmf.hpp b/MCDV/vmf.hpp index de992d5..6f5c943 100644 --- a/MCDV/vmf.hpp +++ b/MCDV/vmf.hpp @@ -29,6 +29,8 @@ #include +#include "../AutoRadar_installer/FileSystemHelper.h" + namespace vmf_parse { //Pass Vector3 bool Vector3f(std::string str, glm::vec3* vec) @@ -169,6 +171,7 @@ namespace vmf { int ID; std::string classname; glm::vec3 origin; + glm::vec3* angles; std::map keyValues; std::vector internal_solids; @@ -199,8 +202,14 @@ namespace vmf { std::vector props; - vmf(std::string path) - { + // String to vmf* conversion of referenced vmf files. + std::map subvmf_references; + + std::string filepath; + + vmf(std::string path){ + this->filepath = path; + std::cout << "Opening: " << path << "\n"; std::ifstream ifs(path); @@ -549,7 +558,6 @@ namespace vmf { } glm::vec3* calculateSpawnLocation(team _team) { - std::vector spawns = this->findEntitiesByClassName(_team == team::terrorist ? "info_player_terrorist" : "info_player_counterterrorist"); if (spawns.size() <= 0) return NULL; @@ -651,6 +659,22 @@ namespace vmf { } } + /* Calls all other setup functions in order... */ + void setup_main() { + this->genVMFReferences(); // Load all our func_instances + this->ComputeGLMeshes(); + this->ComputeDisplacements(); + + // Recurse and setup all subvmfs + for (auto && subVMF : this->subvmf_references) { + subVMF.second->setup_main(); + } + } + + void draw_main(std::string vgroupFilter, bool recurse = false) { + + } + void populatePropList(std::string visgroupfilter = "") { for (auto && prop : this->findEntitiesByClassName("prop_static")) { if (!this->testIfInVisgroup(prop, visgroupfilter)) continue; @@ -885,6 +909,29 @@ namespace vmf { std::cout << "Displacement computation: " << milliseconds << "ms" << std::endl; } + /* Load all vmf instances. */ + void genVMFReferences() { + std::string thisfolder = fs::getDirName(this->filepath); + + for (auto && ent : this->findEntitiesByClassName("func_instance")) { + std::string mapname = kv::tryGetStringValue(ent->keyValues, "file", ""); + + if (mapname == "") continue; //Something went wrong... + if (this->subvmf_references.count(mapname)) continue; //Already referenced + + std::string mappath = thisfolder + mapname; + + if (fs::checkFileExist(mappath.c_str())) { + std::cout << "Loading referenced vmf: " << mapname << "\n"; + vmf* ref = new vmf(mappath); + this->subvmf_references.insert({ mapname, ref }); // add to list + } + else { + std::cout << "Failed to load referenced vmf: " << mapname << "\n"; + } + } + } + void clean() { for (int i = 0; i < this->solids.size(); i++) { delete this->solids[i].mesh; diff --git a/tar_entities/tar_entities.fgd b/tar_entities/tar_entities.fgd index 95d1168..1de5366 100644 --- a/tar_entities/tar_entities.fgd +++ b/tar_entities/tar_entities.fgd @@ -20,6 +20,8 @@ customCol1(color255) : "Custom middle level color" : "77 74 72" : "What the color of the radar should be in the middle of the map" customCol2(color255) : "Custom high level color" : "178 113 65" : "What the color of the radar should be at the heighest points of the map" + vgs_seperate(string) : " " : "" : "(spacer)" + // Ambient occlusion enableAO(choices) : "Ambient Occlusion" : 1 = @@ -48,10 +50,24 @@ outlineWidth(float) : "Outline width" : "2" : "How big should the outline be" + vgs_seperate2(string) : " " : "" : "(spacer)" + + // Cover color + zColCover(color255) : "Cover Color" : "179 179 179 255" : "Color of the cover" + zColOutline(color255) : "Outline Color" : "204 204 204 153" : "Color of the outline" + zColAO(color255) : "AO Color" : "0 0 0 255" : "Color of the ambient occlusion" + + zColBuyzone(color255) : "Buyzone Color" : "46 211 57 170" : "Color of the buyzones" + zColObjective(color255) : "Bombsite Color" : "196 75 44 255" : "What the color should cover be?" + + vgs_seperate3(string) : " " : "" : "(spacer)" + // Visgroup specifiers vgroup_layout(string) : "Visgroup: Layout" : "tar_layout" : "Name of the visgroup that specifies the layout of the map" vgroup_negative(string) : "Visgroup: Mask" : "tar_mask" : "Name of the visgroup that specifies subtractive brushes of the maps layout (use on walls)" vgroup_cover(string) : "Visgroup: Cover" : "tar_cover" : "Name of the visgroup that specifies the cover of the map. Chuck all yr crates in here" + + ] @PointClass iconsprite("tar/editor/tar_min.vmt") = tar_min :