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
#ifndef _SHADOW_DIRECTIONAL_FRAG_
#define _SHADOW_DIRECTIONAL_FRAG_

float linstep(float a, float b, float v) {
    return clamp((v - a) / (b - a), 0.0, 1.0);
}

// Reduces VSM light bleeding (remove the [0, amount] tail and linearly rescale (amount, 1])
float reduceLightBleeding(float pMax, float amount) {
    return linstep(amount, 1.0f, pMax);
}

float chebyshevUpperBound(vec2 moments, float compare, float minVariance) {
    float p = step(compare, moments.x);
    float variance = max(moments.y - (moments.x * moments.x), minVariance);
    
    float d = (compare - moments.x);

    float pMax = reduceLightBleeding(variance / (variance + d*d), dvd_shadowingSettings.x);
    
    return min(max(p, pMax), 1.0);
}

bool inRange(const in float value){
    return value >= 0.0 && value <= 1.0;
}

float applyShadowDirectional(int shadowIndex, int splitCount) {

    Shadow currentShadowSource  = dvd_ShadowSource[shadowIndex];
#   if !defined(_DEBUG)
      int _shadowTempInt = -2;
#   endif
    float zDist = gl_FragCoord.z;
    
    // find the appropriate depth map to look up in based on the depth of this fragment
    _shadowTempInt = 0;
    for (int i = 0; i < splitCount; ++i) {
        if (zDist > currentShadowSource._floatValues[i].x)      {
            _shadowTempInt = i + 1;
        }
    }
    
    // GLOBAL
    const int SplitPowLookup[8] = { 0, 1, 1, 2, 2, 2, 2, 3 };
    // Ensure that every fragment in the quad choses the same split so that derivatives
    // will be meaningful for proper texture filtering and LOD selection.
    /*int SplitPow = 1 << _shadowTempInt;
    int SplitX = int(abs(dFdx(SplitPow)));
    int SplitY = int(abs(dFdy(SplitPow)));
    int SplitXY = int(abs(dFdx(SplitY)));
    int SplitMax = max(SplitXY, max(SplitX, SplitY));
    _shadowTempInt = SplitMax > 0 ? SplitPowLookup[SplitMax - 1] : _shadowTempInt;*/

    if (_shadowTempInt < 0 || _shadowTempInt > splitCount) {
        return 1.0;
    }

    vec4 shadow_coord = currentShadowSource._lightVP[_shadowTempInt] * VAR._vertexW;
    
    if (inRange(shadow_coord.z) && inRange(shadow_coord.x) && inRange(shadow_coord.y)){
        shadow_coord.w = shadow_coord.z;
        shadow_coord.z = _shadowTempInt + currentShadowSource._arrayOffset.x;

        vec2 moments = texture(texDepthMapFromLightArray, shadow_coord.xyz).rg;
       
        //float shadowBias = DEPTH_EXP_WARP * exp(DEPTH_EXP_WARP * dvd_shadowingSettings.y);
        //float shadowWarpedz1 = exp(shadow_coord.w * DEPTH_EXP_WARP);
        //return mix(chebyshevUpperBound(moments, shadowWarpedz1, dvd_shadowingSettings.y), 
        //             1.0, 
        //             clamp(((gl_FragCoord.z + dvd_shadowingSettings.z) - dvd_shadowingSettings.w) / dvd_shadowingSettings.z, 0.0, 1.0));
        return chebyshevUpperBound(moments, shadow_coord.w, dvd_shadowingSettings.y);
    }

    return 1.0;
}

#endif //_SHADOW_DIRECTIONAL_FRAG_

Commits for Divide-Framework/trunk/assets/shaders/GLSL/fragmentAtoms/shadow_directional.frag

Diff revisions: vs.
Revision Author Commited Message
727 Diff Diff IonutCava picture IonutCava Tue 14 Jun, 2016 16:01:38 +0000

[IonutCava]
- Remove node and cmd buffers from GFXDevice and add them as a new BufferData struct to RenderPass class.
— Each render pass holds its own buffers
- Improvements / fixes to the CSM code
- Added a global toggle to enable/disable custom memory allocators

716 Diff Diff IonutCava picture IonutCava Tue 31 May, 2016 16:08:29 +0000

[IonutCava]
- Multithreaded scene load/unload fixes:
— Added postLoadMainThread call for scenes for thread sensitive loading steps
— GUI element adding is a thread sensitive loading step (a fast one) because CEGUI doesn’t handle threading
- Added REALTIME_WITH_CALLBACK task priority for tasks that need an immediate callback when they complete instead of using the flushCallbackQueue system.
- Some work on shadow mapping for getting it to work again
- ShaderPrograms that fail to load can cause a LockManager infinite wait. Delete the lockManager if the shader didn’t load to avoid waiting on commands that never get called.

609 Diff Diff IonutCava picture IonutCava Fri 18 Dec, 2015 13:05:06 +0000

[IonutCava]
- Postprocessing improvements
- Shadowmapping warning fix (non-depth texture bound to depth sampler)

587 Diff Diff IonutCava picture IonutCava Fri 27 Nov, 2015 17:00:25 +0000

[IonutCava]
- Finished multi-light rendering:
— Proper position/distance transform (homogeneous trans for positions / non-homogeneous trans for directions)
-— Point lights with range based attenuation
-— Spot lights with inner and outer cones for smooth falloff
-— Directional lights same as before
- Added a basic Flashlight system: spot light at the camera’s position facing forward (toggled with L key)
- WarScene updated:
— 16 point lights moving around the scene with random colours

576 Diff Diff IonutCava picture IonutCava Fri 20 Nov, 2015 11:54:22 +0000

[IonutCava]
- C++ based Interface block generation for GLSL

573 Diff Diff IonutCava picture IonutCava Wed 18 Nov, 2015 21:27:33 +0000

[IonutCava]
- AMD specific corrections for the previous commit
- Removed RenderingComponent’s impostorBox as it wasn’t used

572 Diff Diff IonutCava picture IonutCava Wed 18 Nov, 2015 17:15:43 +0000

[Ionut]
- Attempt to pack all shadowmaps in Shadowmap arrays
- Cleanup lighting and material info
- Fix light impostor rendering

559 Diff Diff IonutCava picture IonutCava Tue 10 Nov, 2015 16:34:26 +0000

[IonutCava]
- Uniform cleanup:
— Grab most shader uniform calls and batch the data in a scene global shader buffer
- Fix a crash related to environment maps:
— Material instance does not own the REFLECTION texture (unlike the other texture types). Increase the incoming texture’s reference count instead

551 Diff Diff IonutCava picture IonutCava Thu 05 Nov, 2015 17:08:03 +0000

[IonutCava]
- Streamline RenderPass/RenderBin/RenderPassCuller logic:
— Separate culling from updating nodes
— Improve sorting and batching
- Cleanups and sanity checks
- Replace some std::bind calls with lambdas

548 IonutCava picture IonutCava Wed 04 Nov, 2015 17:23:15 +0000

[IonutCava]
- More work on improving cascaded shadow maps