terrain improvements

This commit is contained in:
Mikulas Florek 2021-02-05 23:50:12 +01:00
parent 89ad9a88bb
commit 7b919e4e38
2 changed files with 10 additions and 2 deletions

View file

@ -33,6 +33,7 @@ compute_shader [[
uint u_type;
float u_radius;
uint u_rotation_mode;
vec2 u_terrain_xz_scale;
};
vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
@ -97,7 +98,8 @@ compute_shader [[
inst_pos.xz = (u_from + vec2(gl_GlobalInvocationID.xy)) * 0.25;
if (any(lessThan(inst_pos.xz, vec2(0)))) return;
uvec4 splat = uvec4(texture(u_splatmap, (inst_pos.xz + 0.5) / u_terrain_size) * 255.0 + 0.5);
vec2 uv = (inst_pos.xz / (u_terrain_size + u_terrain_xz_scale)) + 0.5 / (u_terrain_size.x / u_terrain_xz_scale + 1);
uvec4 splat = uvec4(texture(u_splatmap, uv) * 255.0 + 0.5);
uint mask = (splat.w << 8) | splat.z;
@ -107,7 +109,9 @@ compute_shader [[
inst_pos.x += (fract(r * 2531) * 2 - 1) * 0.5;
inst_pos.z += (fract(r * 2819) * 2 - 1) * 0.5;
inst_pos.y += texture(u_heightmap, (inst_pos.xz + 0.5) / u_terrain_size).x * u_terrain_y_scale;
vec2 uv = (inst_pos.xz / (u_terrain_size + u_terrain_xz_scale)) + 0.5 / (u_terrain_size.x / u_terrain_xz_scale + 1);
inst_pos.y += texture(u_heightmap, uv).x * u_terrain_y_scale;
inst_pos += u_pos.xyz;
float dist_t = saturate(length(inst_pos) / u_distance);

View file

@ -3734,6 +3734,7 @@ struct PipelineImpl final : Pipeline
grass.splatmap = terrain->m_splatmap ? terrain->m_splatmap->handle : gpu::INVALID_TEXTURE;
grass.terrain_size = terrain->getSize();
grass.terrain_y_scale = terrain->getYScale();
grass.terrain_xz_scale = Vec2(terrain->getXZScale());
grass.grass_height = type.m_grass_model->getAABB().max.y;
grass.type = u32(&type - terrain->m_grass_types.begin());
grass.radius = type.m_grass_model->getOriginBoundingRadius();
@ -3779,6 +3780,7 @@ struct PipelineImpl final : Pipeline
u32 type;
float radius;
u32 rotation_mode;
Vec2 terrain_xz_scale;
} dc;
dc.pos = Vec4(grass.mtx.getTranslation(), 1);
dc.from = grass.from;
@ -3792,6 +3794,7 @@ struct PipelineImpl final : Pipeline
dc.type = grass.type;
dc.radius = grass.radius;
dc.rotation_mode = grass.rotation_mode;
dc.terrain_xz_scale = grass.terrain_xz_scale;
gpu::update(m_pipeline->m_drawcall_ub, &dc, sizeof(dc));
Indirect indirect_dc;
@ -3851,6 +3854,7 @@ struct PipelineImpl final : Pipeline
gpu::ProgramHandle program;
Vec2 terrain_size;
float terrain_y_scale;
Vec2 terrain_xz_scale;
float grass_height;
IVec2 from;
IVec2 to;