|
@@ -2,10 +2,31 @@
|
|
|
* @author mrdoob / http://mrdoob.com/
|
|
|
* @author marklundin / http://mark-lundin.com/
|
|
|
* @author alteredq / http://alteredqualia.com/
|
|
|
+ * @author tschw
|
|
|
*/
|
|
|
|
|
|
THREE.AnaglyphEffect = function ( renderer, width, height ) {
|
|
|
|
|
|
+ // Matrices generated with angler.js https://github.com/tschw/angler.js/
|
|
|
+ // (in column-major element order, as accepted by WebGL)
|
|
|
+
|
|
|
+ this.colorMatrixLeft = new THREE.Matrix3().set(
|
|
|
+
|
|
|
+ 1.0671679973602295, -0.0016435992438346148, 0.0001777536963345483, // r out
|
|
|
+ -0.028107794001698494, -0.00019593400065787137, -0.0002875397040043026, // g out
|
|
|
+ -0.04279090091586113, 0.000015809757314855233, -0.00024287120322696865 // b out
|
|
|
+ );
|
|
|
+
|
|
|
+ // red green blue in
|
|
|
+
|
|
|
+ this.colorMatrixRight = new THREE.Matrix3().set(
|
|
|
+
|
|
|
+ -0.0355340838432312, -0.06440307199954987, 0.018319187685847282, // r out
|
|
|
+ -0.10269022732973099, 0.8079727292060852, -0.04835830628871918, // g out
|
|
|
+ 0.0001224992738571018, -0.009558862075209618, 0.567823588848114 // b out
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
var _camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
|
|
|
|
|
|
var _scene = new THREE.Scene();
|
|
@@ -25,7 +46,10 @@ THREE.AnaglyphEffect = function ( renderer, width, height ) {
|
|
|
uniforms: {
|
|
|
|
|
|
"mapLeft": { type: "t", value: _renderTargetL },
|
|
|
- "mapRight": { type: "t", value: _renderTargetR }
|
|
|
+ "mapRight": { type: "t", value: _renderTargetR },
|
|
|
+
|
|
|
+ "colorMatrixLeft": { type: "m3", value: this.colorMatrixLeft },
|
|
|
+ "colorMatrixRight": { type: "m3", value: this.colorMatrixRight }
|
|
|
|
|
|
},
|
|
|
|
|
@@ -48,17 +72,40 @@ THREE.AnaglyphEffect = function ( renderer, width, height ) {
|
|
|
"uniform sampler2D mapRight;",
|
|
|
"varying vec2 vUv;",
|
|
|
|
|
|
+ "uniform mat3 colorMatrixLeft;",
|
|
|
+ "uniform mat3 colorMatrixRight;",
|
|
|
+
|
|
|
+ // These functions implement sRGB linearization and gamma correction
|
|
|
+
|
|
|
+ "float lin( float c ) {",
|
|
|
+ " return c <= 0.04045 ? c * 0.0773993808 :",
|
|
|
+ " pow( c * 0.9478672986 + 0.0521327014, 2.4 );",
|
|
|
+ "}",
|
|
|
+
|
|
|
+ "vec4 lin( vec4 c ) {",
|
|
|
+ " return vec4( lin( c.r ), lin( c.g ), lin( c.b ), c.a );",
|
|
|
+ "}",
|
|
|
+
|
|
|
+ "float dev( float c ) {",
|
|
|
+ " return c <= 0.0031308 ? c * 12.92",
|
|
|
+ " : pow( c, 0.41666 ) * 1.055 - 0.055;",
|
|
|
+ "}",
|
|
|
+
|
|
|
+
|
|
|
"void main() {",
|
|
|
|
|
|
- " vec4 colorL, colorR;",
|
|
|
" vec2 uv = vUv;",
|
|
|
|
|
|
- " colorL = texture2D( mapLeft, uv );",
|
|
|
- " colorR = texture2D( mapRight, uv );",
|
|
|
+ " vec4 colorL = lin( texture2D( mapLeft, uv ) );",
|
|
|
+ " vec4 colorR = lin( texture2D( mapRight, uv ) );",
|
|
|
|
|
|
- // http://3dtv.at/Knowhow/AnaglyphComparison_en.aspx
|
|
|
+ " vec3 color = clamp(",
|
|
|
+ " colorMatrixLeft * colorL.rgb +",
|
|
|
+ " colorMatrixRight * colorR.rgb, 0., 1. );",
|
|
|
|
|
|
- " gl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;",
|
|
|
+ " gl_FragColor = vec4(",
|
|
|
+ " dev( color.r ), dev( color.g ), dev( color.b ),",
|
|
|
+ " max( colorL.a, colorR.a ) );",
|
|
|
|
|
|
"}"
|
|
|
|