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
-- Vertex

layout(location = 10) in vec4 intanceData;
layout(location = 11) in float instanceData2;

uniform vec3 ObjectExtent;
uniform float dvd_visibilityDistance;
uniform float dvd_frustumBias = 0.01;


/*layout(std430, binding = 10) buffer dvd_transformBlock{
    coherent readonly mat4 transform[];
};*/

out vec4 OrigData;
out float OrigData2;
flat out int OrigData3;
flat out int objectVisible;

vec4 BoundingBox[8];

uniform sampler2D HiZBuffer;

subroutine int CullRoutineType(const in vec3 position);
subroutine uniform CullRoutineType CullRoutine;

//subroutine(CullRoutineType)
int PassThrough(const in vec3 position) {
    return 1;
}

//subroutine(CullRoutineType)
int InstanceCloudReduction(const in vec3 position) {

    //mat4 finalTransform = dvd_ViewProjectionMatrix * transform[gl_InstanceID];
    mat4 finalTransform = dvd_ViewProjectionMatrix;
    // create the bounding box of the object 
    BoundingBox[0] = finalTransform * vec4(position + vec3( ObjectExtent.x,  ObjectExtent.y,  ObjectExtent.z), 1.0);
    BoundingBox[1] = finalTransform * vec4(position + vec3(-ObjectExtent.x,  ObjectExtent.y,  ObjectExtent.z), 1.0);
    BoundingBox[2] = finalTransform * vec4(position + vec3( ObjectExtent.x, -ObjectExtent.y,  ObjectExtent.z), 1.0);
    BoundingBox[3] = finalTransform * vec4(position + vec3(-ObjectExtent.x, -ObjectExtent.y,  ObjectExtent.z), 1.0);
    BoundingBox[4] = finalTransform * vec4(position + vec3( ObjectExtent.x,  ObjectExtent.y, -ObjectExtent.z), 1.0);
    BoundingBox[5] = finalTransform * vec4(position + vec3(-ObjectExtent.x,  ObjectExtent.y, -ObjectExtent.z), 1.0);
    BoundingBox[6] = finalTransform * vec4(position + vec3( ObjectExtent.x, -ObjectExtent.y, -ObjectExtent.z), 1.0);
    BoundingBox[7] = finalTransform * vec4(position + vec3(-ObjectExtent.x, -ObjectExtent.y, -ObjectExtent.z), 1.0);

    // check how the bounding box resides regarding to the view frustum 
    uint outOfBound[6] = uint[6](0, 0, 0, 0, 0, 0);

    vec4 crtBB;
    float frustumLimit = 0.0;
    for (uint i = 0; i < 8; i++)  {
        crtBB = BoundingBox[i];
        frustumLimit = crtBB.w + dvd_frustumBias;
        if (crtBB.x >  frustumLimit) outOfBound[0]++;
        if (crtBB.x < -frustumLimit) outOfBound[1]++;
        if (crtBB.y >  frustumLimit) outOfBound[2]++;
        if (crtBB.y < -frustumLimit) outOfBound[3]++;
        if (crtBB.z >  frustumLimit) outOfBound[4]++;
        if (crtBB.z < -frustumLimit) outOfBound[5]++;
    }

    return (outOfBound[0] == 8 || outOfBound[1] == 8 || outOfBound[2] == 8 ||
            outOfBound[3] == 8 || outOfBound[4] == 8 || outOfBound[5] == 8) ? 0 : 1;
}

//subroutine(CullRoutineType)
int HiZOcclusionCull(const in vec3 position) {
    /* first do instance cloud reduction */
    if (InstanceCloudReduction(position) == 0) return 0;

    if (distance(dvd_ViewMatrix * vec4(position, 1.0), vec4(0.0, 0.0, 0.0, 1.0)) > dvd_visibilityDistance)
        return 0;
    
    /* perform perspective division for the bounding box */
    BoundingBox[0].xyz /= BoundingBox[0].w;
    BoundingBox[1].xyz /= BoundingBox[1].w;
    BoundingBox[2].xyz /= BoundingBox[2].w;
    BoundingBox[3].xyz /= BoundingBox[3].w;
    BoundingBox[4].xyz /= BoundingBox[4].w;
    BoundingBox[5].xyz /= BoundingBox[5].w;
    BoundingBox[6].xyz /= BoundingBox[6].w;
    BoundingBox[7].xyz /= BoundingBox[7].w;

    /* calculate screen space bounding rectangle */
    vec2 BoundingRect[2];
    BoundingRect[0].x = min(min(min(BoundingBox[0].x, BoundingBox[1].x), min(BoundingBox[2].x, BoundingBox[3].x)),
                            min(min(BoundingBox[4].x, BoundingBox[5].x), min(BoundingBox[6].x, BoundingBox[7].x))) * 0.5 + 0.5;

    BoundingRect[0].y = min(min(min(BoundingBox[0].y, BoundingBox[1].y), min(BoundingBox[2].y, BoundingBox[3].y)),
                            min(min(BoundingBox[4].y, BoundingBox[5].y), min(BoundingBox[6].y, BoundingBox[7].y))) * 0.5 + 0.5;

    BoundingRect[1].x = max(max(max(BoundingBox[0].x, BoundingBox[1].x), max(BoundingBox[2].x, BoundingBox[3].x)),
                            max(max(BoundingBox[4].x, BoundingBox[5].x), max(BoundingBox[6].x, BoundingBox[7].x))) * 0.5 + 0.5;

    BoundingRect[1].y = max(max(max(BoundingBox[0].y, BoundingBox[1].y), max(BoundingBox[2].y, BoundingBox[3].y)),
                            max(max(BoundingBox[4].y, BoundingBox[5].y), max(BoundingBox[6].y, BoundingBox[7].y))) * 0.5 + 0.5;

    /* then the linear depth value of the front-most point */
    float InstanceDepth = min(min(min(BoundingBox[0].z, BoundingBox[1].z), min(BoundingBox[2].z, BoundingBox[3].z)),
                              min(min(BoundingBox[4].z, BoundingBox[5].z), min(BoundingBox[6].z, BoundingBox[7].z)));

    /* now we calculate the bounding rectangle size in viewport coordinates */
    /* now we calculate the texture LOD used for lookup in the depth buffer texture */
    float LOD = ceil(log2(max((BoundingRect[1].x - BoundingRect[0].x) * dvd_ViewPort.y, (BoundingRect[1].y - BoundingRect[0].y) * dvd_ViewPort.z) / 2.0));

    /* finally fetch the depth texture using explicit LOD lookups */
    /* if the instance depth is bigger than the depth in the texture discard the instance */
    return (InstanceDepth > max(max(textureLod(HiZBuffer, vec2(BoundingRect[0].x, BoundingRect[0].y), LOD).x, 
                                    textureLod(HiZBuffer, vec2(BoundingRect[0].x, BoundingRect[1].y), LOD).x),
                                max(textureLod(HiZBuffer, vec2(BoundingRect[1].x, BoundingRect[1].y), LOD).x,
                                    textureLod(HiZBuffer, vec2(BoundingRect[1].x, BoundingRect[0].y), LOD).x))) ? 0 : 1;
}

uniform uint cullType = 0;

void main(void) {

    OrigData = intanceData;
    OrigData2 = instanceData2;
    OrigData3 = gl_InstanceID;
    //objectVisible = CullRoutine(OrigData.xyz);
    objectVisible = cullType > 0 ? (cullType > 1 ? HiZOcclusionCull(OrigData.xyz) : InstanceCloudReduction(OrigData.xyz)) : PassThrough(OrigData.xyz);
}

-- Geometry

layout(points) in;
layout(points, max_vertices = 1) out;

in vec4 OrigData[1];
in float OrigData2[1];
flat in int OrigData3[1];

flat in int objectVisible[1];

out vec4 outVertexData;
out float outData1;
flat out int outData2;

//uniform uint queryId;
//layout(binding = 0, offset = 0) uniform atomic_uint primitiveCount[5];

void main() {

    // only emit primitive if the object is visible 
    if (objectVisible[0] == 1)  {
        //atomicCounterIncrement(primitiveCount[queryId]);
        outVertexData = OrigData[0];
        outData1 = OrigData2[0];
        outData2 = OrigData3[0];
        EmitVertex();
        EndPrimitive();
    }
}

Commits for Divide-Framework/trunk/assets/shaders/GLSL/instanceCull.glsl

Diff revisions: vs.
Revision Author Commited Message
280 Diff Diff IonutCava picture IonutCava Sat 28 Jun, 2014 19:11:37 +0000

[Ionut] [[BR]]
- Improve ClipPlane management (bunch equations into the matrix shader buffer) [[BR]]
- Immediate mode emulation primitives set their own state based on specified hash instead of relying on state functions to be defined [[BR]]
- updateStates() function is now called right before the actual draw call to facilitate future batching work [[BR]]
- added tracked bool values (similar to those in ShaderInfo) to SGN class to fix selection bug. [[BR]]
— will probably create a “stateTracker” class to allow multiple classes to use tracked variables without all of the code duplication [[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]]

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]]

272 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 11:30:51 +0000

[Ionut] [[BR]]
- Added initial code for Forward+ rendering (grid based light culling) [[BR]]
- Simplified Light class [[BR]]
- Moved more light uniform data to ShaderBuffers [[BR]]
- Double buffered grass rendering [[BR]]
- Added a better attribute interface to GenericVertexData [[BR]]
- Fixed screenshot capture [[BR]]
- Fixed texture double-bind checks [[BR]]

268 Diff Diff IonutCava picture IonutCava Wed 04 Jun, 2014 10:20:27 +0000

[IonutCava] [[BR]]
- Terrain and vegetation updates: [[BR]]
— Use standard phong lighting model [[BR]]
— Separate grass patches per chunk [[BR]]
— Reduce number of required texture bind points for terrain by adding both textures and normal maps in a single texture array [[BR]]
— Draw terrain with 2 drawcalls (using glMultiDrawElements twice, once for LoD == 0 and once for LoD > 0) [[BR]]
[[BR]]
- Buffer management updates: [[BR]]
— Unified buffer binding system [[BR]]
— Made Uniform buffer objects visible to all classes and moved lightUBO to LightManager, matricesUBO to GFXDevice etc [[BR]]
— Added initial support for Shader Buffer Objects [[BR]]
— Moved viewport management to GFXDevice class [[BR]]
[[BR]]
- Rendering improvements: [[BR]]
— Added Hi-Z occlusion culling to instanceCull shader (using Hi-Z depth buffer constructed in GFXDevice class) [[BR]]
— Resolved issues with shadow maps overriding texture bind locations [[[BR]]
— Improved shader and shader program loading [[BR]]
— Improved material transparency support [[BR]]
— Added buffer lock manager class from “Approaching Zero Driver Overhead in OpenGL (Presented by NVIDIA)” speech at GDC14 [[BR]]

264 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]]