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
#include "Headers/Object3D.h"

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

Object3D::Object3D(const ObjectType& type, U32 flag) : Object3D("", type, flag)

{
}

Object3D::Object3D(const std::string& name, const ObjectType& type, U32 flag) : SceneNode(name,TYPE_OBJECT3D),
                                                                                _update(false),
                                                                                _geometryType(type),
                                                                                _geometryFlagMask(flag),
                                                                                _geometryPartitionId(0)
{
    _buffer = bitCompare(_geometryFlagMask, OBJECT_FLAG_NO_VB) ? nullptr : GFX_DEVICE.newVB();
}

Object3D::~Object3D()
{
    SAFE_DELETE(_buffer);
}

VertexBuffer* const Object3D::getGeometryVB() const {
    return _buffer;
}

void Object3D::render(SceneGraphNode* const sgn, const SceneRenderState& sceneRenderState, const RenderStage& currentRenderStage){
    ShaderProgram* drawShader = getDrawShader(currentRenderStage);

    if(drawCommands().empty()){
        GenericDrawCommand drawCmd;
        drawCmd.setStateHash(getDrawStateHash(currentRenderStage));
        drawCmd.setDrawIDs(GFX_DEVICE.getDrawIDs(sgn->getGUID()));
        drawCmd.setShaderProgram(drawShader);
        GFX_DEVICE.submitRenderCommand(getGeometryVB(), drawCmd);
    }else{
        for(GenericDrawCommand& cmd : _drawCommands)
            cmd.setShaderProgram(drawShader);

        GFX_DEVICE.submitRenderCommand(getGeometryVB(), drawCommands());
    }
}

bool Object3D::onDraw(SceneGraphNode* const sgn, const RenderStage& currentStage){
    return getState() == RES_LOADED;
}

void Object3D::computeNormals() {
    if (!getGeometryVB()) return;

    vec3<F32> v1 , v2, normal;
    //Code from http://devmaster.net/forums/topic/1065-calculating-normals-of-a-mesh/

    vectorImpl<vec3<F32> >* normal_buffer = new vectorImpl<vec3<F32> >[getGeometryVB()->getPosition().size()];

    for( U32 i = 0; i < getGeometryVB()->getIndexCount(); i += 3 ) {
        // get the three vertices that make the faces
        const vec3<F32>& p1 = getGeometryVB()->getPosition(getGeometryVB()->getIndex(i+0));
        const vec3<F32>& p2 = getGeometryVB()->getPosition(getGeometryVB()->getIndex(i+1));
        const vec3<F32>& p3 = getGeometryVB()->getPosition(getGeometryVB()->getIndex(i+2));

        v1.set(p2 - p1);
        v2.set(p3 - p1);
        normal.cross(v1, v2);
        normal.normalize();

        // Store the face's normal for each of the vertices that make up the face.
        normal_buffer[getGeometryVB()->getIndex(i+0)].push_back( normal );
        normal_buffer[getGeometryVB()->getIndex(i+1)].push_back( normal );
        normal_buffer[getGeometryVB()->getIndex(i+2)].push_back( normal );
    }

    getGeometryVB()->resizeNormalCount((U32)getGeometryVB()->getPosition().size());
    // Now loop through each vertex vector, and average out all the normals stored.
    vec3<F32> currentNormal;
    for(U32 i = 0; i < getGeometryVB()->getPosition().size(); ++i ){
        currentNormal.reset();
        for(U32 j = 0; j < normal_buffer[i].size(); ++j ){
            currentNormal += normal_buffer[i][j];
        }
        currentNormal /= normal_buffer[i].size();

        getGeometryVB()->modifyNormalValue(i, currentNormal);
    }
    SAFE_DELETE_ARRAY(normal_buffer);
}

void Object3D::computeTangents(){
    if (!getGeometryVB()) return;

    //Code from: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/#header-1
    // inputs
    const vectorImpl<vec2<F32> > & uvs      = getGeometryVB()->getTexcoord();
    //const vectorImpl<vec3<F32> > & normals  = _geometry->getNormal();

    vec3<F32> deltaPos1, deltaPos2;
    vec2<F32> deltaUV1, deltaUV2;
    vec3<F32> tangent, bitangent;

    for( U32 i = 0; i < getGeometryVB()->getIndexCount(); i += 3 ) {
        // get the three vertices that make the faces
        const vec3<F32>& v0 = getGeometryVB()->getPosition(getGeometryVB()->getIndex(i+0));
        const vec3<F32>& v1 = getGeometryVB()->getPosition(getGeometryVB()->getIndex(i+1));
        const vec3<F32>& v2 = getGeometryVB()->getPosition(getGeometryVB()->getIndex(i+2));

        // Shortcuts for UVs
        const vec2<F32> & uv0 = uvs[getGeometryVB()->getIndex(i+0)];
        const vec2<F32> & uv1 = uvs[getGeometryVB()->getIndex(i+1)];
        const vec2<F32> & uv2 = uvs[getGeometryVB()->getIndex(i+2)];

        // Edges of the triangle : position delta
        deltaPos1.set(v1-v0);
        deltaPos2.set(v2-v0);

        // UV delta
        deltaUV1.set(uv1-uv0);
        deltaUV2.set(uv2-uv0);

        F32 r = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV1.y * deltaUV2.x);
        tangent.set((deltaPos1 * deltaUV2.y   - deltaPos2 * deltaUV1.y)*r);
        bitangent.set((deltaPos2 * deltaUV1.x   - deltaPos1 * deltaUV2.x)*r);

        // Set the same tangent for all three vertices of the triangle.
        // They will be merged later, in vbindexer.cpp
        getGeometryVB()->addTangent(tangent);
        getGeometryVB()->addTangent(tangent);
        getGeometryVB()->addTangent(tangent);
        // Same thing for binormals
        getGeometryVB()->addBiTangent(bitangent);
        getGeometryVB()->addBiTangent(bitangent);
        getGeometryVB()->addBiTangent(bitangent);
    }
}

//Create a list of triangles from the vertices + indices lists based on primitive type
bool Object3D::computeTriangleList(bool force){
    VertexBuffer* geometry = getGeometryVB();
    U32 partitionOffset = geometry->getPartitionOffset(_geometryPartitionId);
    U32 partitionCount  = geometry->getPartitionCount(_geometryPartitionId);
    PrimitiveType type  = (_geometryType == MESH || _geometryType == SUBMESH ? TRIANGLES : TRIANGLE_STRIP);
    //We can't have a VB without vertex positions
    DIVIDE_ASSERT(!geometry->getPosition().empty(), "Object3D error: computeTriangleList called with no position data available!");

    if(!_geometryTriangles.empty() && force) 
        _geometryTriangles.resize(0);

    if(geometry->getIndexCount() == 0) 
        return false;
    
    U32 indiceCount = partitionCount;
    bool largeIndices = geometry->usesLargeIndices();
    if(type == TRIANGLE_STRIP){
        U32 indiceStart = 2 + partitionOffset;
        U32 indiceEnd = indiceCount + partitionOffset;
        vec3<U32> curTriangle;
        _geometryTriangles.reserve(indiceCount * 0.5);
        if(largeIndices){
            const vectorImpl<U32>& indices = geometry->getIndicesL();
            for(U32 i = indiceStart; i < indiceEnd; i++){
                curTriangle.set(indices[i - 2], indices[i - 1], indices[i]);
                //Check for correct winding
                if (i % 2 != 0) std::swap(curTriangle.y, curTriangle.z);
                _geometryTriangles.push_back(curTriangle);
            }
        }else{
            const vectorImpl<U16>& indices = geometry->getIndicesS();
            for(U32 i = indiceStart; i < indiceEnd; i++){
                curTriangle.set(indices[i - 2], indices[i - 1], indices[i]);
                //Check for correct winding
                if (i % 2 != 0) std::swap(curTriangle.y, curTriangle.z);
                _geometryTriangles.push_back(curTriangle);
            }
        }
    }else if (type == TRIANGLES){
        indiceCount /= 3;
        _geometryTriangles.reserve(indiceCount);
        if(largeIndices){
            const vectorImpl<U32>& indices = geometry->getIndicesL();
            for(U32 i = 0; i < indiceCount; i++){
                    _geometryTriangles.push_back(vec3<U32>(indices[i*3 + 0],indices[i*3 + 1],indices[i*3 + 2]));
            }
        }else{
            const vectorImpl<U16>& indices = geometry->getIndicesS();
                for(U32 i = 0; i < indiceCount; i++){
                    _geometryTriangles.push_back(vec3<U32>(indices[i*3 + 0],indices[i*3 + 1],indices[i*3 + 2]));
            }
        }
    }

    //Check for degenerate triangles
    _geometryTriangles.erase(std::partition(_geometryTriangles.begin(), _geometryTriangles.end(),
                            [](const vec3<U32>& triangle) -> bool {
                            return (triangle.x != triangle.y && triangle.x != triangle.z && triangle.y != triangle.z);
                        }), _geometryTriangles.end());

    DIVIDE_ASSERT(!_geometryTriangles.empty(), "Object3D error: computeTriangleList() failed to generate any triangles!");
    return true;
}

Commits for Divide-Framework/trunk/Source Code/Geometry/Shapes/Object3D.cpp

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

279 Diff Diff IonutCava picture IonutCava Sat 28 Jun, 2014 16:20:46 +0000

[Ionut][[BR]]
- Unified draw command system into GenericDrawCommand [[BR]]
- Fixed double VB creation in Object3D [[BR]]
- Reworked triangle data computation (now Object3D’s responsibility) [[BR]]
- VertexArrays can now render using the primitive type specified in the draw command instead of the fixed type specified at creation [[BR]]
- Optimized terrain shader [[BR]]

276 Diff Diff IonutCava picture IonutCava Fri 13 Jun, 2014 18:23:32 +0000

[Ionut][[BR]]
- Terrain now inherits from Object3D (instead of directly from SceneNode) [[BR]]
- Restructured RenderInstance to support multiple draw commands [[BR]]
— Multiple draw commands per instance are separated to different LoD batches automatically on render [[BR]]

274 Diff Diff IonutCava picture IonutCava Fri 13 Jun, 2014 12:56:03 +0000

[Ionut] [[BR]]
- Simplified buffer based rendering (VertexBuffer & GenericVertexData are now exclusively command based) [[BR]]
- Update bone buffer to persistent mapped-SSBO system with double-buffering [[BR]]
- Simplified sky rendering and (finally) reduced the sun’s radius [[BR]]

273 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 20:34:00 +0000

[Ionut] [[BR]]
- Improved batching part2: [[BR]]
— Moved all bone transformation matrices upload from uniform functions in SceneNode to Shader Storage Buffers in AnimationController class with updates controlled by SceneGraphNode’s AnimationComponent [[BR]]
-— No double-buffering or efficient mapping of data yet. Just raw buffer updates [[BR]]
— Replaced all RenderStateBlock* pointers with I64 hash values [[BR]]
-— Will be used later in draw commands as per-shader state hash [[BR]]
— Moved getShaderProgram from Material to Material::ShaderInfo [[BR]]
-— Improved redundant uniform checks [[BR]]
— Improved texture unit changing in case of redundant texture bind case (i.e. skip changing the texture unit) [[BR]]
[[BR]]
- Improved float and double comparison functions using algorithms described in http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/ [[BR]]
- Added a new utility function, DIVIDE_ASSERT, to more easily bind an assert check with a specific message [[BR]]
- Added missing files from Forward+ renderer’s initial code [[BR]]

270 Diff Diff IonutCava picture IonutCava Thu 05 Jun, 2014 19:08:07 +0000

[Ionut][[BR]]
- SubMeshes now use a single vertex buffer (owned by the parent mesh) with proper offsetting and querying [[BR]]
— Implementation not optimal yet [[BR]]
- Cleaned up VertexBuffer related classes [[BR]]

264 Diff Diff k1ngp1n picture k1ngp1n Tue 27 May, 2014 13:04:38 +0000

[Ionut] [[BR]]
- New camera system: [[BR]]
— Stack based (push/pop active camera) [[BR]]
— Per camera frustum [[BR]]
— Per camera projection [[BR]]
— Shadow mapping now uses the new camera system (each light has a shadow camera) [[BR]]
[[BR]]
- New terrain, water and vegetation system: [[BR]]
— Direct import of terrain from L3DT both as 8-bit grayscale and 16-bit raw formats [[BR]]
— Multiple alpha maps for texture splatting support [[BR]]
— Per texture detail map support [[BR]]
— Transform feedback based visibility culling for vegetation [[BR]]
— Alpha-map based vegetation placing on terrain [[BR]]
— Water now uses a refraction map instead of alpha blending for better refraction effects [[BR]]
[[BR]]
- SceneGraph improvements: [[BR]]
— Better bounding box updates from child to parent [[BR]]
— Better onDraw / postDraw implementation [[BR]]
[[BR]]
- Performance improvements: [[BR]]
— Batch 2D rendering tasks together as much as possible[[BR]]
— Improve renderStateBlock hash generation for better sorting [[BR]]
— Move most state related gfx changes from API implementation to the GFXDevice class [[BR]]
— Move viewport stack to the GFXDevice class [[BR]]
— Added various performance counters (frame duration with round-robin query system, draw call count, etc) [[BR]]
— Fixed and improved clip plane management [[BR]]
— Delete client-side texture data after GPU upload [[BR]]
[[BR]]
- New features: [[BR]]
— Added callback support to the Task class so that a specific task may call a function in the main thread upon completion [[BR]]
— Added mouse-wheel zoom support to Orbit/ThirdPerson cameras [[BR]]
— Added 2D Texture Array support (e.g. used for terrain textures) [[BR]]

259 Diff Diff k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]

258 Diff Diff k1ngp1n picture k1ngp1n Tue 15 Apr, 2014 15:26:22 +0000

[Ionut]
- Bumped minimum OpenGL required version to 4.3 (any Fermi and GCN 1.1 GPU)
- Fixed an issue with opacity maps
- Improved loading times by optimizing console output system and various optimizations in DVDConverter
- Create GUIConsole when needed (not on load)
- Moved common control code to the Scene class

253 k1ngp1n picture k1ngp1n Wed 09 Apr, 2014 11:30:54 +0000

[Ionut] [[BR]]
- Split SceneAnimator in global and per-instance data (SceneAnimator and AnimatorComponent) respectively [[BR]]
— Each SceneNode, sharing the same skinned mesh can have different animations with different timings now [[BR]]
- Fixed particle systems' billboarding issues [[BR]]
- More cleaning up of the Material class [[BR]]