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

#include "utility.frag"
#include "lightInput.cmn"
#include "lightData.frag"
#include "materialData.frag"
#include "shadowMapping.frag"
#include "phong_lighting.frag"

vec3 processedNormal = vec3(0.0, 0.0, 1.0);

//TEMP PBR
/// Smith GGX Visibility
///     nDotL: dot-prod of surface normal and light direction
///     nDotV: dot-prod of surface normal and view direction
///     roughness: surface roughness
float SmithGGXVisibility(in float nDotL, in float nDotV, in float roughness)
{
    float rough2 = roughness * roughness;
    float gSmithV = nDotV + sqrt(nDotV * (nDotV - nDotV * rough2) + rough2);
    float gSmithL = nDotL + sqrt(nDotL * (nDotL - nDotL * rough2) + rough2);
    return 1.0 / (gSmithV * gSmithL);
}


float SchlickG1(in float factor, in float rough2)
{
    return 1.0 / (factor * (1.0 - rough2) + rough2);
}

/// Schlick approximation of Smith GGX
///     nDotL: dot product of surface normal and light direction
///     nDotV: dot product of surface normal and view direction
///     roughness: surface roughness
float SchlickVisibility(float nDotL, float nDotV, float roughness)
{
    const float rough2 = roughness * roughness;
    return (SchlickG1(nDotL, rough2) * SchlickG1(nDotV, rough2)) * 0.25;
}

void PBR(in int lightIndex, in vec3 normalWV, inout vec4 colourInOut) {
    vec3 lightDirection = getLightDirection(lightIndex);
    vec3 lightDir = normalize(lightDirection);
    float roughness = dvd_MatShininess;


    colourInOut = vec4(1.0);
}

//TEMP PBR
void getBRDFFactors(in int lightIndex,
                    in vec3 normalWV,
                    inout vec3 colourInOut)
{
#if defined(USE_SHADING_PHONG) || defined (USE_SHADING_BLINN_PHONG)
    Phong(lightIndex, normalWV, colourInOut);
#elif defined(USE_SHADING_TOON)
#elif defined(USE_SHADING_OREN_NAYAR)
#else //if defined(USE_SHADING_COOK_TORRANCE)
    PBR(lightIndex, normalWV, colourInOut);
#endif
}

uint GetNumLightsInThisTile(uint nTileIndex)
{
    uint nNumLightsInThisTile = 0;
    uint nIndex = uint(dvd_otherData.w) * nTileIndex;
    uint nNextLightIndex = perTileLightIndices[nIndex];
    while (nNextLightIndex != LIGHT_INDEX_BUFFER_SENTINEL)
    {
        nIndex++;
        nNextLightIndex = perTileLightIndices[nIndex];
        nNumLightsInThisTile++;
    }

    return nNumLightsInThisTile;
}

vec4 getPixelColour(const in vec2 texCoord, in vec3 normalWV) {
    //Occlusion culling visibility debug code
#if defined(USE_HIZ_CULLING) && defined(DEBUG_HIZ_CULLING)
    if (dvd_customData > 2.0) {
        return vec4(1.0, 0.0, 0.0, 1.0);
    }
#endif

    parseMaterial();

    processedNormal = normalWV;

#if defined(HAS_TRANSPARENCY)
#   if defined(USE_OPACITY_DIFFUSE)
        float alpha = dvd_MatDiffuse.a;
#   endif
#   if defined(USE_OPACITY_MAP)
        vec4 opacityMap = texture(texOpacityMap, texCoord);
        float alpha = max(min(opacityMap.r, opacityMap.g), min(opacityMap.b, opacityMap.a));
#   endif
#   else
        const float alpha = 1.0;
#   endif

#   if defined (USE_DOUBLE_SIDED)
        processedNormal = gl_FrontFacing ? processedNormal : -processedNormal;
#   endif

#   if defined(USE_SHADING_FLAT)
        vec3 colour = dvd_MatDiffuse.rgb;
#   else
    vec3 lightColour = vec3(0.0);
    // Apply all lighting contributions
    uint lightIdx;
    // Directional lights
    for (lightIdx = 0; lightIdx < dvd_lightCountPerType[0]; ++lightIdx) {
        getBRDFFactors(int(lightIdx), processedNormal, lightColour);
    }

    uint offset = dvd_lightCountPerType[0];
    // Point lights
    uint nIndex = uint(dvd_otherData.w) * GetTileIndex(gl_FragCoord.xy);
    uint nNextLightIndex = perTileLightIndices[nIndex];
    while (nNextLightIndex != LIGHT_INDEX_BUFFER_SENTINEL)
    {
        uint nLightIndex = nNextLightIndex;
        nNextLightIndex = perTileLightIndices[++nIndex];

        getBRDFFactors(int(nLightIndex - 1 + offset), processedNormal, lightColour);
    }

    offset = dvd_lightCountPerType[1];
    // Spot lights
    // Moves past the first sentinel to get to the spot lights.
    nNextLightIndex = perTileLightIndices[++nIndex];
    while (nNextLightIndex != LIGHT_INDEX_BUFFER_SENTINEL)
    {
        uint nLightIndex = nNextLightIndex;
        nNextLightIndex = perTileLightIndices[++nIndex];
        getBRDFFactors(int(nLightIndex - 1 + offset), processedNormal, lightColour);
    }
    
    vec3 colour = mix(dvd_MatEmissive, lightColour, DIST_TO_ZERO(length(lightColour)));
#endif

    float reflectance = saturate(dvd_MatShininess / 255.0);
    if (reflectance > 0.75 && dvd_lodLevel < 1) {
        vec3 reflectDirection = reflect(normalize(VAR._vertexWV.xyz), processedNormal);
        reflectDirection = vec3(inverse(dvd_ViewMatrix) * vec4(reflectDirection, 0.0));
        colour = mix(texture(texEnvironmentCube, vec4(reflectDirection, 0.0)).rgb,
                    colour,
                    vec3(reflectance));

    }

    colour *= mix(mix(1.0, 2.0, dvd_isHighlighted), 3.0, dvd_isSelected);
    // Apply shadowing
    colour *= mix(1.0, shadow_loop(), dvd_shadowMapping);

#if defined(_DEBUG) && defined(DEBUG_SHADOWMAPPING)
    if (dvd_showDebugInfo == 1) {
        switch (_shadowTempInt){
#if defined(DEBUG_SHADOWSPLITS)
            case -1: colour = vec3(1.0); break;
            case  0: colour = vec3(1.0, 0.0, 0.0); break;
            case  1: colour = vec3(0.0, 1.0, 0.0); break;
            case  2: colour = vec3(0.0, 0.0, 1.0); break;
            case  3: colour = vec3(1.0, 0.25, 0.40); break;
#else
            case -1: colour = vec3(1.0); break;
            case  0: colour.r += 0.15; break;
            case  1: colour.g += 0.25; break;
            case  2: colour.b += 0.40; break;
            case  3: colour += vec3(0.15, 0.25, 0.40); break;
#endif
        };
    }
#endif
    return vec4(colour, alpha);
}

#endif

Commits for Divide-Framework/trunk/assets/shaders/GLSL/fragmentAtoms/BRDF.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

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

645 Diff Diff IonutCava picture IonutCava Mon 15 Feb, 2016 16:44:16 +0000

[IonutCava]
- Added frustum planes to the GFXDevice UBO
- Occlusion culling updates

644 Diff Diff IonutCava picture IonutCava Sun 14 Feb, 2016 15:04:17 +0000

[IonutCava]
- Fix ZPrePass on AMD hardware:
— Use invariant gl_Position;
— USe early fragment test for non-alpha blended entities
— Add a toggle to disable/enable ZPrePass at compile time
- Add Occlusion culling debugging feature togglable at compile time
- Initial code for high prio materials (used to always calc reflections, compute shaders immediately, etc)

640 Diff Diff IonutCava picture IonutCava Tue 09 Feb, 2016 17:18:17 +0000

[IonutCava]
- More Octree updates
- Fixed bounding box collision check
- Added initial intersection code
- Added on-demand flush call for fence locking system

633 Diff Diff IonutCava picture IonutCava Wed 27 Jan, 2016 16:54:12 +0000

[IonutCava]
- Improve load times by using ShaderCache files to avoid re-parsing atoms multiple times
- Z_PRE_PASS and multi-threaded asset loading is disabled automatically for AMD only (until driver issues are resolved)

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

628 Diff Diff IonutCava picture IonutCava Wed 20 Jan, 2016 17:17:53 +0000

[IonutCava]
- Reworked GenericVertexData ring-buffering system and changed vertex attributes to the vertex format system
— Might be buggy
- Disabled bump-mapping for low-LoD level entities
- Removed a forgotten test line in BRDF shader that prevented lighting calculations to occur properly (an early return)
- Updated auto-reflection system for high shininess materials
- Converted a lot of ‘to_xyz’ calls to ‘to_const_xyz’ calls where appropriate to reduce runtime cost (‘to_const_xyz’ is evaluated at compile time)

626 Diff Diff IonutCava picture IonutCava Tue 19 Jan, 2016 17:12:16 +0000

[IonutCava]
- All visual entities have a reflection texture by default and it becomes visible above a certain shininess threshold
- More profile-guided optimizations

621 IonutCava picture IonutCava Tue 12 Jan, 2016 16:39:50 +0000

[IonutCava]
- Terrain rendering updates
- Framebuffer optimizations