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
#include "Headers/Terrain.h"
#include "Headers/TerrainLoader.h"
#include "Headers/TerrainDescriptor.h"

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

namespace Divide {

TerrainLoader::TerrainLoader() : Singleton()
{
    _albedoSampler = MemoryManager_NEW SamplerDescriptor();
	_albedoSampler->setWrapMode(TEXTURE_REPEAT);
	_albedoSampler->setAnisotropy(8);
	_albedoSampler->toggleMipMaps(true);
	_albedoSampler->toggleSRGBColorSpace(true);

    _normalSampler = MemoryManager_NEW SamplerDescriptor();
	_normalSampler->setWrapMode(TEXTURE_REPEAT);
	_normalSampler->setAnisotropy(8);
	_normalSampler->toggleMipMaps(true);
}

TerrainLoader::~TerrainLoader()
{
    MemoryManager::DELETE( _albedoSampler );
    MemoryManager::DELETE( _normalSampler );
}

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

    SamplerDescriptor blendMapSampler;
    blendMapSampler.setWrapMode(TEXTURE_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 = stringAlg::toBase(Util::toString(i));
        textureLayer = MemoryManager_NEW TerrainTextureLayer();
        
        ResourceDescriptor textureBlendMap("Terrain Blend Map_" + name + "_layer_" + layerOffsetStr);
        textureBlendMap.setResourceLocation(terrainDescriptor->getVariable("blendMap" + layerOffsetStr));
        textureBlendMap.setPropertyDescriptor(blendMapSampler);
        textureLayer->setBlendMap(CreateResource<Texture>(textureBlendMap));

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

        ResourceDescriptor textureTileMaps("Terrain Tile Maps_" + name + "_layer_" + layerOffsetStr);
        textureTileMaps.setEnumValue(TEXTURE_2D_ARRAY);
        textureTileMaps.setId(textureCountAlbedo);
        textureTileMaps.setResourceLocation(arrayLocation);
		textureTileMaps.setPropertyDescriptor(*_albedoSampler);
        textureLayer->setTileMaps(CreateResource<Texture>(textureTileMaps));

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

		ResourceDescriptor textureNormalMaps("Terrain Normal Maps_" + name + "_layer_" + layerOffsetStr);
		textureNormalMaps.setEnumValue(TEXTURE_2D_ARRAY);
		textureNormalMaps.setId(textureCountDetail);
		textureNormalMaps.setResourceLocation(arrayLocation);
		textureNormalMaps.setPropertyDescriptor(*_normalSampler);
		textureLayer->setNormalMaps(CreateResource<Texture>(textureTileMaps));

        terrain->_terrainTextures.push_back(textureLayer);
    }   
   
    ResourceDescriptor terrainMaterialDescriptor("terrainMaterial_" + name);
    Material* terrainMaterial = CreateResource<Material>(terrainMaterialDescriptor);

    terrainMaterial->setDiffuse(vec4<F32>(DefaultColors::WHITE().rgb() / 2, 1.0f));
    terrainMaterial->setAmbient(vec4<F32>(DefaultColors::WHITE().rgb() / 3, 1.0f));
    terrainMaterial->setSpecular(vec4<F32>(0.1f, 0.1f, 0.1f, 1.0f));
    terrainMaterial->setShininess(20.0f);
    terrainMaterial->setShadingMode(Material::SHADING_BLINN_PHONG);
    terrainMaterial->addShaderDefines("COMPUTE_TBN");
    terrainMaterial->addShaderDefines("SKIP_TEXTURES");
    terrainMaterial->addShaderDefines(stringAlg::toBase("MAX_TEXTURE_LAYERS " + Util::toString(terrain->_terrainTextures.size())));
    terrainMaterial->addShaderDefines(stringAlg::toBase("CURRENT_TEXTURE_COUNT " + Util::toString(textureCount)));
    terrainMaterial->setShaderProgram("terrain", FINAL_STAGE, true);
    terrainMaterial->setShaderProgram("depthPass.Shadow.Terrain", SHADOW_STAGE, true);
    terrainMaterial->setShaderProgram("depthPass.PrePass.Terrain", Z_PRE_PASS_STAGE, true);

    ResourceDescriptor textureWaterCaustics("Terrain Water Caustics_" + name);
    textureWaterCaustics.setResourceLocation(terrainDescriptor->getVariable("waterCaustics"));
    textureWaterCaustics.setPropertyDescriptor(*_albedoSampler);
    terrainMaterial->setTexture(ShaderProgram::TEXTURE_UNIT0, CreateResource<Texture>(textureWaterCaustics));

    ResourceDescriptor underwaterAlbedoTexture("Terrain Underwater Albedo_" + name);
    underwaterAlbedoTexture.setResourceLocation(terrainDescriptor->getVariable("underwaterAlbedoTexture"));
	underwaterAlbedoTexture.setPropertyDescriptor(*_albedoSampler);
    terrainMaterial->setTexture(ShaderProgram::TEXTURE_UNIT1, CreateResource<Texture>(underwaterAlbedoTexture));

    ResourceDescriptor underwaterDetailTexture("Terrain Underwater Detail_" + name);
    underwaterDetailTexture.setResourceLocation(terrainDescriptor->getVariable("underwaterDetailTexture"));
    underwaterDetailTexture.setPropertyDescriptor(*_normalSampler);
    terrainMaterial->setTexture(ShaderProgram::TEXTURE_NORMALMAP, CreateResource<Texture>(underwaterDetailTexture));

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

    //Generate a render state
    RenderStateBlockDescriptor terrainDesc;
    terrainDesc.setCullMode(CULL_MODE_CW);
    RenderStateBlockDescriptor terrainDescRef;
    terrainDescRef.setCullMode(CULL_MODE_CCW);
    //Generate a shadow render state
    RenderStateBlockDescriptor terrainDescDepth;
    terrainDescDepth.setCullMode(CULL_MODE_CCW);
    //terrainDescDepth.setZBias(1.0f, 2.0f);
    terrainDescDepth.setColorWrites(true, true, false, false);

    terrain->_terrainRenderStateHash           = GFX_DEVICE.getOrCreateStateBlock(terrainDesc);
    terrain->_terrainReflectionRenderStateHash = GFX_DEVICE.getOrCreateStateBlock(terrainDescRef);
    terrain->_terrainDepthRenderStateHash      = GFX_DEVICE.getOrCreateStateBlock(terrainDescDepth);

    return loadThreadedResources(terrain, terrainDescriptor);
}

bool TerrainLoader::loadThreadedResources(Terrain* terrain, TerrainDescriptor* terrainDescriptor){
    ResourceDescriptor infinitePlane( "infinitePlane" );
    infinitePlane.setFlag( true ); //No default material
    terrain->_plane = CreateResource<Quad3D>( infinitePlane );
    // our bottom plane is placed at the bottom of our water entity
    F32 height = GET_ACTIVE_SCENE()->state().getWaterLevel() - GET_ACTIVE_SCENE()->state().getWaterDepth();
    terrain->_farPlane = 2.0f * GET_ACTIVE_SCENE()->state().getRenderState().getCameraConst().getZPlanes().y;
    terrain->_plane->setCorner( Quad3D::TOP_LEFT, vec3<F32>( -terrain->_farPlane * 1.5f, height, -terrain->_farPlane * 1.5f ) );
    terrain->_plane->setCorner( Quad3D::TOP_RIGHT, vec3<F32>( terrain->_farPlane * 1.5f, height, -terrain->_farPlane * 1.5f ) );
    terrain->_plane->setCorner( Quad3D::BOTTOM_LEFT, vec3<F32>( -terrain->_farPlane * 1.5f, height, terrain->_farPlane * 1.5f ) );
    terrain->_plane->setCorner( Quad3D::BOTTOM_RIGHT, vec3<F32>( terrain->_farPlane * 1.5f, height, terrain->_farPlane * 1.5f ) );

    VertexBuffer* groundVB = terrain->getGeometryVB();

    terrain->_chunkSize = terrainDescriptor->getChunkSize();
    terrain->_terrainScaleFactor.y = terrainDescriptor->getScale().y;
    terrain->_terrainScaleFactor.x = terrainDescriptor->getScale().x;
    
    const vec2<F32>& terrainScaleFactor = terrain->_terrainScaleFactor;
    const vec2<U16>& terrainDimensions = terrainDescriptor->getDimensions();
    const vectorImpl<vec3<F32> >& normalData  = groundVB->getNormal();
    const vectorImpl<vec3<F32> >& tangentData = groundVB->getTangent();

    U16 heightmapWidth = terrainDimensions.width;
    U16 heightmapHeight = terrainDimensions.height;
    vectorImpl<U16> heightValues;
    if ( terrainDescriptor->is16Bit() ) {
        assert( heightmapWidth != 0 && heightmapHeight != 0 );
        stringImpl terrainRawFile( terrainDescriptor->getVariable( "heightmap" ) );
        // only raw files for 16 bit support
        assert( terrainRawFile.substr( terrainRawFile.length() - 4, terrainRawFile.length() ).compare( ".raw" ) == 0 ); 
        // Read File Data
        FILE* terrainFile = nullptr;
        fopen_s( &terrainFile, 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;
        img.create( terrainDescriptor->getVariable( "heightmap" ) );
        assert( terrainDimensions == img.dimensions() );
        //data will be destroyed when img gets out of scope
        const U8* data = img.data();
        assert( data );
        heightValues.reserve( heightmapWidth * heightmapWidth );
        for ( size_t i = 0; i < img.imageSize(); ++i ) {
            heightValues.push_back( data[i] );
        }
    }


    terrain->_terrainWidth = heightmapWidth;
    terrain->_terrainHeight = heightmapHeight;

    if (terrain->_terrainWidth % 2 == 0)  terrain->_terrainWidth++;
    if (terrain->_terrainHeight % 2 == 0) terrain->_terrainHeight++;
    D_PRINT_FN(Locale::get("TERRAIN_INFO"), terrain->_terrainWidth, terrain->_terrainHeight);

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

    groundVB->resizePositionCount(terrainWidth *terrainHeight);
    groundVB->resizeNormalCount(terrainWidth * terrainHeight);
    groundVB->resizeTangentCount(terrainWidth * terrainHeight);

    BoundingBox& terrainBB = terrain->_boundingBox;

    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 = terrain->_terrainScaleFactor.y;
    // 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);

                vec3<F32> vertexData;
                vertexData.x = bMin.x + ((F32)i) * (bMax.x - bMin.x) / (terrainWidth - 1);
                vertexData.z = bMin.z + ((F32)j) * (bMax.z - bMin.z) / (terrainHeight - 1);

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

                vertexData.y = minAltitude + altitudeRange * (F32)heightValues[idxIMG] / 65536.0f;
                vertexData.y *= yScaleFactor;
                vertexData.y += yOffset;
                #pragma omp critical
                {
                      groundVB->modifyPositionValue(idxHM, vertexData);
                }
            }
        }
    }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 + ((F32)i) * (bMax.x - bMin.x) / (terrainWidth - 1);
                vertexData.z = bMin.z + ((F32)j) * (bMax.z - bMin.z) / (terrainHeight - 1);

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

                F32 h = (F32)(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();

    const vectorImpl<vec3<F32> >& groundPos = groundVB->getPosition();

    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(groundPos[TER_COORD(i + offset, j + 0, terrainWidth)] - groundPos[TER_COORD(i - offset, j + 0, terrainWidth)]);
            vV.set(groundPos[TER_COORD(i + 0, j + offset, terrainWidth)] - groundPos[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);
        }
    }

    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);

            groundVB->modifyNormalValue(idx0, normalData[idx1]);
            groundVB->modifyTangentValue(idx0,tangentData[idx1]);

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

            groundVB->modifyNormalValue(idx0, normalData[idx1]);
            groundVB->modifyTangentValue(idx0,tangentData[idx1]);
        }
    }

    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);

            groundVB->modifyNormalValue(idx0, normalData[idx1]);
            groundVB->modifyTangentValue(idx0,normalData[idx1]);

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

            groundVB->modifyNormalValue(idx0, normalData[idx1]);
            groundVB->modifyTangentValue(idx0,normalData[idx1]);
        }
    }
    groundVB->Create();
    terrain->buildQuadtree();

    initializeVegetation(terrain, terrainDescriptor);
    PRINT_FN(Locale::get("TERRAIN_LOAD_END"), terrain->getName().c_str());
    return true;
}

void TerrainLoader::initializeVegetation(Terrain* terrain, 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::TEXTURE_CLAMP);
    ResourceDescriptor textureDetailMaps("Vegetation Billboards");
    textureDetailMaps.setEnumValue(TEXTURE_2D_ARRAY);
    textureDetailMaps.setId(textureCount);
    textureDetailMaps.setResourceLocation(textureLocation);
    textureDetailMaps.setPropertyDescriptor(grassSampler);
    Texture* grassBillboardArray = CreateResource<Texture>(textureDetailMaps);

    terrain->_vegDetails.billboardCount = textureCount;
    terrain->_vegDetails.name = terrainDescriptor->getName() + "_grass";
    terrain->_vegDetails.grassDensity = terrainDescriptor->getGrassDensity();
    terrain->_vegDetails.grassScale = terrainDescriptor->getGrassScale();
    terrain->_vegDetails.treeDensity = terrainDescriptor->getTreeDensity();
    terrain->_vegDetails.treeScale = terrainDescriptor->getTreeScale();
    terrain->_vegDetails.map = terrainDescriptor->getVariable("grassMap");
    terrain->_vegDetails.grassBillboards = grassBillboardArray;
    terrain->_vegDetails.grassShaderName = "grass";
    terrain->_vegDetails.parentTerrain = terrain;
}

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
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

329 Diff Diff IonutCava picture IonutCava Tue 07 Oct, 2014 12:51:37 +0000

[Ionut]
- Modified material class and shaders to support multiple BRDFs (currently, only Flat, Phong and Blinn-Phong supported with Cook-Torrance and Oren-Nayar in future commits)
- Optimized transform updates and queries
- Fixed an indirect draw command (no buffer was bound to GL_DRAW_INDIRECT_BUFFER, violating a core requirement)

328 Diff Diff IonutCava picture IonutCava Sat 04 Oct, 2014 18:03:36 +0000

[Ionut]
- Added per SceneGraphNode material instances. (Cloned from the SceneNode’s material)
- Improved shader loading for materials

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

324 Diff Diff IonutCava picture IonutCava Sun 14 Sep, 2014 14:01:39 +0000

[Ionut]
- New memory management system (no custom allocators in this commit)
— Memory tracer to detect memory leaks on shutdown (from: https://www.relisoft.com/book/tech/9new.html)
— SAFE_DELETE_XYZ are now inline template functions not macros
— ASSERTION system now supports logging and message boxes and continue on error configurable for each build type
— Fixed a lot of memory leaks detected by the new system (some still remain)

- Added SRGB support (part 1)
— Albedo textures are loaded as SRGB (make sure resources are SRGB)
— Shaders output gamma corrected colors
— Moved terrain textures back to 2 array system (albedo and normal maps, albedo maps using a SRGB sampler)

- Sky is now loaded via the ResourceCache system
- Added include safeguards in shader atoms

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

301 Diff Diff IonutCava picture IonutCava Tue 05 Aug, 2014 20:55:30 +0000

[Ionut]
- Code cleanups and comments (ShaderManager, ShaderProgram, Texture)
- Fixed some singleton destruction order between ResourceCache and ShaderManager to properly unload remaining shader programs

296 Diff Diff k1ngp1n picture k1ngp1n Sun 03 Aug, 2014 14:54:21 +0000

[Ionut]
- nVidia compatibility fixes (GUI, shadows, post-processing)
- Texture bind slots are now part of ShaderProgram class
- Renamed ForwardRenderer class to ForwardPlusRenderer and moved ligh grid creation to it
- More code cleanups and comments

286 IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]