+#pragma once
#include <Windows.h>
#include <vector>
#include <string>
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;
};
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
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;
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);
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);
#include <glm\glm.hpp>
#include <glm\gtc\matrix_transform.hpp>
#include <glm\gtc\type_ptr.hpp>
+#include <string>
//Linear interpolation between two floats, given time
static float lerpf(float a, float b, float f) {
{
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<std::string> 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
#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);
}
/* 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);
}
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();
}
}
+#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);
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);
#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
{
"editorversion" "400"
"editorbuild" "8075"
- "mapversion" "155"
+ "mapversion" "175"
"formatversion" "100"
"prefab" "0"
}
world
{
"id" "1"
- "mapversion" "155"
+ "mapversion" "175"
"classname" "worldspawn"
"detailmaterial" "detail/detailsprites"
"detailvbsp" "detail.vbsp"
}
}
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"
}
}
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"
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
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 )
// 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()
{
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
#include <io.h>
+#include "../AutoRadar_installer/FileSystemHelper.h"
+
namespace vmf_parse {
//Pass Vector3
bool Vector3f(std::string str, glm::vec3* vec)
int ID;
std::string classname;
glm::vec3 origin;
+ glm::vec3* angles;
std::map<std::string, std::string> keyValues;
std::vector<Solid> internal_solids;
std::vector<DrawableProp> props;
- vmf(std::string path)
- {
+ // String to vmf* conversion of referenced vmf files.
+ std::map<std::string, vmf*> subvmf_references;
+
+ std::string filepath;
+
+ vmf(std::string path){
+ this->filepath = path;
+
std::cout << "Opening: " << path << "\n";
std::ifstream ifs(path);
}
glm::vec3* calculateSpawnLocation(team _team) {
-
std::vector<Entity*> spawns = this->findEntitiesByClassName(_team == team::terrorist ? "info_player_terrorist" : "info_player_counterterrorist");
if (spawns.size() <= 0) return NULL;
}
}
+ /* 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;
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;
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 =
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 :