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
layout(binding = TEXTURE_DEPTH_MAP) uniform sampler2D HiZBuffer;

vec4 BoundingBox[8];

int PassThrough(const in vec3 position, const in vec3 extents) {
    return 1;
}

int InstanceCloudReduction(const in vec3 position, const in vec3 extents) {
    const float frustumBias = 0.5;

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

    // check how the bounding box resides regarding to the view frustum 
    uint outOfBound[6] = uint[](0, 0, 0, 0, 0, 0);
    
    for (int i = 0; i<8; i++)
    {
        if (BoundingBox[i].x >  BoundingBox[i].w) outOfBound[0]++;
        if (BoundingBox[i].x < -BoundingBox[i].w) outOfBound[1]++;
        if (BoundingBox[i].y >  BoundingBox[i].w) outOfBound[2]++;
        if (BoundingBox[i].y < -BoundingBox[i].w) outOfBound[3]++;
        if (BoundingBox[i].z >  BoundingBox[i].w) outOfBound[4]++;
        if (BoundingBox[i].z < -BoundingBox[i].w) outOfBound[5]++;
    }

    int inFrustum = 1;

    for (int i = 0; i<6; i++)
        if (outOfBound[i] == 8) inFrustum = 0;

    return inFrustum;
}

//Return: 0 = culled, 1 = visible
int zBufferCull(const in vec3 position, const in vec3 extents) {
    /* first do instance cloud reduction */
    if (InstanceCloudReduction(position, extents) == 0) {
        return 0;
    }

    /* perform perspective division for the bounding box */
    for (uint i = 0; i < 8; i++) {
        BoundingBox[i].xyz /= BoundingBox[i].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))) / 2.0 + 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))) / 2.0 + 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))) / 2.0 + 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))) / 2.0 + 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 */
    float ViewSizeX = (BoundingRect[1].x - BoundingRect[0].x) * dvd_ViewPort.z;
    float ViewSizeY = (BoundingRect[1].y - BoundingRect[0].y) * dvd_ViewPort.w;

    /* now we calculate the texture LOD used for lookup in the depth buffer texture */
    float LOD = ceil(log2(max(ViewSizeX, ViewSizeY) / 2.0));

    /* finally fetch the depth texture using explicit LOD lookups */
    vec4 Samples;
    Samples.x = textureLod(HiZBuffer, vec2(BoundingRect[0].x, BoundingRect[0].y), LOD).r;
    Samples.y = textureLod(HiZBuffer, vec2(BoundingRect[0].x, BoundingRect[1].y), LOD).r;
    Samples.z = textureLod(HiZBuffer, vec2(BoundingRect[1].x, BoundingRect[1].y), LOD).r;
    Samples.w = textureLod(HiZBuffer, vec2(BoundingRect[1].x, BoundingRect[0].y), LOD).r;
    float MaxDepth = max(max(Samples.x, Samples.y), max(Samples.z, Samples.w));

    /* if the instance depth is bigger than the depth in the texture discard the instance */
    return (InstanceDepth > MaxDepth) ? 0 : 1;

   
}

Commits for Divide-Framework/trunk/assets/shaders/GLSL/common/HiZCullingAlgorithm.cmn

Diff revisions: vs.
Revision Author Commited Message
631 Diff Diff IonutCava picture IonutCava Sun 24 Jan, 2016 20:28:21 +0000

[IonutCava]
- Fix and optimize particle rendering system
- Temporarily disable Z_PRE_PASS system for testing
- Improve thread pool destruction system a bit
- Fix texture loading when used as fb attachment
- Forward+ renderer now takes the entire light buffer (no need to split up by light type)
- Start work on occlusion culling fixes:
— ToDo: Take into account batching system
— Fix gl_DrawIDARB usage

630 Diff Diff IonutCava picture IonutCava Fri 22 Jan, 2016 17:15:44 +0000

[IonutCava]
- Improve reflection generation system
— Still buggy
- Investigate occlusion culling issue
— Still buggy
- Improve threadpool idle time using main app time and conservative thread sleep calls

617 Diff Diff IonutCava picture IonutCava Tue 05 Jan, 2016 16:47:21 +0000

[IonutCava]
- Depth writing is now a rendering API level toggle instead of a renderstateblock option
- Z-Pre-pass fixes and improvements
- Moved normal render target to the display stage from the pre-pass stage
— Normals are only used in post-processing. This improves pre-pass performance

615 Diff Diff IonutCava picture IonutCava Tue 22 Dec, 2015 16:30:42 +0000

[IonutCava]
not working properly
- Move HiZ buffer to separate render target
- Implement basic, per-scene, auto Save/Load system (works with camera position only for now)
- Fix a few wrong calls in glFramebuffer and glVertexArray
- Re-work skybox rendering

535 IonutCava picture IonutCava Tue 27 Oct, 2015 17:03:35 +0000

[IonutCava]
- Improve occlusion culling
- Improve draw command management