grass rotation modes
This commit is contained in:
parent
ea42bc485d
commit
6a3b74e680
4 changed files with 16 additions and 4 deletions
|
@ -32,6 +32,7 @@ compute_shader [[
|
|||
uint u_vertex_count;
|
||||
uint u_type;
|
||||
float u_radius;
|
||||
uint u_rotation_mode;
|
||||
};
|
||||
|
||||
float hash(float n) { return fract(sin(n) * 1e4); }
|
||||
|
@ -92,7 +93,16 @@ compute_shader [[
|
|||
if (scale > 0.01) {
|
||||
uint i = atomicAdd(b_indirect.instance_count, 1);
|
||||
b_data[i * 2 + 1] = vec4(inst_pos, scale);
|
||||
b_data[i * 2] = vec4(0, sin(r*16), 0, cos(r*16));
|
||||
switch(u_rotation_mode) {
|
||||
case 1:
|
||||
vec3 axis = normalize(vec3(fract(r * 2531), fract(r * 2819), fract(r * 13)) * 2 - 1);
|
||||
b_data[i * 2] = vec4(axis, cos(r*16));
|
||||
break;
|
||||
default:
|
||||
case 0:
|
||||
b_data[i * 2] = vec4(0, sin(r*16), 0, cos(r*16));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2989,6 +2989,7 @@ struct PipelineImpl final : Pipeline
|
|||
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->getBoundingRadius();
|
||||
grass.rotation_mode = (u32)type.m_rotation_mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3029,6 +3030,7 @@ struct PipelineImpl final : Pipeline
|
|||
u32 indices_count;
|
||||
u32 type;
|
||||
float radius;
|
||||
u32 rotation_mode;
|
||||
} dc;
|
||||
dc.pos = Vec4(grass.mtx.getTranslation(), 1);
|
||||
dc.from = grass.from;
|
||||
|
@ -3041,6 +3043,7 @@ struct PipelineImpl final : Pipeline
|
|||
dc.indices_count = grass.mesh->indices_count;
|
||||
dc.type = grass.type;
|
||||
dc.radius = grass.radius;
|
||||
dc.rotation_mode = grass.rotation_mode;
|
||||
gpu::update(m_pipeline->m_drawcall_ub, &dc, sizeof(dc));
|
||||
|
||||
Indirect indirect_dc;
|
||||
|
@ -3100,6 +3103,7 @@ struct PipelineImpl final : Pipeline
|
|||
IVec2 to;
|
||||
u32 type;
|
||||
float radius;
|
||||
u32 rotation_mode;
|
||||
};
|
||||
|
||||
IAllocator& m_allocator;
|
||||
|
|
|
@ -352,12 +352,11 @@ static void registerProperties(IAllocator& allocator)
|
|||
using namespace Reflection;
|
||||
|
||||
struct RotationModeEnum : Reflection::EnumAttribute {
|
||||
u32 count(ComponentUID cmp) const override { return 3; }
|
||||
u32 count(ComponentUID cmp) const override { return 2; }
|
||||
const char* name(ComponentUID cmp, u32 idx) const override {
|
||||
switch((Terrain::GrassType::RotationMode)idx) {
|
||||
case Terrain::GrassType::RotationMode::ALL_RANDOM: return "All random";
|
||||
case Terrain::GrassType::RotationMode::Y_UP: return "Y up";
|
||||
case Terrain::GrassType::RotationMode::ALIGN_WITH_NORMAL: return "Align with normal";
|
||||
default: ASSERT(false); return "N/A";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ struct Terrain
|
|||
{
|
||||
Y_UP,
|
||||
ALL_RANDOM,
|
||||
ALIGN_WITH_NORMAL,
|
||||
|
||||
COUNT,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue