Skip to content

Commit

Permalink
Detail textures and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Derpius committed Aug 20, 2022
1 parent 20be5e1 commit 4d9937e
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 72 deletions.
11 changes: 3 additions & 8 deletions source/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Vector MakeVector(const float x, const float y, const float z)
return v;
}

std::string getMaterialString(ILuaBase* LUA, const std::string& key)
std::string GetMaterialString(ILuaBase* LUA, const std::string& key)
{
std::string val = "";
LUA->GetField(-1, "GetString");
Expand All @@ -85,12 +85,7 @@ std::string getMaterialString(ILuaBase* LUA, const std::string& key)
return val;
}

bool checkMaterialFlag(uint32_t flags, const MaterialFlags flag)
{
return (flags & static_cast<uint32_t>(flag)) == static_cast<uint32_t>(flag);
}

bool readTexture(const std::string& path, VTFTexture** ppTextureOut)
bool ReadTexture(const std::string& path, VTFTexture** ppTextureOut)
{
std::string texturePath = "materials/" + path + ".vtf";
if (!FileSystem::Exists(texturePath.c_str(), "GAME")) return false;
Expand All @@ -115,7 +110,7 @@ bool readTexture(const std::string& path, VTFTexture** ppTextureOut)
return true;
}

bool validVector(const glm::vec3& v)
bool ValidVector(const glm::vec3& v)
{
return (
!(v.x == 0.f && v.y == 0.f && v.z == 0.f) &&
Expand Down
16 changes: 4 additions & 12 deletions source/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Vector MakeVector(const float x, const float y, const float z);
/// <param name="LUA">ILuaBase pointer</param>
/// <param name="key">String key</param>
/// <returns>Value at the key or an empty string</returns>
std::string getMaterialString(GarrysMod::Lua::ILuaBase* LUA, const std::string& key);
std::string GetMaterialString(GarrysMod::Lua::ILuaBase* LUA, const std::string& key);

/// <summary>
/// VMT flags
Expand Down Expand Up @@ -83,28 +83,20 @@ inline MaterialFlags operator&(const MaterialFlags a, const MaterialFlags b)
return static_cast<MaterialFlags>(static_cast<const uint32_t>(a) & static_cast<const uint32_t>(b));
}

/// <summary>
/// Returns true if the flag is present in the flags uint
/// </summary>
/// <param name="flags">uint32_t of flags</param>
/// <param name="flag">Flag to check</param>
/// <returns>True if the flag is set</returns>
bool checkMaterialFlag(MaterialFlags flags, const MaterialFlags flag);

/// <summary>
/// Read a VTF texture at the given path
/// </summary>
/// <param name="path">Path to texture (without materials/ and .vtf)</param>
/// <param name="ppTextureOut">Pointer to pointer to texture for passing the newly read texture out</param>
/// <returns>Whether the read was successful or not</returns>
bool readTexture(const std::string& path, VTFTexture** ppTextureOut);
bool ReadTexture(const std::string& path, VTFTexture** ppTextureOut);

/// <summary>
/// Check if a vector is valid (not all zero or NaN)
/// </summary>
/// <param name="v">Vector to validate</param>
/// <returns>Whether the vector was valid</returns>
bool validVector(const glm::vec3& v);
bool ValidVector(const glm::vec3& v);

/// <summary>
/// Transforms a texture coordinate with a material transform matrix and scale
Expand All @@ -119,7 +111,7 @@ inline glm::vec2 TransformTexcoord(const glm::vec2& texcoord, const glm::mat2x4&
transformed.x = glm::dot(glm::vec4(texcoord, 1.f, 1.f), transform[0]);
transformed.y = glm::dot(glm::vec4(texcoord, 1.f, 1.f), transform[1]);

return transformed;
return transformed * scale;
}

// Ray Tracing Gems
Expand Down
Loading

0 comments on commit 4d9937e

Please sign in to comment.