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

#include "vbInputData.vert"
#include "lightingDefaults.vert"

#if defined(ADD_FOLIAGE)
#include "foliage.vert"
#endif

void main(void){

    computeData();

#if defined(ADD_FOLIAGE) && defined(IS_TREE)
    computeFoliageMovementTree(dvd_Vertex);
#endif
    
    computeLightVectors();

    //Compute the final vert position
    gl_Position = dvd_ViewProjectionMatrix * VAR._vertexW;

}

-- Fragment

#if defined(USE_OPACITY_DIFFUSE) || defined(USE_OPACITY_MAP) || defined(USE_OPACITY_DIFFUSE_MAP)
#   define HAS_TRANSPARENCY
#endif

#if !defined(HAS_TRANSPARENCY)
layout(early_fragment_tests) in;
#endif

#include "BRDF.frag"

#if defined(COMPUTE_TBN)
    #include "bumpMapping.frag"
#endif

#include "velocityCalc.frag"

#if defined(USE_WB_OIT)
layout(location = 0) out vec4  _accum;
layout(location = 1) out float _revealage;
layout(location = 2) out vec4  _modulate;
#else
layout(location = 0) out vec4 _colourOut;
layout(location = 1) out vec2 _normalOut;
layout(location = 2) out vec2 _velocityOut;
#endif

//subroutine vec4 MappingRoutineType();

//layout(location = 0) subroutine uniform MappingRoutineType MappingRoutine;

//subroutine(MappingRoutineType)
vec4 mappingFlat(){
    return getPixelColour(VAR._texCoord, VAR._normalWV);
}

#if defined(COMPUTE_TBN)
//subroutine(MappingRoutineType)
vec4 mappingNormal(){
    vec3 bump = getBump(VAR._texCoord);
    return mix(getPixelColour(getTBNMatrix() * bump),
               mappingFlat(),
               vec4(dvd_lodLevel > 1));
}

//subroutine(MappingRoutineType)
vec4 mappingRelief(){
    return mix(ReliefMapping(VAR._texCoord),
               mappingFlat(),
               vec4(dvd_lodLevel > 1));
}

//subroutine(MappingRoutineType)
vec4 mappingParallax(){
    return mix(ParallaxMapping(VAR._texCoord),
               mappingFlat(),
               vec4(dvd_lodLevel > 1));
}
#endif

vec4 getFinalPixelColour() {
//return MappingRoutine();
#if defined(COMPUTE_TBN)
    bumpInit();
#    if defined(USE_PARALLAX_MAPPING)
    return mappingParallax();
#    elif defined(USE_RELIEF_MAPPING)
    return mappingRelief();
#    else
    return mappingNormal();
#    endif
#else
   return mappingFlat();
#endif
}


#if defined(USE_WB_OIT)
// Shameless copy-paste from http://casual-effects.blogspot.co.uk/2015/03/colored-blended-order-independent.html
void writePixel(vec4 premultipliedReflect, vec3 transmit, float csZ, inout vec4 accum, inout float revealage) {
    /* NEW: Perform this operation before modifying the coverage to account for transmission. */
    _modulate.rgb = premultipliedReflect.a * (vec3(1.0) - transmit);

    /* Modulate the net coverage for composition by the transmission. This does not affect the color channels of the
    transparent surface because the caller's BSDF model should have already taken into account if transmission modulates
    reflection. See

    McGuire and Enderton, Colored Stochastic Shadow Maps, ACM I3D, February 2011
    http://graphics.cs.williams.edu/papers/CSSM/

    for a full explanation and derivation.*/
    premultipliedReflect.a *= 1.0 - (transmit.r + transmit.g + transmit.b) * (1.0 / 3.0);

    // Intermediate terms to be cubed
    float tmp = (premultipliedReflect.a * 8.0 + 0.01) *  (-gl_FragCoord.z * 0.95 + 1.0);

    /* If a lot of the scene is close to the far plane, then gl_FragCoord.z does not
    provide enough discrimination. Add this term to compensate:

    tmp /= sqrt(abs(csZ)); */

    float w = clamp(tmp * tmp * tmp * 1e3, 1e-2, 3e2);
    _accum = premultipliedReflect * w;
    _revealage = premultipliedReflect.a;
}
#endif

void main (void){
    vec4 colourOut = vec4(0.0);

#if defined(_DEBUG)
    if (dvd_NormalsOnly) {
        colourOut.rgb = getProcessedNormal();
    } else {
        colourOut = getFinalPixelColour();
    }
#else
    colourOut = getFinalPixelColour();
#endif

vec2 screenPositionNormalised = getScreenPositionNormalised();
#if defined(USE_WB_OIT)
    float linearDepth = ToLinearDepth(getDepthValue(screenPositionNormalised));
    writePixel(colourOut, vec3(1.0), linearDepth, _accum, _revealage);
#else
    _colourOut = colourOut;
    _normalOut = packNormal(getProcessedNormal());
    _velocityOut = velocityCalc(dvd_InvProjectionMatrix, screenPositionNormalised);
#endif
}

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

Diff revisions: vs.
Revision Author Commited Message
912 Diff Diff IonutCava picture IonutCava Sun 02 Jul, 2017 23:42:39 +0000

[Ionut]
- Add experimental Weighted Blended Order Independed Transparency (ref: http://casual-effects.blogspot.co.uk/2015/03/implemented-weighted-blended-order.html)
— Add per drawbuffer blend
— All translucent renderbin items go via the new OIT 2-step rendering: accumulation and composition
- Make sure we have proper blend enabled for text rendering
- Add a primitive form of PushConstants (unused yet. Emulated via Uniform calls)
- Fix bug with XMLParser not using case insensitive key lookups

899 Diff Diff IonutCava picture IonutCava Fri 23 Jun, 2017 15:37:44 +0000

[IonutCava]
- Move sRGB conversion and fog calculation to post-processing stages (fog in postProcessing using the depth buffer and sRGB in the presentToScreen step)
- Split the bloom.glsl file into multiple shaders: bloom, tonemap and luminanceCalc for ease of use purposes
- Rework RenderBin sorting: sort translucent/transparent nodes by material in depth passes
- Sort order is no longer part of RenderBin for better control

889 Diff Diff IonutCava picture IonutCava Tue 04 Apr, 2017 16:01:34 +0000

[IonutCava]
- Rework uniform passing/caching to better work with shader recompilation
- Cleanup shaders a bit for better performance

884 Diff Diff IonutCava picture IonutCava Mon 27 Mar, 2017 15:32:26 +0000

[Ionut]
- More terrain work

811 Diff Diff IonutCava picture IonutCava Wed 11 Jan, 2017 17:26:49 +0000

[IonutCava]
- Fix some threadpool cleanup bugs
- Fix terrain rendering (except underwater caustics)
- Fix terrain loading
- Fix terrain unloading

809 Diff Diff IonutCava picture IonutCava Tue 10 Jan, 2017 17:16:26 +0000

[IonutCava]
- Move velocity calc to the normal colour pass.
- Optimise glFramebuffer and cleanup RTAttachment class

806 Diff Diff IonutCava picture IonutCava Sun 08 Jan, 2017 22:00:48 +0000

[IonutCava]
- Finish implementing per-fragment velocity computation using a compute shader
— Further tuning still needed
- Add VS2017 build targets

770 Diff Diff IonutCava picture IonutCava Tue 20 Sep, 2016 16:12:27 +0000

[IonutCava]
- Prepare velocity map calculation (later used for temporal AA and motion blur):
— Add a previous depth buffer render target that blits the main depth buffer at the end of the frame
— Add a new render target to the screen FBO: velocity map
- Store normals as RG instead of RGB and pack/unpack in shaders. (compute >>>> bandwith)
- Rename Forward+ renderer to something more descriptive

(Requires deletion of all parsed & cached data)

756 Diff Diff IonutCava picture IonutCava Fri 29 Jul, 2016 16:09:29 +0000

[IonutCava]
- Cleaned up material shader:
— Add explicit functions for material colour properties
— Separate Phong from PBR
— Remove texture count variable and use TEX_OPERATION_NONE for single texture
- Added a Shader compute queue that all materials share. This allows better frame time allocation for shader compilation
- Attempt to fix Task and TaskPool race conditions

753 IonutCava picture IonutCava Thu 28 Jul, 2016 14:26:48 +0000

[IonutCava]
- Very small cleanup and renaming changes
- Updated PhysX build as well