Skip to content

Instantly share code, notes, and snippets.

@pfreema1
Created January 24, 2020 15:37
Show Gist options
  • Save pfreema1/7815fd1151414c7b8d28bfa632eb2c56 to your computer and use it in GitHub Desktop.
Save pfreema1/7815fd1151414c7b8d28bfa632eb2c56 to your computer and use it in GitHub Desktop.
THREE.WebGLShader: gl.getShaderInfoLog() fragment
ERROR: 0:343: 'fff' : syntax error
1: precision highp float;
2: precision highp int;
3: #define HIGH_PRECISION
4: #define SHADER_NAME MeshBasicMaterial
5: #define GAMMA_FACTOR 2
6: uniform mat4 viewMatrix;
7: uniform vec3 cameraPosition;
8: #define TONE_MAPPING
9: #ifndef saturate
10: #define saturate(a) clamp( a, 0.0, 1.0 )
11: #endif
12: uniform float toneMappingExposure;
13: uniform float toneMappingWhitePoint;
14: vec3 LinearToneMapping( vec3 color ) {
15: return toneMappingExposure * color;
16: }
17: vec3 ReinhardToneMapping( vec3 color ) {
18: color *= toneMappingExposure;
19: return saturate( color / ( vec3( 1.0 ) + color ) );
20: }
21: #define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )
22: vec3 Uncharted2ToneMapping( vec3 color ) {
23: color *= toneMappingExposure;
24: return saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );
25: }
26: vec3 OptimizedCineonToneMapping( vec3 color ) {
27: color *= toneMappingExposure;
28: color = max( vec3( 0.0 ), color - 0.004 );
29: return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
30: }
31: vec3 ACESFilmicToneMapping( vec3 color ) {
32: color *= toneMappingExposure;
33: return saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );
34: }
35: vec3 toneMapping( vec3 color ) { return LinearToneMapping( color ); }
36:
37: vec4 LinearToLinear( in vec4 value ) {
38: return value;
39: }
40: vec4 GammaToLinear( in vec4 value, in float gammaFactor ) {
41: return vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );
42: }
43: vec4 LinearToGamma( in vec4 value, in float gammaFactor ) {
44: return vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );
45: }
46: vec4 sRGBToLinear( in vec4 value ) {
47: 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 );
48: }
49: vec4 LinearTosRGB( in vec4 value ) {
50: 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 );
51: }
52: vec4 RGBEToLinear( in vec4 value ) {
53: return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );
54: }
55: vec4 LinearToRGBE( in vec4 value ) {
56: float maxComponent = max( max( value.r, value.g ), value.b );
57: float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );
58: return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );
59: }
60: vec4 RGBMToLinear( in vec4 value, in float maxRange ) {
61: return vec4( value.rgb * value.a * maxRange, 1.0 );
62: }
63: vec4 LinearToRGBM( in vec4 value, in float maxRange ) {
64: float maxRGB = max( value.r, max( value.g, value.b ) );
65: float M = clamp( maxRGB / maxRange, 0.0, 1.0 );
66: M = ceil( M * 255.0 ) / 255.0;
67: return vec4( value.rgb / ( M * maxRange ), M );
68: }
69: vec4 RGBDToLinear( in vec4 value, in float maxRange ) {
70: return vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );
71: }
72: vec4 LinearToRGBD( in vec4 value, in float maxRange ) {
73: float maxRGB = max( value.r, max( value.g, value.b ) );
74: float D = max( maxRange / maxRGB, 1.0 );
75: D = min( floor( D ) / 255.0, 1.0 );
76: return vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );
77: }
78: const mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );
79: vec4 LinearToLogLuv( in vec4 value ) {
80: vec3 Xp_Y_XYZp = cLogLuvM * value.rgb;
81: Xp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );
82: vec4 vResult;
83: vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;
84: float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;
85: vResult.w = fract( Le );
86: vResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;
87: return vResult;
88: }
89: const mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );
90: vec4 LogLuvToLinear( in vec4 value ) {
91: float Le = value.z * 255.0 + value.w;
92: vec3 Xp_Y_XYZp;
93: Xp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );
94: Xp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;
95: Xp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;
96: vec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;
97: return vec4( max( vRGB, 0.0 ), 1.0 );
98: }
99: vec4 mapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
100: vec4 matcapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
101: vec4 envMapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
102: vec4 emissiveMapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
103: vec4 linearToOutputTexel( vec4 value ) { return LinearToGamma( value, float( GAMMA_FACTOR ) ); }
104:
105: uniform float pathProgress;
106: varying vec2 vUv;
107: uniform vec3 diffuse;
108: uniform float opacity;
109: #ifndef FLAT_SHADED
110: varying vec3 vNormal;
111: #endif
112: #define PI 3.14159265359
113: #define PI2 6.28318530718
114: #define PI_HALF 1.5707963267949
115: #define RECIPROCAL_PI 0.31830988618
116: #define RECIPROCAL_PI2 0.15915494
117: #define LOG2 1.442695
118: #define EPSILON 1e-6
119: #define saturate(a) clamp( a, 0.0, 1.0 )
120: #define whiteComplement(a) ( 1.0 - saturate( a ) )
121: float pow2( const in float x ) { return x*x; }
122: float pow3( const in float x ) { return x*x*x; }
123: float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
124: float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
125: highp float rand( const in vec2 uv ) {
126: const highp float a = 12.9898, b = 78.233, c = 43758.5453;
127: highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
128: return fract(sin(sn) * c);
129: }
130: #ifdef HIGH_PRECISION
131: float precisionSafeLength( vec3 v ) { return length( v ); }
132: #else
133: float max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }
134: float precisionSafeLength( vec3 v ) {
135: float maxComponent = max3( abs( v ) );
136: return length( v / maxComponent ) * maxComponent;
137: }
138: #endif
139: struct IncidentLight {
140: vec3 color;
141: vec3 direction;
142: bool visible;
143: };
144: struct ReflectedLight {
145: vec3 directDiffuse;
146: vec3 directSpecular;
147: vec3 indirectDiffuse;
148: vec3 indirectSpecular;
149: };
150: struct GeometricContext {
151: vec3 position;
152: vec3 normal;
153: vec3 viewDir;
154: #ifdef CLEARCOAT
155: vec3 clearcoatNormal;
156: #endif
157: };
158: vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
159: return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
160: }
161: vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
162: return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
163: }
164: vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
165: float distance = dot( planeNormal, point - pointOnPlane );
166: return - distance * planeNormal + point;
167: }
168: float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
169: return sign( dot( point - pointOnPlane, planeNormal ) );
170: }
171: vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
172: return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;
173: }
174: mat3 transposeMat3( const in mat3 m ) {
175: mat3 tmp;
176: tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
177: tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
178: tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
179: return tmp;
180: }
181: float linearToRelativeLuminance( const in vec3 color ) {
182: vec3 weights = vec3( 0.2126, 0.7152, 0.0722 );
183: return dot( weights, color.rgb );
184: }
185: #ifdef USE_COLOR
186: varying vec3 vColor;
187: #endif
188: #ifdef USE_UV
189: varying vec2 vUv;
190: #endif
191: #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
192: varying vec2 vUv2;
193: #endif
194: #ifdef USE_MAP
195: uniform sampler2D map;
196: #endif
197: #ifdef USE_ALPHAMAP
198: uniform sampler2D alphaMap;
199: #endif
200: #ifdef USE_AOMAP
201: uniform sampler2D aoMap;
202: uniform float aoMapIntensity;
203: #endif
204: #ifdef USE_LIGHTMAP
205: uniform sampler2D lightMap;
206: uniform float lightMapIntensity;
207: #endif
208: #ifdef USE_ENVMAP
209: uniform float envMapIntensity;
210: uniform float flipEnvMap;
211: uniform int maxMipLevel;
212: #ifdef ENVMAP_TYPE_CUBE
213: uniform samplerCube envMap;
214: #else
215: uniform sampler2D envMap;
216: #endif
217:
218: #endif
219: #ifdef USE_ENVMAP
220: uniform float reflectivity;
221: #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
222: #define ENV_WORLDPOS
223: #endif
224: #ifdef ENV_WORLDPOS
225: varying vec3 vWorldPosition;
226: uniform float refractionRatio;
227: #else
228: varying vec3 vReflect;
229: #endif
230: #endif
231: #ifdef USE_FOG
232: uniform vec3 fogColor;
233: varying float fogDepth;
234: #ifdef FOG_EXP2
235: uniform float fogDensity;
236: #else
237: uniform float fogNear;
238: uniform float fogFar;
239: #endif
240: #endif
241: #ifdef USE_SPECULARMAP
242: uniform sampler2D specularMap;
243: #endif
244: #if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
245: uniform float logDepthBufFC;
246: varying float vFragDepth;
247: #endif
248: #if 0 > 0
249: #if ! defined( STANDARD ) && ! defined( PHONG ) && ! defined( MATCAP )
250: varying vec3 vViewPosition;
251: #endif
252: uniform vec4 clippingPlanes[ 0 ];
253: #endif
254: void main() {
255: #if 0 > 0
256: vec4 plane;
257:
258: #if 0 < 0
259: bool clipped = true;
260:
261: if ( clipped ) discard;
262: #endif
263: #endif
264: vec4 diffuseColor = vec4( diffuse, opacity );
265: #if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
266: gl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;
267: #endif
268: #ifdef USE_MAP
269: vec4 texelColor = texture2D( map, vUv );
270: texelColor = mapTexelToLinear( texelColor );
271: diffuseColor *= texelColor;
272: #endif
273: #ifdef USE_COLOR
274: diffuseColor.rgb *= vColor;
275: #endif
276: #ifdef USE_ALPHAMAP
277: diffuseColor.a *= texture2D( alphaMap, vUv ).g;
278: #endif
279: #ifdef ALPHATEST
280: if ( diffuseColor.a < ALPHATEST ) discard;
281: #endif
282: float specularStrength;
283: #ifdef USE_SPECULARMAP
284: vec4 texelSpecular = texture2D( specularMap, vUv );
285: specularStrength = texelSpecular.r;
286: #else
287: specularStrength = 1.0;
288: #endif
289: ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
290: #ifdef USE_LIGHTMAP
291: reflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;
292: #else
293: reflectedLight.indirectDiffuse += vec3( 1.0 );
294: #endif
295: #ifdef USE_AOMAP
296: float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;
297: reflectedLight.indirectDiffuse *= ambientOcclusion;
298: #if defined( USE_ENVMAP ) && defined( STANDARD )
299: float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
300: reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );
301: #endif
302: #endif
303: reflectedLight.indirectDiffuse *= diffuseColor.rgb;
304: vec3 outgoingLight = reflectedLight.indirectDiffuse;
305: #ifdef USE_ENVMAP
306: #ifdef ENV_WORLDPOS
307: vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );
308: vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
309: #ifdef ENVMAP_MODE_REFLECTION
310: vec3 reflectVec = reflect( cameraToVertex, worldNormal );
311: #else
312: vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );
313: #endif
314: #else
315: vec3 reflectVec = vReflect;
316: #endif
317: #ifdef ENVMAP_TYPE_CUBE
318: vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
319: #elif defined( ENVMAP_TYPE_EQUIREC )
320: vec2 sampleUV;
321: reflectVec = normalize( reflectVec );
322: sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
323: sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
324: vec4 envColor = texture2D( envMap, sampleUV );
325: #elif defined( ENVMAP_TYPE_SPHERE )
326: reflectVec = normalize( reflectVec );
327: vec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );
328: vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );
329: #else
330: vec4 envColor = vec4( 0.0 );
331: #endif
332: envColor = envMapTexelToLinear( envColor );
333: #ifdef ENVMAP_BLENDING_MULTIPLY
334: outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
335: #elif defined( ENVMAP_BLENDING_MIX )
336: outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
337: #elif defined( ENVMAP_BLENDING_ADD )
338: outgoingLight += envColor.xyz * specularStrength * reflectivity;
339: #endif
340: #endif
341: gl_FragColor = vec4( outgoingLight, diffuseColor.a );
342:
343: vec4 color1 = vec4(1.0, 0.0, 0.0, 1.0)fff;
344: vec4 color2 = vec4(0.0);
345: vec4 finalColor = vec4(0.0);
346:
347: finalColor = mix(color1, color2, step(pathProgress, vUv.y));
348:
349: gl_FragColor = vec4(finalColor);
350:
351: #if defined( TONE_MAPPING )
352: gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
353: #endif
354: gl_FragColor = linearToOutputTexel( gl_FragColor );
355: #ifdef USE_FOG
356: #ifdef FOG_EXP2
357: float fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );
358: #else
359: float fogFactor = smoothstep( fogNear, fogFar, fogDepth );
360: #endif
361: gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
362: #endif
363: }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment