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
#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;

void getBRDFFactors(in int lightIndex,
                    in vec3 normalWV,
                    inout vec3 colorInOut)
{
#if defined(USE_SHADING_PHONG) || defined (USE_SHADING_BLINN_PHONG)
    Phong(lightIndex, normalWV, colorInOut);
#elif defined(USE_SHADING_TOON)
#elif defined(USE_SHADING_OREN_NAYAR)
#else //if defined(USE_SHADING_COOK_TORRANCE)
#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 getPixelColor(const in vec2 texCoord, in vec3 normalWV) {
    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 color = dvd_MatDiffuse.rgb;
#   else
    vec3 lightColor = vec3(0.0);
    // Apply all lighting contributions
    uint lightIdx;
    // Directional lights
    for (lightIdx = 0; lightIdx < dvd_lightCountPerType[0]; ++lightIdx) {
        getBRDFFactors(int(lightIdx), processedNormal, lightColor);
    }

    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, lightColor);
    }

    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, lightColor);
    }
    
    vec3 color = mix(dvd_MatEmissive, lightColor, DIST_TO_ZERO(length(lightColor)));
#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));
        color = mix(texture(texEnvironmentCube, vec4(reflectDirection, 0.0)).rgb,
                    color,
                    vec3(reflectance));

    }

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

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

#endif

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

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

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 Diff Diff IonutCava picture IonutCava Tue 12 Jan, 2016 16:39:50 +0000

[IonutCava]
- Terrain rendering updates
- Framebuffer optimizations

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

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)

601 Diff Diff IonutCava picture IonutCava Wed 09 Dec, 2015 17:12:38 +0000

[IonutCava]
- Shadow mapping system improvements:
— Point and spot light support
— Variable number of debug preview planes
- Light impostor rendering fix and update:
— Displays coloured icons for point and spot lights
- Camera system improvement:
— Camera manager is the only class allowed to instantiate new cameras
- Initial dual paraboloid rendering code
- Remove discard statements from shader code (should use blending if visual artefacts are encountered)

594 Diff Diff IonutCava picture IonutCava Thu 03 Dec, 2015 23:36:32 +0000

[IonutCava]
- Reverted some test code from the previous commit

593 Diff Diff IonutCava picture IonutCava Thu 03 Dec, 2015 17:17:30 +0000

[IonutCava]
- Culling, light rendering, physics transforms and impostor updates

591 IonutCava picture IonutCava Wed 02 Dec, 2015 17:17:23 +0000

[IonutCava]
- More work on the ForwardPlus renderer
- Singleton cleanup
- First steps for reducing scope of GFXDevice class