Implement raytraced lightmap

This commit is contained in:
2019-01-09 23:32:10 +01:00
parent 3dde1e1083
commit 9787175b13
12 changed files with 240 additions and 28 deletions

View File

@@ -255,8 +255,8 @@ bool HeightmapPlane::create(float w, float h, const Image& img, float scale, flo
int div = new_size.x - 1; // TODO: handle height also
int idx_size = (div * div * 6) + (div * (div + 1) * 4);
int vertices_size = (div + 1)*(div + 1);
std::vector<GLuint> idx(idx_size);
std::vector<vertex_t> vertices(vertices_size);
idx.resize(idx_size);
vertices.resize(vertices_size);
std::vector<int> nor_count((size_t)vertices_size, 0);
count[0] = div * div * 6;
@@ -277,8 +277,8 @@ bool HeightmapPlane::create(float w, float h, const Image& img, float scale, flo
{
vertex_t v;
v.pos.x = ox + dx * (float)x;
v.pos.y = oy + dy * (float)y;
v.pos.z = (*px++).r / 255.f;
v.pos.y = (*px++).r / 255.f * height;
v.pos.z = oy + dy * (float)y;
v.pos.w = 1;
v.uvs2 = v.uvs = glm::vec2(x, y) / (float)div;
*pv++ = v;
@@ -286,7 +286,7 @@ bool HeightmapPlane::create(float w, float h, const Image& img, float scale, flo
}
// generate indices
const glm::vec3 yscale(1, 1, height);
const glm::vec3 yscale(1, height, 1);
for (int y = 0; y < div; y++)
{
int i = y * (div + 1);
@@ -363,8 +363,8 @@ bool HeightmapPlane::create(float w, float h, int div)
{
vertex_t v;
v.pos.x = ox + dx * (float)x;
v.pos.y = oy + dy * (float)y;
v.pos.z = 0.f;
v.pos.y = 0.f;
v.pos.z = oy + dy * (float)y;
v.pos.w = 1.f;
v.uvs2 = v.uvs = glm::vec2(x, y) / (float)div;
v.nor = { 0, 1, 0 };