Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 911 vs 912 for /trunk/assets/shaders/GLSL/material.glsl

Diff revisions: vs.
  @@ -40,9 +40,15 @@
40 40
41 41 #include "velocityCalc.frag"
42 42
43 + #if defined(USE_WB_OIT)
44 + layout(location = 0) out vec4 _accum;
45 + layout(location = 1) out float _revealage;
46 + layout(location = 2) out vec4 _modulate;
47 + #else
43 48 layout(location = 0) out vec4 _colourOut;
44 49 layout(location = 1) out vec2 _normalOut;
45 50 layout(location = 2) out vec2 _velocityOut;
51 + #endif
46 52
47 53 //subroutine vec4 MappingRoutineType();
48 54
  @@ -93,15 +99,57 @@
93 99 #endif
94 100 }
95 101
102 +
103 + #if defined(USE_WB_OIT)
104 + // Shameless copy-paste from http://casual-effects.blogspot.co.uk/2015/03/colored-blended-order-independent.html
105 + void writePixel(vec4 premultipliedReflect, vec3 transmit, float csZ, inout vec4 accum, inout float revealage) {
106 + /* NEW: Perform this operation before modifying the coverage to account for transmission. */
107 + _modulate.rgb = premultipliedReflect.a * (vec3(1.0) - transmit);
108 +
109 + /* Modulate the net coverage for composition by the transmission. This does not affect the color channels of the
110 + transparent surface because the caller's BSDF model should have already taken into account if transmission modulates
111 + reflection. See
112 +
113 + McGuire and Enderton, Colored Stochastic Shadow Maps, ACM I3D, February 2011
114 + http://graphics.cs.williams.edu/papers/CSSM/
115 +
116 + for a full explanation and derivation.*/
117 + premultipliedReflect.a *= 1.0 - (transmit.r + transmit.g + transmit.b) * (1.0 / 3.0);
118 +
119 + // Intermediate terms to be cubed
120 + float tmp = (premultipliedReflect.a * 8.0 + 0.01) * (-gl_FragCoord.z * 0.95 + 1.0);
121 +
122 + /* If a lot of the scene is close to the far plane, then gl_FragCoord.z does not
123 + provide enough discrimination. Add this term to compensate:
124 +
125 + tmp /= sqrt(abs(csZ)); */
126 +
127 + float w = clamp(tmp * tmp * tmp * 1e3, 1e-2, 3e2);
128 + _accum = premultipliedReflect * w;
129 + _revealage = premultipliedReflect.a;
130 + }
131 + #endif
132 +
96 133 void main (void){
97 - _colourOut = getFinalPixelColour();
98 - _normalOut = packNormal(getProcessedNormal());
99 - _velocityOut = velocityCalc(dvd_InvProjectionMatrix, getScreenPositionNormalised());
134 + vec4 colourOut = vec4(0.0);
100 135
101 136 #if defined(_DEBUG)
102 137 if (dvd_NormalsOnly) {
103 - _colourOut.rgb = getProcessedNormal();
138 + colourOut.rgb = getProcessedNormal();
139 + } else {
140 + colourOut = getFinalPixelColour();
104 141 }
142 + #else
143 + colourOut = getFinalPixelColour();
105 144 #endif
106 145
107 - }
146 + vec2 screenPositionNormalised = getScreenPositionNormalised();
147 + #if defined(USE_WB_OIT)
148 + float linearDepth = ToLinearDepth(getDepthValue(screenPositionNormalised));
149 + writePixel(colourOut, vec3(1.0), linearDepth, _accum, _revealage);
150 + #else
151 + _colourOut = colourOut;
152 + _normalOut = packNormal(getProcessedNormal());
153 + _velocityOut = velocityCalc(dvd_InvProjectionMatrix, screenPositionNormalised);
154 + #endif
155 + }