Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#include "Headers/Terrain.h"
#include "Headers/TerrainLoader.h"
#include "Headers/TerrainDescriptor.h"

#include "Platform/Video/Headers/GFXDevice.h"
#include "Platform/Video/Headers/RenderStateBlock.h"

#include "Geometry/Material/Headers/Material.h"
#include "Managers/Headers/SceneManager.h"
#include "Geometry/Shapes/Headers/Predefined/Quad3D.h"

namespace Divide {

bool TerrainLoader::loadTerrain(std::shared_ptr<Terrain> terrain,
                                const TerrainDescriptor* terrainDescriptor) {
    const stringImpl& name = terrainDescriptor->getVariable("terrainName");

    Attorney::TerrainLoader::setUnderwaterDiffuseScale(
        *terrain, terrainDescriptor->getVariablef("underwaterDiffuseScale"));

    SamplerDescriptor blendMapSampler;
    blendMapSampler.setWrapMode(TextureWrap::CLAMP);
    blendMapSampler.setAnisotropy(0);
    blendMapSampler.toggleMipMaps(false);

    TerrainTextureLayer* textureLayer = nullptr;
    stringImpl layerOffsetStr;
    stringImpl currentTexture;
    stringImpl arrayLocation;
    U32 textureCount = 0;
    U32 textureCountAlbedo = 0;
    U32 textureCountDetail = 0;

    for (U32 i = 0; i < terrainDescriptor->getTextureLayerCount(); ++i) {
        textureCountAlbedo = 0;
        textureCountDetail = 0;

        layerOffsetStr = to_stringImpl(i);
        textureLayer = MemoryManager_NEW TerrainTextureLayer();

        ResourceDescriptor textureBlendMap("Terrain Blend Map_" + name +
                                           "_layer_" + layerOffsetStr);
        textureBlendMap.setResourceLocation(
            terrainDescriptor->getVariable("blendMap" + layerOffsetStr));
        textureBlendMap.setPropertyDescriptor(blendMapSampler);
        textureBlendMap.setEnumValue(to_const_uint(TextureType::TEXTURE_2D));
        textureLayer->setBlendMap(CreateResource<Texture>(terrain->parentResourceCache(), textureBlendMap));

        arrayLocation.clear();
        currentTexture =
            terrainDescriptor->getVariable("redAlbedo" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation = currentTexture;
            textureCount++;
            textureCountAlbedo++;
            textureLayer->setDiffuseScale(
                TerrainTextureLayer::TerrainTextureChannel::TEXTURE_RED_CHANNEL,
                terrainDescriptor->getVariablef("diffuseScaleR" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("greenAlbedo" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCount++;
            textureCountAlbedo++;
            textureLayer->setDiffuseScale(
                TerrainTextureLayer::TerrainTextureChannel::TEXTURE_GREEN_CHANNEL,
                terrainDescriptor->getVariablef("diffuseScaleG" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("blueAlbedo" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCount++;
            textureCountAlbedo++;
            textureLayer->setDiffuseScale(
                TerrainTextureLayer::TerrainTextureChannel::TEXTURE_BLUE_CHANNEL,
                terrainDescriptor->getVariablef("diffuseScaleB" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("alphaAlbedo" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCount++;
            textureCountAlbedo++;
            textureLayer->setDiffuseScale(
                TerrainTextureLayer::TerrainTextureChannel::TEXTURE_ALPHA_CHANNEL,
                terrainDescriptor->getVariablef("diffuseScaleA" +
                                                layerOffsetStr));
        }

        ResourceDescriptor textureTileMaps("Terrain Tile Maps_" + name +
                                           "_layer_" + layerOffsetStr);
        textureTileMaps.setEnumValue(to_const_uint(TextureType::TEXTURE_2D_ARRAY));
        textureTileMaps.setID(textureCountAlbedo);
        textureTileMaps.setResourceLocation(arrayLocation);
        textureTileMaps.setPropertyDescriptor(
            Attorney::TerrainLoader::getAlbedoSampler(*terrain));
        textureLayer->setTileMaps(CreateResource<Texture>(terrain->parentResourceCache(), textureTileMaps));

        arrayLocation.clear();
        currentTexture =
            terrainDescriptor->getVariable("redDetail" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCountDetail++;
            textureLayer->setDetailScale(
                TerrainTextureLayer::TerrainTextureChannel::TEXTURE_RED_CHANNEL,
                terrainDescriptor->getVariablef("detailScaleR" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("greenDetail" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCountDetail++;
            textureLayer->setDetailScale(
                TerrainTextureLayer::TerrainTextureChannel::TEXTURE_GREEN_CHANNEL,
                terrainDescriptor->getVariablef("detailScaleG" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("blueDetail" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCountDetail++;
            textureLayer->setDetailScale(
                TerrainTextureLayer::TerrainTextureChannel::TEXTURE_BLUE_CHANNEL,
                terrainDescriptor->getVariablef("detailScaleB" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("alphaDetail" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCountDetail++;
            textureLayer->setDetailScale(
                TerrainTextureLayer::TerrainTextureChannel::TEXTURE_ALPHA_CHANNEL,
                terrainDescriptor->getVariablef("detailScaleA" +
                                                layerOffsetStr));
        }

        ResourceDescriptor textureNormalMaps("Terrain Normal Maps_" + name +
                                             "_layer_" + layerOffsetStr);
        textureNormalMaps.setEnumValue(to_const_uint(TextureType::TEXTURE_2D_ARRAY));
        textureNormalMaps.setID(textureCountDetail);
        textureNormalMaps.setResourceLocation(arrayLocation);
        textureNormalMaps.setPropertyDescriptor(
            Attorney::TerrainLoader::getNormalSampler(*terrain));
        textureLayer->setNormalMaps(CreateResource<Texture>(terrain->parentResourceCache(), textureNormalMaps));

        Attorney::TerrainLoader::addTextureLayer(*terrain, textureLayer);
    }

    ResourceDescriptor terrainMaterialDescriptor("terrainMaterial_" + name);
    Material_ptr terrainMaterial =
        CreateResource<Material>(terrain->parentResourceCache(), terrainMaterialDescriptor);

    terrainMaterial->setDiffuse(
        vec4<F32>(DefaultColours::WHITE().rgb() / 2, 1.0f));
    terrainMaterial->setSpecular(vec4<F32>(0.1f, 0.1f, 0.1f, 1.0f));
    terrainMaterial->setShininess(20.0f);
    terrainMaterial->setShadingMode(Material::ShadingMode::BLINN_PHONG);
    terrainMaterial->setShaderDefines("COMPUTE_TBN");
    terrainMaterial->setShaderDefines("SKIP_TEXTURES");
    terrainMaterial->setShaderDefines("USE_SHADING_PHONG");
    terrainMaterial->setShaderDefines("MAX_TEXTURE_LAYERS " +
        to_stringImpl(Attorney::TerrainLoader::textureLayerCount(*terrain)));
    terrainMaterial->setShaderDefines("CURRENT_TEXTURE_COUNT " +
                                      to_stringImpl(textureCount));
    terrainMaterial->setShaderProgram("terrain", RenderStage::DISPLAY, true);
    terrainMaterial->setShaderProgram("terrain", RenderStage::REFLECTION, true);
    terrainMaterial->setShaderProgram("terrain", RenderStage::REFRACTION, true);
    terrainMaterial->setShaderProgram("depthPass.Shadow.Terrain", RenderStage::SHADOW, true);
    terrainMaterial->setShaderProgram("depthPass.PrePass.Terrain", RenderStage::Z_PRE_PASS, true);

    ResourceDescriptor textureWaterCaustics("Terrain Water Caustics_" + name);
    textureWaterCaustics.setResourceLocation(terrainDescriptor->getVariable("waterCaustics"));
    textureWaterCaustics.setPropertyDescriptor(Attorney::TerrainLoader::getAlbedoSampler(*terrain));
    textureWaterCaustics.setEnumValue(to_const_uint(TextureType::TEXTURE_2D));
    terrainMaterial->setTexture(ShaderProgram::TextureUsage::UNIT0, CreateResource<Texture>(terrain->parentResourceCache(), textureWaterCaustics));

    ResourceDescriptor underwaterAlbedoTexture("Terrain Underwater Albedo_" +
                                               name);
    underwaterAlbedoTexture.setResourceLocation(terrainDescriptor->getVariable("underwaterAlbedoTexture"));
    underwaterAlbedoTexture.setPropertyDescriptor(Attorney::TerrainLoader::getAlbedoSampler(*terrain));
    underwaterAlbedoTexture.setEnumValue(to_const_uint(TextureType::TEXTURE_2D));
    terrainMaterial->setTexture(ShaderProgram::TextureUsage::UNIT1, CreateResource<Texture>(terrain->parentResourceCache(), underwaterAlbedoTexture));

    ResourceDescriptor underwaterDetailTexture("Terrain Underwater Detail_" +
                                               name);
    underwaterDetailTexture.setResourceLocation(
        terrainDescriptor->getVariable("underwaterDetailTexture"));
    underwaterDetailTexture.setPropertyDescriptor(
        Attorney::TerrainLoader::getNormalSampler(*terrain));
    underwaterDetailTexture.setEnumValue(to_const_uint(TextureType::TEXTURE_2D));
    terrainMaterial->setTexture(ShaderProgram::TextureUsage::NORMALMAP, CreateResource<Texture>(terrain->parentResourceCache(), underwaterDetailTexture));

    terrainMaterial->setShaderLoadThreaded(false);
    terrainMaterial->dumpToFile(false);
    terrain->setMaterialTpl(terrainMaterial);

    // Generate a render state
    RenderStateBlock terrainRenderState;
    terrainRenderState.setCullMode(CullMode::CW);
    // Generate a render state for drawing reflections
    RenderStateBlock terrainRenderStateReflection;
    terrainRenderStateReflection.setCullMode(CullMode::CCW);
    // Generate a shadow render state
    RenderStateBlock terrainRenderStateDepth;
    terrainRenderStateDepth.setCullMode(CullMode::CCW);
    // terrainDescDepth.setZBias(1.0f, 2.0f);
    terrainRenderStateDepth.setColourWrites(true, true, false, false);

    Attorney::TerrainLoader::setRenderStateHashes(
        *terrain,
        terrainRenderState.getHash(),
        terrainRenderStateReflection.getHash(),
        terrainRenderStateDepth.getHash());

    return loadThreadedResources(terrain, terrainDescriptor);
}

bool TerrainLoader::loadThreadedResources(std::shared_ptr<Terrain> terrain, const TerrainDescriptor* terrainDescriptor) {
    ResourceDescriptor infinitePlane("infinitePlane");
    infinitePlane.setFlag(true);  // No default material

    vec2<F32>& terrainScaleFactor =
        Attorney::TerrainLoader::scaleFactor(*terrain);

    Attorney::TerrainLoader::chunkSize(*terrain) =
        terrainDescriptor->getChunkSize();
    terrainScaleFactor.set(terrainDescriptor->getScale());

    const vec2<U16>& terrainDimensions = terrainDescriptor->getDimensions();
    
    U16 heightmapWidth = terrainDimensions.width;
    U16 heightmapHeight = terrainDimensions.height;
    vectorImpl<U16> heightValues;
    stringImpl terrainRawFile(terrainDescriptor->getVariable("heightmap"));
    if (terrainDescriptor->is16Bit()) {
        assert(heightmapWidth != 0 && heightmapHeight != 0);
        // only raw files for 16 bit support
        assert(hasExtension(terrainRawFile, "raw"));
        // Read File Data
        FILE* terrainFile = fopen(terrainRawFile.c_str(), "rb");
        assert(terrainFile);
        U32 lCurPos = ftell(terrainFile);
        fseek(terrainFile, 0, SEEK_END);
        U32 positionCount = ftell(terrainFile);
        fseek(terrainFile, lCurPos, SEEK_SET);
        heightValues.reserve(positionCount / 2);
        U8* dataTemp = MemoryManager_NEW U8[positionCount];
        rewind(terrainFile);
        assert(dataTemp);
        fread(dataTemp, 1, positionCount, terrainFile);
        fclose(terrainFile);
        for (U32 i = 0; i < positionCount + 1; i += 2) {
            heightValues.push_back(((U8)dataTemp[i + 1] << 8) |
                                    (U8)dataTemp[i]);
        }
        MemoryManager::DELETE_ARRAY(dataTemp);
    } else {
        ImageTools::ImageData img;
        ImageTools::ImageDataInterface::CreateImageData(terrainRawFile, img);
        assert(terrainDimensions == img.dimensions());
        // data will be destroyed when img gets out of scope
        const U8* data = (const U8*)img.data();
        assert(data);
        heightValues.reserve(heightmapWidth * heightmapWidth);
        size_t size = img.imageLayers().front()._data.size();
        for (size_t i = 0; i < size; ++i) {
            heightValues.push_back(data[i]);
        }
    }
    vec2<U16>& dimensions = Attorney::TerrainLoader::dimensions(*terrain);
    Attorney::TerrainLoader::dimensions(*terrain)
        .set(heightmapWidth, heightmapHeight);
    if (dimensions.x % 2 == 0) {
        dimensions.x++;
    }
    if (dimensions.y % 2 == 0) {
        dimensions.y++;
    }
    Console::d_printfn(Locale::get(_ID("TERRAIN_INFO")), dimensions.x, dimensions.y);

    I32 terrainWidth = (I32)dimensions.x;
    I32 terrainHeight = (I32)dimensions.y;
    F32 minAltitude = terrainDescriptor->getAltitudeRange().x;
    F32 maxAltitude = terrainDescriptor->getAltitudeRange().y;
    F32 altitudeRange = maxAltitude - minAltitude;

    BoundingBox& terrainBB = Attorney::TerrainLoader::boundingBox(*terrain);

    terrainBB.set(
        vec3<F32>(-terrainWidth * 0.5f, minAltitude, -terrainHeight * 0.5f),
        vec3<F32>(terrainWidth * 0.5f, maxAltitude, terrainHeight * 0.5f));

    terrainBB.translate(terrainDescriptor->getPosition());
    terrainBB.multiply(vec3<F32>(terrainScaleFactor.x, terrainScaleFactor.y,
                                 terrainScaleFactor.x));
    F32 yOffset = terrainDescriptor->getPosition().y;
    const vec3<F32>& bMin = terrainBB.getMin();
    const vec3<F32>& bMax = terrainBB.getMax();
    F32 yScaleFactor = terrainScaleFactor.y;

    VertexBuffer* groundVB = terrain->getGeometryVB();

    stringImpl cacheLocation(terrainDescriptor->getVariable("heightmap"));
    cacheLocation += ".cache";

    ByteBuffer terrainCache;
    if (!terrainCache.loadFromFile(cacheLocation) ||
        !groundVB->deserialize(terrainCache)) {
        groundVB->resizeVertexCount(terrainWidth * terrainHeight);
        // scale and translate all height by half to convert from 0-255 (0-65335) to
        // -127 - 128 (-32767 - 32768)
        if (terrainDescriptor->is16Bit()) {
        #pragma omp parallel for
            for (I32 j = 0; j < terrainHeight; j++) {
                for (I32 i = 0; i < terrainWidth; i++) {
                    U32 idxHM = TER_COORD(i, j, terrainWidth);

                    F32 x = bMin.x + (to_float(i)) * (bMax.x - bMin.x) / (terrainWidth - 1);
                    F32 z = bMin.z + (to_float(j)) * (bMax.z - bMin.z) / (terrainHeight - 1);

                    U32 idxIMG = TER_COORD<U32>(
                        i < to_int(heightmapWidth) ? i : i - 1,
                        j < to_int(heightmapHeight) ? j : j - 1, heightmapWidth);

                    F32 y = minAltitude + altitudeRange * to_float(heightValues[idxIMG]) / 65536.0f;
                    y *= yScaleFactor;
                    y += yOffset;
        #pragma omp critical
                    { groundVB->modifyPositionValue(idxHM, x, y, z); }
                }
            }
        } else {
        #pragma omp parallel for
            for (I32 j = 0; j < terrainHeight; j++) {
                for (I32 i = 0; i < terrainWidth; i++) {
                    U32 idxHM = TER_COORD(i, j, terrainWidth);
                    vec3<F32> vertexData;

                    vertexData.x =
                        bMin.x + (to_float(i)) * (bMax.x - bMin.x) / (terrainWidth - 1);
                    vertexData.z =
                        bMin.z + (to_float(j)) * (bMax.z - bMin.z) / (terrainHeight - 1);

                    U32 idxIMG = TER_COORD<U32>(
                        i < to_int(heightmapWidth) ? i : i - 1,
                        j < to_int(heightmapHeight) ? j : j - 1, heightmapWidth);

                    F32 h = to_float(heightValues[idxIMG * 3 + 0] +
                                     heightValues[idxIMG * 3 + 1] +
                                     heightValues[idxIMG * 3 + 2]) /
                            3.0f;

                    vertexData.y = minAltitude + altitudeRange * h / 255.0f;
                    vertexData.y *= yScaleFactor;
                    vertexData.y += yOffset;
        #pragma omp critical
                    { groundVB->modifyPositionValue(idxHM, vertexData); }
                }
            }
        }

        heightValues.clear();

        I32 offset = 2;
        vec3<F32> vU, vV, vUV;
        U32 idx = 0, idx0 = 0, idx1 = 0;
        for (I32 j = offset; j < terrainHeight - offset; j++) {
            for (I32 i = offset; i < terrainWidth - offset; i++) {
                idx = TER_COORD(i, j, terrainWidth);

                vU.set(groundVB->getPosition(TER_COORD(i + offset, j + 0, terrainWidth)) -
                       groundVB->getPosition(TER_COORD(i - offset, j + 0, terrainWidth)));
                vV.set(groundVB->getPosition(TER_COORD(i + 0, j + offset, terrainWidth)) -
                       groundVB->getPosition(TER_COORD(i + 0, j - offset, terrainWidth)));
                vUV.cross(vV, vU);
                vUV.normalize();
                groundVB->modifyNormalValue(idx, vUV);
                vU = -vU;
                vU.normalize();
                groundVB->modifyTangentValue(idx, vU);
            }
        }

        vec3<F32> normal, tangent;
        for (I32 j = 0; j < offset; j++) {
            for (I32 i = 0; i < terrainWidth; i++) {
                idx0 = TER_COORD(i, j, terrainWidth);
                idx1 = TER_COORD(i, offset, terrainWidth);

                normal.set(groundVB->getNormal(idx1));
                tangent.set(groundVB->getTangent(idx1));

                groundVB->modifyNormalValue(idx0, normal);
                groundVB->modifyTangentValue(idx0, tangent);

                idx0 = TER_COORD(i, terrainHeight - 1 - j, terrainWidth);
                idx1 = TER_COORD(i, terrainHeight - 1 - offset, terrainWidth);

                normal.set(groundVB->getNormal(idx1));
                tangent.set(groundVB->getTangent(idx1));

                groundVB->modifyNormalValue(idx0, normal);
                groundVB->modifyTangentValue(idx0, tangent);
            }
        }

        for (I32 i = 0; i < offset; i++) {
            for (I32 j = 0; j < terrainHeight; j++) {
                idx0 = TER_COORD(i, j, terrainWidth);
                idx1 = TER_COORD(offset, j, terrainWidth);

                normal.set(groundVB->getNormal(idx1));
                tangent.set(groundVB->getTangent(idx1));

                groundVB->modifyNormalValue(idx0, normal);
                groundVB->modifyTangentValue(idx0, tangent);

                idx0 = TER_COORD(terrainWidth - 1 - i, j, terrainWidth);
                idx1 = TER_COORD(terrainWidth - 1 - offset, j, terrainWidth);

                normal.set(groundVB->getNormal(idx1));
                tangent.set(groundVB->getTangent(idx1));

                groundVB->modifyNormalValue(idx0, normal);
                groundVB->modifyTangentValue(idx0, tangent);
            }
        }
        if (groundVB->serialize(terrainCache)) {
            terrainCache.dumpToFile(cacheLocation);
        }
    }

    groundVB->keepData(true);
    groundVB->create();
    initializeVegetation(terrain, terrainDescriptor);
    Attorney::TerrainLoader::buildQuadtree(*terrain);

    Quad3D_ptr plane = CreateResource<Quad3D>(terrain->parentResourceCache(), infinitePlane);
    // our bottom plane is placed at the bottom of our water entity
    F32 height = bMin.y + yOffset;
    F32 farPlane = 2.0f * terrainBB.getWidth();

    plane->setCorner(Quad3D::CornerLocation::TOP_LEFT, vec3<F32>(-farPlane * 1.5f, height, -farPlane * 1.5f));
    plane->setCorner(Quad3D::CornerLocation::TOP_RIGHT, vec3<F32>(farPlane * 1.5f, height, -farPlane * 1.5f));
    plane->setCorner(Quad3D::CornerLocation::BOTTOM_LEFT, vec3<F32>(-farPlane * 1.5f, height, farPlane * 1.5f));
    plane->setCorner(Quad3D::CornerLocation::BOTTOM_RIGHT, vec3<F32>(farPlane * 1.5f, height, farPlane * 1.5f));

    Attorney::TerrainLoader::plane(*terrain, plane);

    Console::printfn(Locale::get(_ID("TERRAIN_LOAD_END")), terrain->getName().c_str());
    return terrain->load();
}

void TerrainLoader::initializeVegetation(std::shared_ptr<Terrain> terrain,
                                         const TerrainDescriptor* terrainDescriptor) {
    U8 textureCount = 0;
    stringImpl textureLocation;

    stringImpl currentImage = terrainDescriptor->getVariable("grassBillboard1");
    if (!currentImage.empty()) {
        textureLocation += currentImage;
        textureCount++;
    }

    currentImage = terrainDescriptor->getVariable("grassBillboard2");
    if (!currentImage.empty()) {
        textureLocation += "," + currentImage;
        textureCount++;
    }

    currentImage = terrainDescriptor->getVariable("grassBillboard3");
    if (!currentImage.empty()) {
        textureLocation += "," + currentImage;
        textureCount++;
    }

    currentImage = terrainDescriptor->getVariable("grassBillboard4");
    if (!currentImage.empty()) {
        textureLocation += "," + currentImage;
        textureCount++;
    }

    if (textureCount == 0){
        return;
    }

    SamplerDescriptor grassSampler;
    grassSampler.setAnisotropy(0);
    grassSampler.setWrapMode(TextureWrap::CLAMP);
    ResourceDescriptor textureDetailMaps("Vegetation Billboards");
    textureDetailMaps.setEnumValue(to_const_uint(TextureType::TEXTURE_2D_ARRAY));
    textureDetailMaps.setID(textureCount);
    textureDetailMaps.setResourceLocation(textureLocation);
    textureDetailMaps.setPropertyDescriptor(grassSampler);
    Texture_ptr grassBillboardArray = CreateResource<Texture>(terrain->parentResourceCache(), textureDetailMaps);

    VegetationDetails& vegDetails =
        Attorney::TerrainLoader::vegetationDetails(*terrain);
    vegDetails.billboardCount = textureCount;
    vegDetails.name = terrain->getName() + "_grass";
    vegDetails.grassDensity = terrainDescriptor->getGrassDensity();
    vegDetails.grassScale = terrainDescriptor->getGrassScale();
    vegDetails.treeDensity = terrainDescriptor->getTreeDensity();
    vegDetails.treeScale = terrainDescriptor->getTreeScale();
    vegDetails.grassBillboards = grassBillboardArray;
    vegDetails.grassShaderName = "grass";
    vegDetails.parentTerrain = terrain;

    vegDetails.map.reset(new ImageTools::ImageData);
    ImageTools::ImageDataInterface::CreateImageData(terrainDescriptor->getVariable("grassMap"), *vegDetails.map);
}

bool TerrainLoader::Save(const char* fileName) { return true; }

bool TerrainLoader::Load(const char* filename) { return true; }
};

Commits for Divide-Framework/trunk/Source Code/Environment/Terrain/TerrainLoader.cpp

Diff revisions: vs.
Revision Author Commited Message
832 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 17:23:11 +0000

[IonutCava]
- More path related work
- Initial code to centralize file I/O (does not compile yet)

831 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 23:52:34 +0000

[IonutCava]
- More path related updates

830 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 17:29:44 +0000

[IonutCava]
- Add a new Platform element: File
— Move all predefined paths to FileManagement System
- Split MathHelper into MathHelper and StringHelper

811 Diff Diff IonutCava picture IonutCava Wed 11 Jan, 2017 17:26:49 +0000

[IonutCava]
- Fix some threadpool cleanup bugs
- Fix terrain rendering (except underwater caustics)
- Fix terrain loading
- Fix terrain unloading

804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
764 Diff Diff IonutCava picture IonutCava Mon 22 Aug, 2016 15:38:11 +0000

[IonutCava]
- Add some explicit include for RenderStateBlock as it will be removed from the RenderAPIWrapper.h file

734 Diff Diff IonutCava picture IonutCava Tue 21 Jun, 2016 16:28:11 +0000

[IonutCava]
- Added a render target pool:
— All render targets are now allocated (and tracked) by the GFXDevice.
— Allocation routines return a slim RenderTargetHandle object that will be used later on in draw commands.

- Added a refraction render pass that will handle translucent objects that need refracted textures instead of clear transparency
— Both reflective nodes and refractive nodes are not gathered properly at this point

- All API specific objects (buffers, textures, etc) are now initialized in the GFXDevice class (see GFXDeviceObjects.cpp)
— This allowed for the slimming of the RenderAPIWrapper interface

- Improved ENABLE_GPU_VALIDATION macro utilization:
— It enabled shadow map split plane debugging
— It bypasses loading shaders from text cache

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

720 Diff Diff IonutCava picture IonutCava Mon 06 Jun, 2016 15:51:06 +0000

[IonutCava]
- PVS-Studio guided static analysis fixes and optimizations
- Added a flag to SceneState to bypass the Save/Load system not needed for certain types of scenes (menus, cinematics, etc)

710 IonutCava picture IonutCava Fri 20 May, 2016 16:24:40 +0000

[IonutCava]
- Code cleanup
- Initial work on Scene loading and unloading with and without unloading assets:
— Need to change AIManager from a Singleton to a per-scene component