TextureCubeNode.js 1.8 KB
Newer Older
S
sunag 已提交
1 2 3 4
/**
 * @author sunag / http://www.sunag.com.br/
 */

S
sunag 已提交
5 6
import { TempNode } from '../core/TempNode.js';
import { TextureCubeUVNode } from './TextureCubeUVNode.js';
S
sunag 已提交
7

S
sunag 已提交
8
function TextureCubeNode( value, uv ) {
S
sunag 已提交
9

S
sunag 已提交
10
	TempNode.call( this, 'v4' );
S
sunag 已提交
11 12

	this.value = value;
S
sunag 已提交
13
	this.uv = uv || new TextureCubeUVNode();
S
sunag 已提交
14

S
sunag 已提交
15
}
S
sunag 已提交
16

S
sunag 已提交
17 18 19
TextureCubeNode.prototype = Object.create( TempNode.prototype );
TextureCubeNode.prototype.constructor = TextureCubeNode;
TextureCubeNode.prototype.nodeType = "TextureCube";
S
sunag 已提交
20

S
sunag 已提交
21
TextureCubeNode.prototype.generate = function ( builder, output ) {
S
sunag 已提交
22 23 24

	if ( builder.isShader( 'fragment' ) ) {

S
sunag 已提交
25 26 27
		var uv_10 = this.uv.build( builder ) + '.uv_10',
			uv_20 = this.uv.build( builder ) + '.uv_20',
			t = this.uv.build( builder ) + '.t';
S
sunag 已提交
28

S
sunag 已提交
29 30
		var color10 = builder.getTexelDecodingFunctionFromTexture( 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_10 + ' )', this.value.value ),
			color20 = builder.getTexelDecodingFunctionFromTexture( 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_20 + ' )', this.value.value );
S
sunag 已提交
31 32

		return builder.format( 'vec4( mix( ' + color10 + ', ' + color20 + ', ' + t + ' ).rgb, 1.0 )', this.getType( builder ), output );
S
sunag 已提交
33

S
sunag 已提交
34 35 36 37 38 39 40 41 42 43
	} else {

		console.warn( "THREE.TextureCubeNode is not compatible with " + builder.shader + " shader." );

		return builder.format( 'vec4( 0.0 )', this.getType( builder ), output );

	}

};

S
sunag 已提交
44
TextureCubeNode.prototype.toJSON = function ( meta ) {
S
sunag 已提交
45 46 47 48 49 50 51

	var data = this.getJSONNode( meta );

	if ( ! data ) {

		data = this.createJSONNode( meta );

S
sunag 已提交
52
		data.uv = this.uv.toJSON( meta ).uuid;
S
sunag 已提交
53 54 55 56 57 58 59 60 61 62
		data.textureSize = this.textureSize.toJSON( meta ).uuid;
		data.blinnExponentToRoughness = this.blinnExponentToRoughness.toJSON( meta ).uuid;

		if ( this.roughness ) data.roughness = this.roughness.toJSON( meta ).uuid;

	}

	return data;

};
S
sunag 已提交
63 64

export { TextureCubeNode };