Skip to content

Commit

Permalink
[Forest] Added 5000 pine trees
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Dec 21, 2023
1 parent 8262dee commit 5bee472
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
16 changes: 11 additions & 5 deletions data/shaders/g_buffer.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,19 @@ PixelInputType mainVS(Vertex_PosUvNorTan input, uint instance_id : SV_InstanceID

// normal
#if INSTANCED
output.normal_world = normalize(mul(input.normal, (float3x3)input.instance_transform)).xyz;
output.tangent_world = normalize(mul(input.tangent, (float3x3)input.instance_transform)).xyz;
float3 normal_transformed = mul(input.normal, (float3x3)buffer_pass.transform);
normal_transformed = mul(normal_transformed, (float3x3)input.instance_transform);
output.normal_world = normalize(normal_transformed);

float3 tangent_transformed = mul(input.tangent, (float3x3)buffer_pass.transform);
tangent_transformed = mul(tangent_transformed, (float3x3)input.instance_transform);
output.tangent_world = normalize(tangent_transformed);

#else
output.normal_world = normalize(mul(input.normal, (float3x3)buffer_pass.transform)).xyz;
output.tangent_world = normalize(mul(input.tangent, (float3x3)buffer_pass.transform)).xyz;
output.normal_world = normalize(mul(input.normal, (float3x3)buffer_pass.transform));
output.tangent_world = normalize(mul(input.tangent, (float3x3)buffer_pass.transform));
#endif

// uv
output.uv = input.uv;

Expand Down
42 changes: 42 additions & 0 deletions runtime/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,48 @@ namespace Spartan
}
}

// vegetation_tree_2
if (shared_ptr<Mesh> tree = ResourceCache::Load<Mesh>("project\\terrain\\vegetation_tree_2\\tree.fbx"))
{
shared_ptr<Entity> entity = tree->GetRootEntity().lock();
entity->SetObjectName("tree_2");
entity->SetScale(Vector3(0.3f, 0.3f, 0.3f));
entity->SetParent(m_default_terrain);

vector<Matrix> instances;

if (Entity* bark = entity->GetDescendantByName("Trunk"))
{
bark->SetScaleLocal(Vector3::One);

Renderable* renderable = bark->GetComponent<Renderable>().get();
renderable->GetMaterial()->SetTexture(MaterialTexture::Color, "project\\terrain\\vegetation_tree_2\\trunk_color.png");
renderable->GetMaterial()->SetTexture(MaterialTexture::Color, "project\\terrain\\vegetation_tree_2\\trunk_normal.png");

// generate instances
terrain->GenerateTransforms(&instances, 5000, TerrainProp::Tree);
renderable->SetInstances(instances);
}

if (Entity* branches = entity->GetDescendantByName("Branches"))
{
branches->SetScaleLocal(Vector3::One);

Renderable* renderable = branches->GetComponent<Renderable>().get();
renderable->SetInstances(instances);

// tweak material
Material* material = renderable->GetMaterial();
material->SetTexture(MaterialTexture::Color, "project\\terrain\\vegetation_tree_2\\branches_color.png");
material->SetTexture(MaterialTexture::Normal, "project\\terrain\\vegetation_tree_2\\branches_normal.png");
material->SetTexture(MaterialTexture::Roughness, "project\\terrain\\vegetation_tree_2\\branches_roughness.png");
material->SetTexture(MaterialTexture::Occlusion, "project\\terrain\\vegetation_tree_2\\branches_ao.png");
material->SetProperty(MaterialProperty::VertexAnimateWind, 1.0f);
material->SetProperty(MaterialProperty::SubsurfaceScattering, 1.0f);
material->SetProperty(MaterialProperty::WorldSpaceHeight, renderable->GetBoundingBox(BoundingBoxType::Transformed).GetSize().y);
}
}

// vegetation_plant_1
if (shared_ptr<Mesh> plant = ResourceCache::Load<Mesh>("project\\terrain\\vegetation_plant_1\\ormbunke.obj"))
{
Expand Down

0 comments on commit 5bee472

Please sign in to comment.