Spaces:
Running
Running
File size: 1,454 Bytes
6cd9596 |
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 |
/**
* @author sunag / http://www.sunag.com.br/
*/
import { TempNode } from '../core/TempNode.js';
import { ConstNode } from '../core/ConstNode.js';
import { FunctionNode } from '../core/FunctionNode.js';
function LuminanceNode( rgb ) {
TempNode.call( this, 'f' );
this.rgb = rgb;
}
LuminanceNode.Nodes = ( function () {
var LUMA = new ConstNode( "vec3 LUMA vec3( 0.2125, 0.7154, 0.0721 )" );
var luminance = new FunctionNode( [
// Algorithm from Chapter 10 of Graphics Shaders
"float luminance( vec3 rgb ) {",
" return dot( rgb, LUMA );",
"}"
].join( "\n" ), [ LUMA ] );
return {
LUMA: LUMA,
luminance: luminance
};
} )();
LuminanceNode.prototype = Object.create( TempNode.prototype );
LuminanceNode.prototype.constructor = LuminanceNode;
LuminanceNode.prototype.nodeType = "Luminance";
LuminanceNode.prototype.generate = function ( builder, output ) {
var luminance = builder.include( LuminanceNode.Nodes.luminance );
return builder.format( luminance + '( ' + this.rgb.build( builder, 'v3' ) + ' )', this.getType( builder ), output );
};
LuminanceNode.prototype.copy = function ( source ) {
TempNode.prototype.copy.call( this, source );
this.rgb = source.rgb;
};
LuminanceNode.prototype.toJSON = function ( meta ) {
var data = this.getJSONNode( meta );
if ( ! data ) {
data = this.createJSONNode( meta );
data.rgb = this.rgb.toJSON( meta ).uuid;
}
return data;
};
export { LuminanceNode };
|