Last active
December 9, 2019 23:32
-
-
Save cdata/784a5b3ac632de4aaff2149d6a6b4fff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
THREE.WebGLShader: gl.getShaderInfoLog() fragment | |
Compile failed. | |
WARNING: 0:254: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results | |
WARNING: 0:256: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results | |
WARNING: 0:258: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results | |
WARNING: 0:260: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results | |
WARNING: 4 compilation warnings. | |
�1: #define n 20 | |
2: | |
3: precision mediump float; | |
4: precision mediump int; | |
5: varying vec3 vOutputDirection; | |
6: uniform sampler2D envMap; | |
7: uniform bool copyEquirectangular; | |
8: uniform vec2 texelSize; | |
9: uniform int samples; | |
10: uniform float weights[n]; | |
11: uniform bool latitudinal; | |
12: uniform float dTheta; | |
13: uniform float mipInt; | |
14: #define RECIPROCAL_PI 0.31830988618 | |
15: #define RECIPROCAL_PI2 0.15915494 | |
16: | |
17: uniform int inputEncoding; | |
18: uniform int outputEncoding; | |
19: | |
20: // For a discussion of what this is, please read this: http://lousodrome.net/blog/light/2013/05/26/gamma-correct-and-hdr-rendering-in-a-32-bits-buffer/ | |
21: | |
22: vec4 LinearToLinear( in vec4 value ) { | |
23: return value; | |
24: } | |
25: | |
26: vec4 GammaToLinear( in vec4 value, in float gammaFactor ) { | |
27: return vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a ); | |
28: } | |
29: | |
30: vec4 LinearToGamma( in vec4 value, in float gammaFactor ) { | |
31: return vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a ); | |
32: } | |
33: | |
34: vec4 sRGBToLinear( in vec4 value ) { | |
35: return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a ); | |
36: } | |
37: | |
38: vec4 LinearTosRGB( in vec4 value ) { | |
39: return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a ); | |
40: } | |
41: | |
42: vec4 RGBEToLinear( in vec4 value ) { | |
43: return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 ); | |
44: } | |
45: | |
46: vec4 LinearToRGBE( in vec4 value ) { | |
47: float maxComponent = max( max( value.r, value.g ), value.b ); | |
48: float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 ); | |
49: return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 ); | |
50: // return vec4( value.brg, ( 3.0 + 128.0 ) / 256.0 ); | |
51: } | |
52: | |
53: // reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html | |
54: vec4 RGBMToLinear( in vec4 value, in float maxRange ) { | |
55: return vec4( value.rgb * value.a * maxRange, 1.0 ); | |
56: } | |
57: | |
58: vec4 LinearToRGBM( in vec4 value, in float maxRange ) { | |
59: float maxRGB = max( value.r, max( value.g, value.b ) ); | |
60: float M = clamp( maxRGB / maxRange, 0.0, 1.0 ); | |
61: M = ceil( M * 255.0 ) / 255.0; | |
62: return vec4( value.rgb / ( M * maxRange ), M ); | |
63: } | |
64: | |
65: // reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html | |
66: vec4 RGBDToLinear( in vec4 value, in float maxRange ) { | |
67: return vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 ); | |
68: } | |
69: | |
70: vec4 LinearToRGBD( in vec4 value, in float maxRange ) { | |
71: float maxRGB = max( value.r, max( value.g, value.b ) ); | |
72: float D = max( maxRange / maxRGB, 1.0 ); | |
73: D = min( floor( D ) / 255.0, 1.0 ); | |
74: return vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D ); | |
75: } | |
76: | |
77: // LogLuv reference: http://graphicrants.blogspot.ca/2009/04/rgbm-color-encoding.html | |
78: | |
79: // M matrix, for encoding | |
80: const mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 ); | |
81: vec4 LinearToLogLuv( in vec4 value ) { | |
82: vec3 Xp_Y_XYZp = cLogLuvM * value.rgb; | |
83: Xp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) ); | |
84: vec4 vResult; | |
85: vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z; | |
86: float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0; | |
87: vResult.w = fract( Le ); | |
88: vResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0; | |
89: return vResult; | |
90: } | |
91: | |
92: // Inverse M matrix, for decoding | |
93: const mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 ); | |
94: vec4 LogLuvToLinear( in vec4 value ) { | |
95: float Le = value.z * 255.0 + value.w; | |
96: vec3 Xp_Y_XYZp; | |
97: Xp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 ); | |
98: Xp_Y_XYZp.z = Xp_Y_XYZp.y / value.y; | |
99: Xp_Y_XYZp.x = value.x * Xp_Y_XYZp.z; | |
100: vec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb; | |
101: return vec4( max( vRGB, 0.0 ), 1.0 ); | |
102: } | |
103: | |
104: vec4 inputTexelToLinear(vec4 value){ | |
105: if(inputEncoding == 0){ | |
106: return value; | |
107: }else if(inputEncoding == 1){ | |
108: return sRGBToLinear(value); | |
109: }else if(inputEncoding == 2){ | |
110: return RGBEToLinear(value); | |
111: }else if(inputEncoding == 3){ | |
112: return RGBMToLinear(value, 7.0); | |
113: }else if(inputEncoding == 4){ | |
114: return RGBMToLinear(value, 16.0); | |
115: }else if(inputEncoding == 5){ | |
116: return RGBDToLinear(value, 256.0); | |
117: }else{ | |
118: return GammaToLinear(value, 2.2); | |
119: } | |
120: } | |
121: vec4 linearToOutputTexel(vec4 value){ | |
122: if(outputEncoding == 0){ | |
123: return value; | |
124: }else if(outputEncoding == 1){ | |
125: return LinearTosRGB(value); | |
126: }else if(outputEncoding == 2){ | |
127: return LinearToRGBE(value); | |
128: }else if(outputEncoding == 3){ | |
129: return LinearToRGBM(value, 7.0); | |
130: }else if(outputEncoding == 4){ | |
131: return LinearToRGBM(value, 16.0); | |
132: }else if(outputEncoding == 5){ | |
133: return LinearToRGBD(value, 256.0); | |
134: }else{ | |
135: return LinearToGamma(value, 2.2); | |
136: } | |
137: } | |
138: | |
139: vec4 envMapTexelToLinear(vec4 color) { | |
140: return inputTexelToLinear(color); | |
141: } | |
142: | |
143: #define cubeUV_maxMipLevel 8.0 | |
144: #define cubeUV_minMipLevel 4.0 | |
145: #define cubeUV_maxTileSize 256.0 | |
146: #define cubeUV_minTileSize 16.0 | |
147: | |
148: float getFace(vec3 direction) { | |
149: vec3 absDirection = abs(direction); | |
150: float face = -1.0; | |
151: if (absDirection.x > absDirection.z) { | |
152: if (absDirection.x > absDirection.y) | |
153: face = direction.x > 0.0 ? 0.0 : 3.0; | |
154: else | |
155: face = direction.y > 0.0 ? 1.0 : 4.0; | |
156: } else { | |
157: if (absDirection.z > absDirection.y) | |
158: face = direction.z > 0.0 ? 2.0 : 5.0; | |
159: else | |
160: face = direction.y > 0.0 ? 1.0 : 4.0; | |
161: } | |
162: return face; | |
163: } | |
164: | |
165: | |
166: vec2 getUV(vec3 direction, float face) { | |
167: vec2 uv; | |
168: if (face == 0.0) { | |
169: uv = vec2(-direction.z, direction.y) / abs(direction.x); | |
170: } else if (face == 1.0) { | |
171: uv = vec2(direction.x, -direction.z) / abs(direction.y); | |
172: } else if (face == 2.0) { | |
173: uv = direction.xy / abs(direction.z); | |
174: } else if (face == 3.0) { | |
175: uv = vec2(direction.z, direction.y) / abs(direction.x); | |
176: } else if (face == 4.0) { | |
177: uv = direction.xz / abs(direction.y); | |
178: } else { | |
179: uv = vec2(-direction.x, direction.y) / abs(direction.z); | |
180: } | |
181: return 0.5 * (uv + 1.0); | |
182: } | |
183: | |
184: vec3 bilinearCubeUV(sampler2D envMap, vec3 direction, float mipInt) { | |
185: float face = getFace(direction); | |
186: float filterInt = max(cubeUV_minMipLevel - mipInt, 0.0); | |
187: mipInt = max(mipInt, cubeUV_minMipLevel); | |
188: float faceSize = exp2(mipInt); | |
189: | |
190: float texelSize = 1.0 / (3.0 * cubeUV_maxTileSize); | |
191: | |
192: vec2 uv = getUV(direction, face) * (faceSize - 1.0); | |
193: vec2 f = fract(uv); | |
194: uv += 0.5 - f; | |
195: if (face > 2.0) { | |
196: uv.y += faceSize; | |
197: face -= 3.0; | |
198: } | |
199: uv.x += face * faceSize; | |
200: if(mipInt < cubeUV_maxMipLevel){ | |
201: uv.y += 2.0 * cubeUV_maxTileSize; | |
202: } | |
203: uv.y += filterInt * 2.0 * cubeUV_minTileSize; | |
204: uv.x += 3.0 * max(0.0, cubeUV_maxTileSize - 2.0 * faceSize); | |
205: uv *= texelSize; | |
206: | |
207: vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb; | |
208: uv.x += texelSize; | |
209: vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb; | |
210: uv.y += texelSize; | |
211: vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb; | |
212: uv.x -= texelSize; | |
213: vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb; | |
214: vec3 tm = mix(tl, tr, f.x); | |
215: vec3 bm = mix(bl, br, f.x); | |
216: return mix(tm, bm, f.y); | |
217: } | |
218: | |
219: void main() { | |
220: gl_FragColor = vec4(0.0); | |
221: if (copyEquirectangular) { | |
222: vec3 direction = normalize(vOutputDirection); | |
223: vec2 uv; | |
224: uv.y = asin(clamp(direction.y, -1.0, 1.0)) * RECIPROCAL_PI + 0.5; | |
225: uv.x = atan(direction.z, direction.x) * RECIPROCAL_PI2 + 0.5; | |
226: vec2 f = fract(uv / texelSize - 0.5); | |
227: uv -= f * texelSize; | |
228: vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb; | |
229: uv.x += texelSize.x; | |
230: vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb; | |
231: uv.y += texelSize.y; | |
232: vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb; | |
233: uv.x -= texelSize.x; | |
234: vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb; | |
235: vec3 tm = mix(tl, tr, f.x); | |
236: vec3 bm = mix(bl, br, f.x); | |
237: gl_FragColor.rgb = mix(tm, bm, f.y); | |
238: } else { | |
239: float xz = length(vOutputDirection.xz); | |
240: for (int i = 0; i < n; i++) { | |
241: if (i >= samples) | |
242: break; | |
243: for (int dir = -1; dir < 2; dir += 2) { | |
244: if (i == 0 && dir == 1) | |
245: continue; | |
246: vec3 sampleDirection = vOutputDirection; | |
247: if (latitudinal) { | |
248: float diTheta = dTheta * float(dir * i) / xz; | |
249: mat2 R = | |
250: mat2(cos(diTheta), sin(diTheta), -sin(diTheta), cos(diTheta)); | |
251: sampleDirection.xz = R * sampleDirection.xz; | |
252: } else { | |
253: float diTheta = dTheta * float(dir * i); | |
254: mat2 R = | |
255: mat2(cos(diTheta), sin(diTheta), -sin(diTheta), cos(diTheta)); | |
256: vec2 xzY = R * vec2(xz, sampleDirection.y); | |
257: if (xzY.x < 0.0) { | |
258: sampleDirection = vec3(0.0, sign(sampleDirection.y), 0.0); | |
259: } else { | |
260: sampleDirection.xz *= xzY.x / xz; | |
261: sampleDirection.y = xzY.y; | |
262: } | |
263: } | |
264: gl_FragColor.rgb += | |
265: weights[i] * bilinearCubeUV(envMap, sampleDirection, mipInt); | |
266: } | |
267: } | |
268: } | |
269: gl_FragColor = linearToOutputTexel(gl_FragColor); | |
270: } | |
271: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
THREE.WebGLShader: gl.getShaderInfoLog() fragment | |
Compile failed. | |
WARNING: 0:255: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results | |
WARNING: 0:257: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results | |
WARNING: 0:259: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results | |
WARNING: 0:261: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results | |
WARNING: 4 compilation warnings. | |