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
/*
   Copyright (c) 2017 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef VEGETATION_H_
#define VEGETATION_H_

#include "Utility/Headers/ImageTools.h"
#include "Graphs/Headers/SceneNode.h"
#include "Platform/Threading/Headers/Task.h"
#include "Platform/Video/Headers/RenderAPIWrapper.h"

namespace Divide {

class Transform;
class SceneState;
class RenderTarget;
class ShaderBuffer;
class TerrainChunk;
class SceneGraphNode;
class RenderStateBlock;
class GenericVertexData;
enum class RenderStage : U32;

FWD_DECLARE_MANAGED_CLASS(Texture);
FWD_DECLARE_MANAGED_CLASS(Terrain);
FWD_DECLARE_MANAGED_CLASS(ShaderProgram);

struct VegetationDetails {
    U16 billboardCount;
    F32 grassDensity;
    F32 grassScale;
    F32 treeDensity;
    F32 treeScale;
    stringImpl name;
    stringImpl grassShaderName;
    std::shared_ptr<ImageTools::ImageData> map;
    std::weak_ptr<Terrain> parentTerrain;
    Texture_ptr grassBillboards;
};

/// Generates grass and trees on the terrain.
/// Grass VB's + all resources are stored locally in the class.
/// Trees are added to the SceneGraph and handled by the scene.
class Vegetation : public SceneNode {
   public:
    Vegetation(GFXDevice& context, ResourceCache& parentCache, size_t descriptorHash, U32 chunkID, const VegetationDetails& details);
    ~Vegetation();

    void initialize(TerrainChunk* const terrainChunk);

    inline void toggleRendering(bool state) { _render = state; }

    void initialiseDrawCommands(SceneGraphNode& sgn,
                                const RenderStagePass& renderStagePass,
                                GenericDrawCommands& drawCommandsInOut) override;
    void updateDrawCommands(SceneGraphNode& sgn,
                            const RenderStagePass& renderStagePass,
                            const SceneRenderState& sceneRenderState,
                            GenericDrawCommands& drawCommandsInOut) override;

   protected:
    void sceneUpdate(const U64 deltaTime,
                     SceneGraphNode& sgn,
                     SceneState& sceneState) override;

    bool onRender(const RenderStagePass& renderStagePass)  override;

    void gpuCull(const SceneRenderState& sceneRenderState);

   private:
    void uploadGrassData();
    void generateTrees(const Task& parentTask);
    void generateGrass(const Task& parentTask);

    U32 getQueryID();

   private:
    enum class CullType : U32 {
        PASS_THROUGH = 0,
        INSTANCE_CLOUD_REDUCTION = 1,
        HI_Z_CULL = 2,
        COUNT
    };

    GFXDevice& _context;
    // variables
    U8 _parentLoD;
    bool _render;  ///< Toggle vegetation rendering On/Off
    bool _success;
    std::atomic_bool _threadedLoadComplete;
    std::atomic_bool _stopLoadingRequest;
    std::weak_ptr<Terrain> _terrain;
    TerrainChunk* _terrainChunk;
    F32 _grassDensity, _treeDensity;
    U16 _billboardCount;  ///< Vegetation cumulated density
    F32 _grassSize, _grassScale, _treeScale;
    F32 _windX, _windZ, _windS, _time;
    U64 _stateRefreshInterval;
    U64 _stateRefreshIntervalBuffer;
    std::shared_ptr<ImageTools::ImageData> _map;  ///< Dispersion map for vegetation placement
    Texture_ptr _grassBillboards;
    ShaderProgram_ptr _cullShader;
    stringImpl _grassShaderName;
    bool _shadowMapped;
    size_t  _grassStateBlockHash;
    bool _culledFinal;
    U32 _readBuffer;
    U32 _writeBuffer;
    U32 _instanceCountGrass;
    U32 _instanceCountTrees;
    std::array<U32, to_base(CullType::COUNT)> _instanceRoutineIdx;
    vectorImpl<F32> _grassScales;
    vectorImplBest<vec4<F32> > _grassPositions;
    GenericVertexData* _grassGPUBuffer[2];
    GenericVertexData* _treeGPUBuffer[2];
    ShaderBuffer* _grassMatrices;
    static bool _staticDataUpdated;
    GenericDrawCommand _cullDrawCommand;
};

TYPEDEF_SMART_POINTERS_FOR_CLASS(Vegetation);

};  // namespace Divide

#endif

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

Diff revisions: vs.
Revision Author Commited Message
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.

852 Diff Diff IonutCava picture IonutCava Tue 07 Feb, 2017 17:17:27 +0000

[IonutCava]
- Separate Pass Type from Render Stage:
— Render Stage: Display, Shadow, Reflection, Refraction, etc
— Pass Type: Depth pass, Colour Pass, etc
- ToDo: Bug fixes for issues introduced with this change

851 Diff Diff IonutCava picture IonutCava Mon 06 Feb, 2017 23:38:14 +0000

[IonutCava]
- Replaced most RenderStage params with RenderStagePass types
- More work on water rendering

847 Diff Diff IonutCava picture IonutCava Sun 05 Feb, 2017 21:16:24 +0000

[IonutCava]
- Code rot fixes:
— Terrain loading (8 bit heightmap only for now)
— Terrain rendering
— Water Plane loading and rendering
— Reflection and Refraction rendering passes (hack for now: need environment cubemaps as separate from reflect/refract maps for planar rendering)
-— ToDo: Separate Reflection / Refraction render targets to Planar R/R and Cube R/R. Environment probes should use Cube Reflections, Water should use planar reflection targets.
- Added a way to register debug views: texture, shader and params. Viewports get automatically scaled and positioned
— ToDo: Add a hover-preview feature
— ToDo: Add a click-lock preview feature

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

833 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 22:04:33 +0000

[IonutCava]
- Fix most build errors. Divide-Server does not build for now.

811 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