This commit is contained in:
2026-03-02 17:21:14 +08:00
parent db0fd98e4f
commit c59c921997
4 changed files with 106 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
#include "camera.h" #include "camera.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <algorithm> #include <algorithm>
#include <cstddef>
#include <functional> #include <functional>
#include <glm/ext/matrix_clip_space.hpp> #include <glm/ext/matrix_clip_space.hpp>
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
@@ -249,7 +250,55 @@ private:
const int vertex_count = cols * rows; const int vertex_count = cols * rows;
std::vector<float> verts; std::vector<float> verts;
for (int i = 0; i < rows; ++i) {
const float v = (rows > 1) ? (float)(i) / (float)(rows - 1) : 0.0F; // normailze to 0-1
const float y = (v - 0.5F) * panelHeight_; // -0.5 - 0.5
for (int j = 0; j < cols; ++j) {
const float u = (cols > 1) ? (float)(j) / (float)(cols - 1) : 0.0F;
const float x = (u - 0.5F) * panelWidth_;
verts.push_back(x);
verts.push_back(y);
verts.push_back(0.0F);
verts.push_back(u);
verts.push_back(v);
}
}
std::vector<unsigned int> idx;
idx.reserve((cols - 1) * (rows - 1) * 6);
for (int r = 0; r < rows - 1; ++r) {
for (int c = 0; c < cols - 1; ++c) {
auto i0 = r * cols + c;
auto i1 = r * cols + c + 1;
auto i2 = (r + 1) * cols + c + 1;
auto i3 = (r + 1) * cols + c;
idx.push_back(i0);
idx.push_back(i1);
idx.push_back(i2);
idx.push_back(i0);
idx.push_back(i2);
idx.push_back(i3);
}
}
heatmapIndexCount = int(idx.size());
glGenVertexArrays(1, &heatmapVao_);
glBindVertexArray(heatmapVao_);
glGenBuffers(1, &heatmapVbo_);
glBindBuffer(GL_ARRAY_BUFFER, heatmapVbo_);
glBufferData(GL_ARRAY_BUFFER, verts.size() * sizeof(float), verts.data(), GL_STATIC_DRAW);
glGenBuffers(1, &heatmapIbo_);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, heatmapIbo_);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx.size() * sizeof(unsigned int), idx.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(0));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glBindVertexArray(0);
} }
bool initBgProgram() { bool initBgProgram() {
@@ -509,6 +558,7 @@ private:
unsigned int heatmapVao_ = 0; unsigned int heatmapVao_ = 0;
unsigned int heatmapVbo_ = 0; unsigned int heatmapVbo_ = 0;
unsigned int heatmapIbo_ = 0; unsigned int heatmapIbo_ = 0;
int heatmapIndexCount = 0;
ViewPort viewport_{800, 600}; ViewPort viewport_{800, 600};
Camera camera_{glm::vec3(0.0F, 0.0F, 2.0F)}; Camera camera_{glm::vec3(0.0F, 0.0F, 2.0F)};

View File

@@ -114,7 +114,7 @@ void main() {
float vC = texture(uHeightTex, vUV).r; float vC = texture(uHeightTex, vUV).r;
bool isZero = abs(vC) <= 1e-6; bool isZero = abs(vC) <= 1e-6;
float t = value01(vC); float t = value01(vC);
float m = maxNeighborValue(vUV); float m = maxNeighborValueK(vUV, 2);
float eps = max(1e-4, 0.001 * (uMaxV - uMinV)); float eps = max(1e-4, 0.001 * (uMaxV - uMinV));
float force = smoothstep(uMaxV - eps, uMaxV, m); float force = smoothstep(uMaxV - eps, uMaxV, m);
t = max(t, force); t = max(t, force);

37
shader/skirt.frag Normal file
View File

@@ -0,0 +1,37 @@
#version 330 core
in vec3 vNormal;
in vec3 vWorldPos;
in vec3 vUV;
out vec4 FragColor;
uniform vec3 uCameraPos;
uniform vec3 uLightDir;
uniform sampler2D uHeightTex;
uniform float uMinV;
uniform float uMaxV;
uniform vec2 uTexelSize;
uniform vec3 uColorZero;
uniform vec3 uColorLow;
uniform vec3 uColorMid;
uniform vec3 uColorHeigh;
float saturate(float x) {
return clamp(x, 0.0, 1.0);
}
float value01(float v) {
return saturate((v - uMinV) / max(uMaxV - uMinV, 1e-6));
}
vec3 colorRamp(float t) {
if (t < 0.5) {
return mix(uColorLow, uColorMid, t / 0.5);
}
return mix(uColorHeigh, uColorMid, (t - 0.5) / 0.5);
}
float maxNeighborValue(vec2 uv) {
}

18
shader/skirt.vert Normal file
View File

@@ -0,0 +1,18 @@
#version 330 core
layout(location=0) in vec3 aPos;
layout(location=1) in vec3 aNormal;
layout(location=2) in vec2 aUV;
out vec3 vNormal;
out vec3 vWorldPos;
out vec2 vUV;
uniform mat4 uMVP;
void main() {
vWorldPos = aPos;
vNormal = aNormal;
vUV = aUV;
gl_Position = uMVP * vec4(aPos, 1.0);
}