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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#include "stdafx.h"

#include "Headers/Vegetation.h"

#include "Managers/Headers/SceneManager.h"
#include "Graphs/Headers/SceneGraphNode.h"
#include "Platform/Video/Headers/GFXDevice.h"
#include "Platform/Video/Headers/RenderStateBlock.h"
#include "Geometry/Material/Headers/Material.h"
#include "Environment/Terrain/Headers/Terrain.h"
#include "Environment/Terrain/Headers/TerrainChunk.h"
#include "Environment/Terrain/Quadtree/Headers/Quadtree.h"
#include "Environment/Terrain/Quadtree/Headers/QuadtreeNode.h"
#include "Platform/Video/Buffers/VertexBuffer/Headers/VertexBuffer.h"
#include "Platform/Video/Buffers/VertexBuffer/GenericBuffer/Headers/GenericVertexData.h"

namespace Divide {

bool Vegetation::_staticDataUpdated = false;

Vegetation::Vegetation(GFXDevice& context, ResourceCache& parentCache, size_t descriptorHash, U32 chunkID, const VegetationDetails& details)
    : SceneNode(parentCache, descriptorHash + chunkID, details.name + "_" + to_stringImpl(chunkID), SceneNodeType::TYPE_VEGETATION_GRASS),
      _context(context),
      _billboardCount(details.billboardCount),
      _grassDensity(details.grassDensity),
      _grassScale(details.grassScale),
      _treeScale(details.treeScale),
      _treeDensity(details.treeDensity),
      _grassBillboards(details.grassBillboards),
      _terrain(details.parentTerrain),
      _render(false),
      _success(false),
      _culledFinal(false),
      _shadowMapped(true),
      _terrainChunk(nullptr),
      _instanceCountGrass(0),
      _instanceCountTrees(0),
      _grassStateBlockHash(0),
      _stateRefreshIntervalBuffer(0ULL),
      _stateRefreshInterval(Time::SecondsToMicroseconds(1))  ///<Every second?
{
    _threadedLoadComplete = false;
    _stopLoadingRequest = false;
    _readBuffer = 1;
    _writeBuffer = 0;
    _parentLoD = 0;

    _map = details.map;
    _grassShaderName = details.grassShaderName;
    _grassGPUBuffer[0] = _context.newGVD(3);
    _grassGPUBuffer[1] = _context.newGVD(3);
    _treeGPUBuffer[0] = _context.newGVD(1);
    _treeGPUBuffer[1] = _context.newGVD(1);

    _cullDrawCommand = GenericDrawCommand(PrimitiveType::API_POINTS, 0, 1);

    _instanceRoutineIdx.fill(0);

    auto setShaderData = [this](Resource_wptr res) {
        ShaderProgram_ptr shader = std::dynamic_pointer_cast<ShaderProgram>(res.lock());

        shader->Uniform("ObjectExtent", vec3<F32>(1.0f, 1.0f, 1.0f));
        _instanceRoutineIdx[to_base(CullType::PASS_THROUGH)] = shader->GetSubroutineIndex(ShaderType::VERTEX, "PassThrough");
        _instanceRoutineIdx[to_base(CullType::INSTANCE_CLOUD_REDUCTION)] = shader->GetSubroutineIndex(ShaderType::VERTEX, "InstanceCloudReduction");
        _instanceRoutineIdx[to_base(CullType::HI_Z_CULL)] = shader->GetSubroutineIndex(ShaderType::VERTEX, "HiZOcclusionCull");
    };

    ResourceDescriptor instanceCullShader("instanceCull");
    instanceCullShader.setThreadedLoading(true);
    instanceCullShader.setID(3);
    instanceCullShader.setOnLoadCallback(setShaderData);
    _cullShader = CreateResource<ShaderProgram>(parentCache, instanceCullShader);
}

Vegetation::~Vegetation()
{
    Console::printfn(Locale::get(_ID("UNLOAD_VEGETATION_BEGIN")), getName().c_str());
    _stopLoadingRequest = true;
    U32 timer = 0;
    while (!_threadedLoadComplete) {
        // wait for the loading thread to finish first;
        std::this_thread::sleep_for(std::chrono::milliseconds(10));
        timer += 10;
        if (timer > 3000) {
            break;
        }
    }
    assert(_threadedLoadComplete);
    Console::printfn(Locale::get(_ID("UNLOAD_VEGETATION_END")));
}

void Vegetation::initialize(TerrainChunk* const terrainChunk) {
    assert(terrainChunk);
    assert(_map->data() != nullptr);

    _terrainChunk = terrainChunk;

    RenderStateBlock transparentRenderState;
    transparentRenderState.setCullMode(CullMode::CW);
    _grassStateBlockHash = transparentRenderState.getHash();

    ResourceDescriptor vegetationMaterial("vegetationMaterial" + getName());
    Material_ptr vegMaterial = CreateResource<Material>(_parentCache, vegetationMaterial);

    vegMaterial->setDiffuse(DefaultColours::WHITE());
    vegMaterial->setSpecular(vec4<F32>(0.1f, 0.1f, 0.1f, 1.0f));
    vegMaterial->setShininess(5.0f);
    vegMaterial->setShadingMode(Material::ShadingMode::BLINN_PHONG);
    vegMaterial->setShaderDefines("SKIP_TEXTURES");
    vegMaterial->setShaderProgram(_grassShaderName, RenderStage::DISPLAY, true);
    vegMaterial->setShaderProgram(_grassShaderName + ".Shadow", RenderStage::SHADOW, true);
    vegMaterial->setShaderProgram(_grassShaderName + ".PrePass",RenderPassType::DEPTH_PASS, true);
    vegMaterial->setTexture(ShaderProgram::TextureUsage::UNIT0, _grassBillboards);
    vegMaterial->setShaderLoadThreaded(false);
    vegMaterial->dumpToFile(false);
    setMaterialTpl(vegMaterial);

    CreateTask(_context.parent().platformContext(),
               DELEGATE_BIND(&Vegetation::generateGrass, this, std::placeholders::_1),
               DELEGATE_BIND(&Vegetation::uploadGrassData, this))
               .startTask(Task::TaskPriority::LOW);
    setState(ResourceState::RES_LOADED);
}

namespace {
enum class BufferUsage : U32 {
    UnculledPositionBuffer = 0,
    CulledPositionBuffer = 1,
    UnculledSizeBuffer = 2,
    CulledSizeBuffer = 3,
    CulledInstanceBuffer = 4,
    COUNT
};

const U32 posLocation = 10;
const U32 scaleLocation = 11;
const U32 instLocation = 12;
const U32 instanceDiv = 1;
};

void Vegetation::uploadGrassData() {
    if (_grassPositions.empty()) {
        _threadedLoadComplete = true;
        return;
    }

    static const vec2<F32> pos000(cosf(Angle::to_RADIANS(0.000f)),
                                  sinf(Angle::to_RADIANS(0.000f)));
    static const vec2<F32> pos120(cosf(Angle::to_RADIANS(120.0f)),
                                  sinf(Angle::to_RADIANS(120.0f)));
    static const vec2<F32> pos240(cosf(Angle::to_RADIANS(240.0f)),
                                  sinf(Angle::to_RADIANS(240.0f)));

    static const vec3<F32> vertices[] = {vec3<F32>(-pos000.x, 0.0f, -pos000.y),
                                         vec3<F32>(-pos000.x, 1.0f, -pos000.y),
                                         vec3<F32>(pos000.x, 1.0f, pos000.y),
                                         vec3<F32>(pos000.x, 0.0f, pos000.y),

                                         vec3<F32>(-pos120.x, 0.0f, -pos120.y),
                                         vec3<F32>(-pos120.x, 1.0f, -pos120.y),
                                         vec3<F32>(pos120.x, 1.0f, pos120.y),
                                         vec3<F32>(pos120.x, 0.0f, pos120.y),

                                         vec3<F32>(-pos240.x, 0.0f, -pos240.y),
                                         vec3<F32>(-pos240.x, 1.0f, -pos240.y),
                                         vec3<F32>(pos240.x, 1.0f, pos240.y),
                                         vec3<F32>(pos240.x, 0.0f, pos240.y)};

    static const U32 indices[] = {2, 1, 0, 2, 0, 1, 2, 0, 3, 2, 3, 0};

    static const vec2<F32> texcoords[] = {vec2<F32>(0.0f, 0.99f),
                                          vec2<F32>(0.0f, 0.01f),
                                          vec2<F32>(1.0f, 0.01f),
                                          vec2<F32>(1.0f, 0.99f)};

    vectorImpl<vec3<F32> > grassBlades;
    vectorImpl<vec2<F32> > texCoord;

    U32 indexOffset = 0;
    for (U8 j = 0; j < 3; ++j) {
        indexOffset = (j * 4);
        for (U8 l = 0; l < 12; ++l) {
            grassBlades.push_back(vertices[indices[l] + indexOffset]);
            texCoord.push_back(texcoords[(indices[l] + indexOffset) % 4]);
        }
    }

    static vectorImpl<mat3<F32> > rotationMatrices;
    if (rotationMatrices.empty()) {
        vectorImpl<F32> angles;
        angles.resize(18, 0.0f);
        for (U8 i = 0; i < 18; ++i) {
            F32 temp = Random(360.0f);
            while (std::find(std::begin(angles), std::end(angles), temp) !=
                   std::end(angles)) {
                temp = Random(360.0f);
            }
            angles[i] = temp;
        }

        mat3<F32> temp;
        for (U8 i = 0; i < 18; ++i) {
            temp.identity();
            temp.fromYRotation(angles[i]);
            rotationMatrices.push_back(temp);
        }
    }

    const Material_ptr& mat = getMaterialTpl();
    for (U8 pass = 0; pass < to_base(RenderPassType::COUNT); ++pass) {
        for (U32 i = 0; i < to_base(RenderStage::COUNT); ++i) {
            const ShaderProgram_ptr& drawShader = mat->getShaderInfo(RenderStagePass(static_cast<RenderStage>(i), static_cast<RenderPassType>(pass))).getProgram();

            drawShader->Uniform("positionOffsets", grassBlades);
            drawShader->Uniform("texCoordOffsets", texCoord);
            drawShader->Uniform("rotationMatrices", rotationMatrices);
            drawShader->Uniform("lod_metric", 100.0f);
        }
    }

    for (U8 i = 0; i < 2; ++i) {
        GenericVertexData* buffer = _grassGPUBuffer[i];

        buffer->create(to_U8(BufferUsage::COUNT), 3);
        // position culled will be generated using transform feedback using
        // shader output 'posLocation'
        // writing to buffer "CulledPositionBuffer"
        buffer->setFeedbackBuffer(to_base(BufferUsage::CulledPositionBuffer), 0);
        buffer->setFeedbackBuffer(to_base(BufferUsage::CulledSizeBuffer), 1);
        buffer->setFeedbackBuffer(to_base(BufferUsage::CulledInstanceBuffer), 2);

        buffer->setBuffer(to_base(BufferUsage::UnculledPositionBuffer), _instanceCountGrass,
                          sizeof(vec4<F32>), true, &_grassPositions[0], false, false);
        buffer->setBuffer(to_base(BufferUsage::UnculledSizeBuffer), _instanceCountGrass,
                          sizeof(F32), true, &_grassScales[0], false, false);
        buffer->setBuffer(to_base(BufferUsage::CulledPositionBuffer), _instanceCountGrass * 3,
                          sizeof(vec4<F32>), true, NULL, true, false);
        buffer->setBuffer(to_base(BufferUsage::CulledSizeBuffer), _instanceCountGrass * 3,
                          sizeof(F32), true, NULL, true, false);
        buffer->setBuffer(to_base(BufferUsage::CulledInstanceBuffer), _instanceCountGrass * 3,
                          sizeof(I32), true, NULL, true, false);

        buffer->attribDescriptor(posLocation)
            .set(to_base(BufferUsage::CulledPositionBuffer), instanceDiv, 4, false, 0, 
                             GFXDataFormat::FLOAT_32);
        buffer->attribDescriptor(scaleLocation)
            .set(to_base(BufferUsage::CulledSizeBuffer), instanceDiv, 1, false, 0,
                 GFXDataFormat::FLOAT_32);
        buffer->attribDescriptor(instLocation)
            .set(to_base(BufferUsage::CulledInstanceBuffer), instanceDiv, 1, false, 0,
                 GFXDataFormat::SIGNED_INT);
        buffer->fdbkAttribDescriptor(posLocation)
            .set(to_base(BufferUsage::UnculledPositionBuffer), instanceDiv, 4, false, 0,
                 GFXDataFormat::FLOAT_32);
        buffer->fdbkAttribDescriptor(scaleLocation)
            .set(to_base(BufferUsage::UnculledSizeBuffer), instanceDiv, 1, false, 0,
                 GFXDataFormat::FLOAT_32);

        buffer->toggleDoubleBufferedQueries(false);
    }

    _grassPositions.clear();
    _grassScales.clear();

    _render = _threadedLoadComplete = true;
}

void Vegetation::sceneUpdate(const U64 deltaTime,
                             SceneGraphNode& sgn,
                             SceneState& sceneState) {
    static const Task updateTask;

    const SceneRenderState& renderState = sceneState.renderState();
    if (_threadedLoadComplete && !_success) {
        generateTrees(updateTask);
        Camera::addUpdateListener([this, &renderState](const Camera& cam) {
            gpuCull(renderState);
        });
        _success = true;
    }

    if (_render && _success) {
        // Query shadow state every "_stateRefreshInterval" microseconds
        if (_stateRefreshIntervalBuffer >= _stateRefreshInterval) {
            if (!_staticDataUpdated) {
                _windX = sceneState.windDirX();
                _windZ = sceneState.windDirZ();
                _windS = sceneState.windSpeed();
                _stateRefreshIntervalBuffer -= _stateRefreshInterval;
                _cullShader->Uniform("dvd_visibilityDistance",
                                     sceneState.renderState().grassVisibility());
                _staticDataUpdated = true;
            }
        }
        _stateRefreshIntervalBuffer += deltaTime;

        _writeBuffer = (_writeBuffer + 1) % 2;
        _readBuffer = (_writeBuffer + 1) % 2;
        _culledFinal = false;
    }

    SceneNode::sceneUpdate(deltaTime, sgn, sceneState);
}

U32 Vegetation::getQueryID() {
    switch (_context.getRenderStage().stage()) {
        case RenderStage::SHADOW:
            return 0;
        case RenderStage::REFLECTION:
            return 1;
        case RenderStage::REFRACTION:
            return 2;
        default:
            return 3;
    };
}

void Vegetation::gpuCull(const SceneRenderState& sceneRenderState) {
    U32 queryID = getQueryID();

    if (_context.is2DRendering()) {
        return;
    }

    bool draw = false;
    switch (queryID) {
        case 0 /*SHADOW*/: {
            draw = _context.getRenderStage() != _context.getPrevRenderStage();
            _culledFinal = false;
        } break;
        case 1 /*REFLECTION*/: {
            draw = true;
            _culledFinal = false;
        } break;
        default: {
            draw = !_culledFinal;
            _culledFinal = true;
        } break;
    }
    _parentLoD = _terrainChunk->getLoD(Camera::activeCamera()->getEye());
    if (draw && _threadedLoadComplete && _parentLoD == 0) {
        GenericVertexData* buffer = _grassGPUBuffer[_writeBuffer];
        //_cullShader->SetSubroutine(VERTEX,
        //_instanceRoutineIdx[HI_Z_CULL]);
        _cullShader->Uniform("cullType",
                             /*queryID*/ to_base(CullType::INSTANCE_CLOUD_REDUCTION));

        _context.renderTarget(RenderTargetID(RenderTargetUsage::SCREEN)).bind(0, RTAttachmentType::Depth, 0);
        buffer->bindFeedbackBufferRange(to_base(BufferUsage::CulledPositionBuffer),
                                        _instanceCountGrass * queryID,
                                        _instanceCountGrass);
        buffer->bindFeedbackBufferRange(to_base(BufferUsage::CulledSizeBuffer),
                                        _instanceCountGrass * queryID,
                                        _instanceCountGrass);
        buffer->bindFeedbackBufferRange(to_base(BufferUsage::CulledInstanceBuffer),
                                        _instanceCountGrass * queryID,
                                        _instanceCountGrass);

        PipelineDescriptor pipeDesc;
        pipeDesc._shaderProgram = _cullShader;

        _cullDrawCommand.cmd().primCount = _instanceCountGrass;
        _cullDrawCommand.enableOption(GenericDrawCommand::RenderOptions::RENDER_NO_RASTERIZE);
        _cullDrawCommand.drawToBuffer(to_U8(queryID));
        _cullDrawCommand.pipeline(_context.newPipeline(pipeDesc));
        _cullDrawCommand.sourceBuffer(buffer);
        buffer->incQueryQueue();

        _context.draw(_cullDrawCommand);

        //_cullDrawCommand.setInstanceCount(_instanceCountTrees);
        //_cullDrawCommand.sourceBuffer(_treeGPUBuffer);
        // GFXDevice::instance().draw(_cullDrawCommand);
    }
}

void Vegetation::initialiseDrawCommands(SceneGraphNode& sgn,
                                        const RenderStagePass& renderStagePass,
                                        GenericDrawCommands& drawCommandsInOut) {

    GenericDrawCommand cmd;
    cmd.primitiveType(PrimitiveType::TRIANGLE_STRIP);
    cmd.cmd().firstIndex = 0;
    cmd.cmd().indexCount = 12 * 3;
    cmd.LoD(1);
    drawCommandsInOut.push_back(cmd);

    SceneNode::initialiseDrawCommands(sgn, renderStagePass, drawCommandsInOut);
}

void Vegetation::updateDrawCommands(SceneGraphNode& sgn,
                                    const RenderStagePass& renderStagePass,
                                    const SceneRenderState& sceneRenderState,
                                    GenericDrawCommands& drawCommandsOut) {

    GenericVertexData* buffer = _grassGPUBuffer[_readBuffer];
    U32 queryID = getQueryID();
    gpuCull(sceneRenderState);

    buffer->attribDescriptor(posLocation).offset(_instanceCountGrass * queryID);
    buffer->attribDescriptor(scaleLocation).offset(_instanceCountGrass * queryID);
    buffer->attribDescriptor(instLocation).offset(_instanceCountGrass * queryID);

    GenericDrawCommand& cmd = drawCommandsOut.front();

    PipelineDescriptor pipeDesc = cmd.pipeline().toDescriptor();
    pipeDesc._stateHash = _grassStateBlockHash;
    pipeDesc._shaderProgram.lock()->Uniform("grassScale", /*_grassScale*/1.0f);

    cmd.cmd().primCount = buffer->getFeedbackPrimitiveCount(to_U8(queryID));
    cmd.sourceBuffer(buffer);
    cmd.pipeline(_context.newPipeline(pipeDesc));

    SceneNode::updateDrawCommands(sgn, renderStagePass, sceneRenderState, drawCommandsOut);
}

bool Vegetation::onRender(const RenderStagePass& renderStagePass) {
    _staticDataUpdated = false;
    return !(!_render || !_success || !_threadedLoadComplete ||
             _parentLoD > 0 ||
             (renderStagePass == _context.getPrevRenderStage() &&
              renderStagePass.stage() == RenderStage::SHADOW));
}

void Vegetation::generateTrees(const Task& parentTask) {
}

void Vegetation::generateGrass(const Task& parentTask) {
    
    //const vec2<F32>& chunkPos = _terrainChunk->getOffsetAndSize().xy();
    const vec2<F32>& chunkSize = _terrainChunk->getOffsetAndSize().zw();
    const F32 waterLevel = _terrainChunk->waterHeight(); //< ToDo: make this dynamic! (cull underwater points later on?)
    const I32 currentCount = std::min((I32)_billboardCount, 4);
    const U16 mapWidth = _map->dimensions().width;
    const U16 mapHeight = _map->dimensions().height;
    const U32 grassElements = to_U32(_grassDensity * chunkSize.x * chunkSize.y);

    Console::printfn(Locale::get(_ID("CREATE_GRASS_BEGIN")), grassElements);

    STUBBED("We really need blue noise or casey muratori's special circle/hex for a nice distribution. Use Poisson disk sampling and optimise from there? -Ionut");
    /*
    ref: https://github.com/corporateshark/poisson-disk-generator/blob/master/Poisson.cpp
    ref: http://yutingye.info/OtherProjects_files/report.pdf
    ref: http://mollyrocket.com/casey/stream_0016.html
    THIS:

    generate the first random point p0
    insert p0 into active list
    place the index of p0 (zero) to the background grid cell
    while active list is not empty do
        choose a random point p from active list
        for attemp = 1:maxAttemp
            get new sample p? around p between r and 2r
            for each non-empty neighbor cell around p?
                if p? is closer than r
                    break
                end if
            end for
            if p? is far from all neighbors
                insert p? to active list
                place the index of p? to background grid cell
                break
            end if
        end for
        if maxAttemp exceed
            remove p from active list
        end if
    end while
    return

    OR THIS:
    real32 PointRadius = 0.025f;
    v2 Ac = { -2, -2 }; // Center of circle A
    real32 ArBase = 1.0f; // Starting radius of circle A
    v2 Bc = { -2, 2 }; // Center of circle B
    real32 BrBase = 1.0f; // Starting radius of circle B
    real32 dR = 2.5f*PointRadius; // Distance between concentric rings
    for (int32x RadiusStepA = 0; RadiusStepA < 128; ++RadiusStepA) {
        real32 Ar = ArBase + dR*(real32)RadiusStepA;
        for (int32x RadiusStepB = 0; RadiusStepB < 128; ++RadiusStepB) {
            real32 Br = BrBase + dR*(real32)RadiusStepB;
            real32 UseAr = Ar + ((RadiusStepB % 3) ? 0.0f : 0.3f*dR);
            real32 UseBr = Br + ((RadiusStepA % 3) ? 0.0f : 0.3f*dR);

            // Intersect circle Ac,UseAr and Bc,UseBr
            // Add the resulting points if they are within the pattern bounds
            // (the bounds were [-1,1] on both axes for all prior screenshots)
        }
    }
    */
    /*
    _grassPositions.reserve(grassElements);
    F32 densityFactor = 1.0f / _grassDensity;
#pragma omp parallel for
    for (I32 index = 0; index < currentCount; ++index) {
        densityFactor += 0.1f;
        for (F32 width = 0; width < chunkSize.x - densityFactor;
             width += densityFactor) {
            for (F32 height = 0; height < chunkSize.y - densityFactor;
                 height += densityFactor) {
                if (_stopLoadingRequest || stopRequested) {
                    continue;
                }
                F32 x = width + Random(densityFactor) + chunkPos.x;
                F32 y = height + Random(densityFactor) + chunkPos.y;
                CLAMP<F32>(x, 0.0f, to_F32(mapWidth) - 1.0f);
                CLAMP<F32>(y, 0.0f, to_F32(mapHeight) - 1.0f);
                F32 x_fac = x / _map->dimensions().width;
                F32 y_fac = y / _map->dimensions().height;

                I32 map_colour = _map->getColour((U16)x, (U16)y)[index];
                if (map_colour < 150) {
                    continue;
                }
                const vec3<F32>& P = _terrain->getPosition(x_fac, y_fac);
                if (P.y < waterLevel) {
                    continue;
                }
                const vec3<F32>& N = _terrain->getNormal(x_fac, y_fac);
                if (N.y < 0.7f) {
                    continue;
                }
#pragma omp critical
                {
                    position.set(P);
                    //mat4<F32> matRot1;
                    //matRot1.scale(vec3<F32>(grassScale));
                    //mat4<F32> matRot2;
                    //matRot2.fromYRotation(Random(360.0f));
                    //_grassMatricesTemp.push_back(matRot1 * matRot2 *
                    //rotationFromVToU(WORLD_Y_AXIS, N).getMatrix());

                    _grassPositions.push_back(vec4<F32>(P, to_F32(index)));
                    _grassScales.push_back(((map_colour + 1) / 256.0f));
                    _instanceCountGrass++;
                }
            }
        }
    }
    */
    Console::printfn(Locale::get(_ID("CREATE_GRASS_END")));
}
};

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

Diff revisions: vs.
Revision Author Commited Message
912 Diff Diff IonutCava picture IonutCava Sun 02 Jul, 2017 23:42:39 +0000

[Ionut]
- Add experimental Weighted Blended Order Independed Transparency (ref: http://casual-effects.blogspot.co.uk/2015/03/implemented-weighted-blended-order.html)
— Add per drawbuffer blend
— All translucent renderbin items go via the new OIT 2-step rendering: accumulation and composition
- Make sure we have proper blend enabled for text rendering
- Add a primitive form of PushConstants (unused yet. Emulated via Uniform calls)
- Fix bug with XMLParser not using case insensitive key lookups

909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

895 Diff Diff IonutCava picture IonutCava Wed 21 Jun, 2017 21:10:26 +0000

[IonutCava]
- Reorder and cleanup OpenGL backend a bit.
- Small code cleanup
- Some small profile-guided optimizations

893 Diff Diff IonutCava picture IonutCava Sun 18 Jun, 2017 17:33:07 +0000

[Ionut]
- Initial implementation of a PipelineStateObject (holds shader program, rasterizer state, etc)
- Rework PCH implementation a bit because VS2017 no longer has a /ZM option

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

881 Diff Diff IonutCava picture IonutCava Tue 21 Mar, 2017 22:07:37 +0000

[IonutCava]
- Multi draw command bug fix: drawCount > 1 should properly register all commands in the command buffer
- More tessellated terrain updates and fixes (still Work In Progress)

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

863 Diff Diff IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.

860 IonutCava picture IonutCava Mon 13 Feb, 2017 21:07:59 +0000

[IonutCava]
- Fix shared_ptr leak in resource loading callbacks