made some texture visualization code
This commit is contained in:
parent
b9bd185968
commit
87d310b55c
@ -199,7 +199,7 @@ Renderer::Renderer(Window& win) : win(win) {
|
||||
};
|
||||
|
||||
/* BSP loader */
|
||||
bsp = std::make_unique<HLBSP::BSP>(phys_dev, dev, "assets/maps/hl1.bsp");
|
||||
bsp = std::make_unique<HLBSP::BSP>(phys_dev, dev, "assets/maps/dmc.bsp");
|
||||
bsp_shaders = {
|
||||
{ dev, "assets/shaders/bin/bsp.vert.spv", vk::ShaderStageFlagBits::eVertex },
|
||||
{ dev, "assets/shaders/bin/bsp.frag.spv", vk::ShaderStageFlagBits::eFragment },
|
||||
|
||||
@ -10,6 +10,13 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
/* changes handedness by swapping z and y */
|
||||
template<typename T>
|
||||
static inline void change_swizzle(T& v) {
|
||||
auto tmp = v.y;
|
||||
v.y = v.z;
|
||||
v.z = tmp;
|
||||
}
|
||||
|
||||
using namespace HLBSP;
|
||||
|
||||
@ -25,7 +32,8 @@ static inline void copy_data(void* file_data, std::vector<T>& dst, Lump& lump) {
|
||||
std::memcpy(dst.data(), ((u8*)file_data) + lump.offset, lump.len);
|
||||
}
|
||||
|
||||
glm::vec2 calc_tex_coords(const glm::vec3& v, const TexInfo& t) {
|
||||
static inline glm::vec2 calc_tex_coords(glm::vec3 v, const TexInfo& t) {
|
||||
change_swizzle(v);
|
||||
return glm::vec2(
|
||||
t.shift_s + glm::dot(v, t.shift_s_dir),
|
||||
t.shift_t + glm::dot(v, t.shift_t_dir)
|
||||
@ -140,14 +148,6 @@ bool BSP::determine_visibility(const Leaf& cam_leaf, const Leaf& leaf, const std
|
||||
return box_in_frustum(frustum, box_verts);
|
||||
}
|
||||
|
||||
/* changes handedness by swapping z and y */
|
||||
template<typename T>
|
||||
static inline void change_swizzle(T& v) {
|
||||
auto tmp = v.y;
|
||||
v.y = v.z;
|
||||
v.z = tmp;
|
||||
}
|
||||
|
||||
static std::vector<std::map<std::string, std::string>> load_entities(const std::string& in) {
|
||||
/* TODO */
|
||||
return {
|
||||
|
||||
BIN
assets/maps/dmc.bsp
Executable file
BIN
assets/maps/dmc.bsp
Executable file
Binary file not shown.
@ -19,6 +19,16 @@ layout (set = 0, binding = 0) uniform Matrices {
|
||||
|
||||
layout (set = 0, binding = 1) uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
FragColor = (color + vec4(1.0)) / 2.0;
|
||||
vec3 tex_map(vec2 coords) {
|
||||
return vec3(
|
||||
1-abs(cos(normalize(texCoord.xxy)))
|
||||
// 0.0,
|
||||
// sin(texCoord.y)
|
||||
// sin(texCoord.x/texCoord.y)
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
FragColor.xyz = tex_map(texCoord);
|
||||
FragColor.w = 1.0;
|
||||
}
|
||||
@ -30,6 +30,6 @@ void main() {
|
||||
|
||||
gl_Position = proj * view * vec4(aPos, 1.0);
|
||||
|
||||
color = vec4(aTexCoord, 0.0, 1.0);
|
||||
color = vec4(0.0);
|
||||
texCoord = aTexCoord;
|
||||
}
|
||||
20
util/geo.hpp
20
util/geo.hpp
@ -4,30 +4,12 @@
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <array>
|
||||
|
||||
static glm::vec4 extract_plane(const glm::mat4& mat, int col) {
|
||||
float sign;
|
||||
if (col < 0) {
|
||||
sign = -1.0;
|
||||
col = -col - 1;
|
||||
} else {
|
||||
sign = 1.0;
|
||||
col -= 1;
|
||||
}
|
||||
|
||||
return glm::column(mat, 3) + sign * glm::column(mat, col);
|
||||
}
|
||||
|
||||
/* extracts frustum from projection matrix */
|
||||
static std::array<glm::vec4, 6> frustum(const glm::mat4& mat) {
|
||||
/* Left, Right, Top, Bottom, Back, Front */
|
||||
std::array<glm::vec4, 6> ret; /* {
|
||||
extract_plane(mat, 1),
|
||||
extract_plane(mat, -1),
|
||||
extract_plane(mat, 2),
|
||||
extract_plane(mat, -2),
|
||||
extract_plane(mat, 3),
|
||||
extract_plane(mat, -3),
|
||||
};*/
|
||||
std::array<glm::vec4, 6> ret;
|
||||
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
for (size_t j = 0; j < 4; j++)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user