game: texturing improvements and new materials

This commit is contained in:
Crypto City 2020-01-29 13:13:56 +00:00
parent 49aa16bc51
commit 57526fd8f5
17 changed files with 106 additions and 29 deletions

View File

@ -0,0 +1,8 @@
<material>
<technique name="Techniques/Diff.xml" />
<texture unit="diffuse" name="Textures/cobblestone_floor_04_diff_1k.jpg" />
<texture unit="emissive" name="MaterialEffects/Textures/circWall/smWhite.jpg" />
<shader psdefines="PACKEDNORMAL" />
<parameter name="MatSpecColor" value="0.3 0.3 0.3 16" />
<parameter name="MatDiffColor" value="1 1 1 .3" />
</material>

View File

@ -0,0 +1,8 @@
<material>
<technique name="Techniques/Diff.xml" />
<texture unit="diffuse" name="Textures/cobblestone_square_diff_1k.jpg" />
<texture unit="emissive" name="MaterialEffects/Textures/circWall/smWhite.jpg" />
<shader psdefines="PACKEDNORMAL" />
<parameter name="MatSpecColor" value="0.3 0.3 0.3 16" />
<parameter name="MatDiffColor" value="1 1 1 .3" />
</material>

View File

@ -1,7 +1,7 @@
<material>
<!-- <technique name="Techniques/DiffNormal.xml" quality="1" /> -->
<technique name="Techniques/Diff.xml" quality="0" />
<texture unit="diffuse" name="Textures/stone.png" />
<texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
<texture unit="emissive" name="MaterialEffects/Textures/circWall/smWhite.jpg" />
<!-- <texture unit="normal" name="Textures/StoneNormal.dds" /> -->
<shader psdefines="PACKEDNORMAL" />

View File

@ -0,0 +1,8 @@
<material>
<technique name="Techniques/Diff.xml" />
<texture unit="diffuse" name="Textures/marble_01_diff_1k.jpg" />
<texture unit="emissive" name="MaterialEffects/Textures/circWall/smWhite.jpg" />
<shader psdefines="PACKEDNORMAL" />
<parameter name="MatSpecColor" value="0.3 0.3 0.3 16" />
<parameter name="MatDiffColor" value="1 1 1 .3" />
</material>

View File

@ -1,8 +1,6 @@
<material>
<!-- <technique name="Techniques/DiffNormal.xml" quality="1" /> -->
<technique name="Techniques/Diff.xml" quality="0" />
<texture unit="diffuse" name="Textures/wood2.png" />
<!-- <texture unit="normal" name="Textures/StoneNormal.dds" /> -->
<texture unit="diffuse" name="Textures/Wood_planks_011_basecolor-hue.jpg" />
<shader psdefines="PACKEDNORMAL" />
<parameter name="MatSpecColor" value="0.3 0.3 0.3 16" />
<parameter name="MatDiffColor" value="1 1 1 1" />

View File

@ -0,0 +1,7 @@
<material>
<technique name="Techniques/Diff.xml" quality="0" />
<texture unit="diffuse" name="Textures/pine.jpg" />
<shader psdefines="PACKEDNORMAL" />
<parameter name="MatSpecColor" value="0.3 0.3 0.3 16" />
<parameter name="MatDiffColor" value="1 1 1 1" />
</material>

View File

@ -0,0 +1,7 @@
<material>
<technique name="Techniques/Diff.xml" quality="0" />
<texture unit="diffuse" name="Textures/Wood_016_basecolor-hue.jpg" />
<shader psdefines="PACKEDNORMAL" />
<parameter name="MatSpecColor" value="0.3 0.3 0.3 16" />
<parameter name="MatDiffColor" value="1 1 1 1" />
</material>

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 632 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

BIN
GameData/Textures/pine.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

View File

@ -32,6 +32,19 @@ enum MaterialVersion
NumMV
};
enum MaterialType: uint8_t
{
MATERIAL_NONE = 0,
MATERIAL_COBBLESTONES_1,
MATERIAL_COBBLESTONES_2,
MATERIAL_SANDSTONE,
MATERIAL_GRANITE,
MATERIAL_MARBLE,
MATERIAL_PINE,
MATERIAL_OAK,
MATERIAL_TEAK,
};
static float vertex_data_template[24*8] = {
// Position Normal UV
// x y z x y z u v
@ -68,6 +81,28 @@ static float get_height_scale(const Vector3 &pos)
return 1.0f + pos.y_ / 10.f;
}
static uint8_t get_material_for_block(const std::shared_ptr<Flag> &flag, uint8_t block, uint16_t h)
{
switch (block)
{
case ITEM_SANDSTONE:
return (h == 0 && flag->role == ROLE_ROAD) ? MATERIAL_COBBLESTONES_1 : MATERIAL_SANDSTONE;
case ITEM_GRANITE:
return (h == 0 && flag->role == ROLE_ROAD) ? MATERIAL_COBBLESTONES_2 : MATERIAL_GRANITE;
case ITEM_MARBLE:
return MATERIAL_MARBLE;
case ITEM_PINE:
return MATERIAL_PINE;
case ITEM_OAK:
return MATERIAL_OAK;
case ITEM_TEAK:
return MATERIAL_TEAK;
default:
return MATERIAL_COBBLESTONES_1;
}
return block;
}
CityMeshResources::CityMeshResources(ResourceCache *cache)
{
ownershipMaterial = cache->GetResource<Material>("Materials/Ownership.xml");
@ -80,9 +115,14 @@ CityMeshResources::CityMeshResources(ResourceCache *cache)
cursorMaterial[CURSOR_NEW]->SetShaderParameter("MatDiffColor", Color(.3f, .8f, .8f));
materials[MVNormal][0] = invisibleMaterial->Clone();
materials[MVNormal][ITEM_SANDSTONE] = cache->GetResource<Material>("Materials/material1_Sandstone.xml")->Clone();
materials[MVNormal][ITEM_GRANITE] = cache->GetResource<Material>("Materials/material2_Granite.xml")->Clone();
materials[MVNormal][ITEM_PINE] = cache->GetResource<Material>("Materials/material4_Pine.xml")->Clone();
materials[MVNormal][MATERIAL_COBBLESTONES_1] = cache->GetResource<Material>("Materials/material_Cobblestones1.xml")->Clone();
materials[MVNormal][MATERIAL_COBBLESTONES_2] = cache->GetResource<Material>("Materials/material_Cobblestones2.xml")->Clone();
materials[MVNormal][MATERIAL_SANDSTONE] = cache->GetResource<Material>("Materials/material_Sandstone.xml")->Clone();
materials[MVNormal][MATERIAL_GRANITE] = cache->GetResource<Material>("Materials/material_Granite.xml")->Clone();
materials[MVNormal][MATERIAL_MARBLE] = cache->GetResource<Material>("Materials/material_Marble.xml")->Clone();
materials[MVNormal][MATERIAL_PINE] = cache->GetResource<Material>("Materials/material_Pine.xml")->Clone();
materials[MVNormal][MATERIAL_OAK] = cache->GetResource<Material>("Materials/material_Oak.xml")->Clone();
materials[MVNormal][MATERIAL_TEAK] = cache->GetResource<Material>("Materials/material_Teak.xml")->Clone();
Technique *technique = cache->GetResource<Technique>("MaterialEffects/Techniques/DiffEmissiveGlow.xml");
for (int i = 0; i < 256; ++i)
@ -335,7 +375,7 @@ void CityMeshSection::setHighlight(const Selection &selection, const std::shared
mv = MVNew;
flagsWithNew.insert(flag->id);
}
material = resources.materials[mv][type];
material = resources.materials[mv][get_material_for_block(flag, type, h)];
nodes[y - vy0][x - vx0].blocks[h].node->GetComponent<StaticModel>()->SetMaterial(material);
}
}
@ -648,6 +688,7 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
{
++n_total;
const uint8_t type = flag->get_tile_type(x, y, h);
const uint8_t material_type = get_material_for_block(flag, type, h);
bool hidden = type == 0;
bool bottom_hidden = false, top_hidden = false, left_hidden = false, right_hidden = false, front_hidden = false, back_hidden = false;
if (!hidden)
@ -666,13 +707,13 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
++n_hidden;
if (nodes[y - vy0][x - vx0].blocks[h].node)
nodes[y - vy0][x - vx0].blocks[h].node->Remove();
nodes[y - vy0][x - vx0].blocks[h] = {NULL, type, false};
nodes[y - vy0][x - vx0].blocks[h] = {NULL, material_type, false};
continue;
}
if (flagRenderMode == RenderCubeModels)
{
if (nodes[y - vy0][x - vx0].blocks[h].type == type && nodes[y - vy0][x - vx0].blocks[h].node)
if (nodes[y - vy0][x - vx0].blocks[h].material == material_type && nodes[y - vy0][x - vx0].blocks[h].node)
continue;
}
else
@ -693,8 +734,8 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
{
case RenderMergedCubes:
{
std::vector<float> &vdata = vertex_data[type][mv];
std::vector<uint32_t> &idata = index_data[type][mv];
std::vector<float> &vdata = vertex_data[material_type][mv];
std::vector<uint32_t> &idata = index_data[material_type][mv];
uint32_t idx_base = vdata.size() / 8;
const float dx = U2F1(,x);
const float dy = U2F1(,y);
@ -717,8 +758,8 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
}
case RenderOptimizedCubes:
{
std::vector<float> &vdata = vertex_data[type][mv];
std::vector<uint32_t> &idata = index_data[type][mv];
std::vector<float> &vdata = vertex_data[material_type][mv];
std::vector<uint32_t> &idata = index_data[material_type][mv];
uint32_t idx_base = vdata.size() / 8;
const float dx = U2F1(,x);
const float dy = U2F1(,y);
@ -734,18 +775,18 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
}
case RenderSingleQuads:
{
if (!groups[type])
if (!groups[material_type])
{
groups[type] = blockNode->CreateComponent<StaticModelGroup>();
groups[type]->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
groups[type]->SetMaterial(resources.materials[mv][type]);
groups[material_type] = blockNode->CreateComponent<StaticModelGroup>();
groups[material_type]->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
groups[material_type]->SetMaterial(resources.materials[mv][material_type]);
}
if (!front_hidden) add_quad_instance(groups[type], blockNode, Vector3(U2F1(,x), h + 0.5f, U2F1(,y) - .5f), resources.FrontRotation);
if (!back_hidden) add_quad_instance(groups[type], blockNode, Vector3(U2F1(,x), h + 0.5f, U2F1(,y) + .5f), resources.BackRotation);
if (!left_hidden) add_quad_instance(groups[type], blockNode, Vector3(U2F1(,x) - .5f, h + 0.5f, U2F1(,y)), resources.LeftRotation);
if (!right_hidden) add_quad_instance(groups[type], blockNode, Vector3(U2F1(,x) + .5f, h + 0.5f, U2F1(,y)), resources.RightRotation);
if (!top_hidden) add_quad_instance(groups[type], blockNode, Vector3(U2F1(,x), h + 1.0f, U2F1(,y)), resources.TopRotation);
if (!bottom_hidden) add_quad_instance(groups[type], blockNode, Vector3(U2F1(,x), h, U2F1(,y)), resources.BottomRotation);
if (!front_hidden) add_quad_instance(groups[material_type], blockNode, Vector3(U2F1(,x), h + 0.5f, U2F1(,y) - .5f), resources.FrontRotation);
if (!back_hidden) add_quad_instance(groups[material_type], blockNode, Vector3(U2F1(,x), h + 0.5f, U2F1(,y) + .5f), resources.BackRotation);
if (!left_hidden) add_quad_instance(groups[material_type], blockNode, Vector3(U2F1(,x) - .5f, h + 0.5f, U2F1(,y)), resources.LeftRotation);
if (!right_hidden) add_quad_instance(groups[material_type], blockNode, Vector3(U2F1(,x) + .5f, h + 0.5f, U2F1(,y)), resources.RightRotation);
if (!top_hidden) add_quad_instance(groups[material_type], blockNode, Vector3(U2F1(,x), h + 1.0f, U2F1(,y)), resources.TopRotation);
if (!bottom_hidden) add_quad_instance(groups[material_type], blockNode, Vector3(U2F1(,x), h, U2F1(,y)), resources.BottomRotation);
break;
}
case RenderCubeModels:
@ -764,7 +805,7 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
if (!right_hidden) add_face(vdata, idata, 3, dx, dy, h, idx_base, y, -h); idx_base -= 4;
if (!bottom_hidden) add_face(vdata, idata, 4, dx, dy, h, idx_base, -y, -x); idx_base -= 4;
if (!top_hidden) add_face(vdata, idata, 5, dx, dy, h, idx_base, y, x); idx_base -= 4;
blockObject = createModel(vdata, idata, true, blockNode, resources.materials[mv][type]);
blockObject = createModel(vdata, idata, true, blockNode, resources.materials[mv][material_type]);
nodes[y - vy0][x - vx0].blocks[h].node = std::move(blockNode);
break;
}
@ -773,8 +814,8 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
else
blockObject = nodes[y - vy0][x - vx0].blocks[h].node->GetComponent<StaticModel>();
if (blockObject)
blockObject->SetMaterial(resources.materials[mv][type]);
nodes[y - vy0][x - vx0].blocks[h].type = type;
blockObject->SetMaterial(resources.materials[mv][material_type]);
nodes[y - vy0][x - vx0].blocks[h].material = material_type;
nodes[y - vy0][x - vx0].blocks[h].is_new = is_new;
if (blockObject)
blockObject->SetCastShadows(true);
@ -876,7 +917,7 @@ void CityMeshSection::Update(float timeStep, bool mark_new_block)
{
if (block.node)
{
block.node->GetComponent<StaticModel>()->SetMaterial(resources.materials[mv][block.type]);
block.node->GetComponent<StaticModel>()->SetMaterial(resources.materials[mv][block.material]);
}
block.is_new = false;
}

View File

@ -100,7 +100,7 @@ private:
struct Block
{
Urho3D::SharedPtr<Urho3D::Node> node;
uint8_t type;
uint8_t material;
bool is_new;
};
std::vector<Block> blocks;