Skip to content

Commit

Permalink
Merge pull request #1 from sunag/dev2-mainline-anisotropy
Browse files Browse the repository at this point in the history
NodeMaterial Revision
  • Loading branch information
DanielSturk authored Sep 16, 2019
2 parents b2b9cb8 + 91b1864 commit 4b23aef
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
12 changes: 0 additions & 12 deletions examples/jsm/nodes/accessors/NormalNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function NormalNode( scope ) {
}

NormalNode.LOCAL = 'local';
NormalNode.BENT = 'bent';
NormalNode.WORLD = 'world';

NormalNode.prototype = Object.create( TempNode.prototype );
Expand Down Expand Up @@ -42,17 +41,6 @@ NormalNode.prototype.generate = function ( builder, output ) {

break;

case NormalNode.BENT:

if ( builder.isShader( 'fragment' ) ) {
if( builder.context.anisotropy ) result = 'getBentNormal( geometry, anisotropyFactor, roughnessFactor )';
else result = 'geometry.normal';
} else {
result = 'geometryNormal';
}

break;

case NormalNode.WORLD:

if ( builder.isShader( 'vertex' ) ) {
Expand Down
9 changes: 4 additions & 5 deletions examples/jsm/nodes/accessors/ReflectNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { TempNode } from '../core/TempNode.js';
import { PositionNode } from './PositionNode.js';
import { NormalNode } from './NormalNode.js';

function ReflectNode( scope, normal ) {
function ReflectNode( scope ) {

TempNode.call( this, 'v3' );

this.scope = scope || ReflectNode.CUBE;
this.normal = normal || null;

}

Expand Down Expand Up @@ -55,7 +54,7 @@ ReflectNode.prototype.generate = function ( builder, output ) {

case ReflectNode.VECTOR:

var viewNormalNode = this.normal || builder.context.viewNormal || new NormalNode();
var viewNormalNode = builder.context.viewNormal || new NormalNode();
var roughnessNode = builder.context.roughness;

var viewNormal = viewNormalNode.build( builder, 'v3' );
Expand Down Expand Up @@ -89,7 +88,7 @@ ReflectNode.prototype.generate = function ( builder, output ) {

case ReflectNode.CUBE:

var reflectVec = new ReflectNode( ReflectNode.VECTOR, this.normal ).build( builder, 'v3' );
var reflectVec = new ReflectNode( ReflectNode.VECTOR ).build( builder, 'v3' );

var code = 'vec3( -' + reflectVec + '.x, ' + reflectVec + '.yz )';

Expand All @@ -109,7 +108,7 @@ ReflectNode.prototype.generate = function ( builder, output ) {

case ReflectNode.SPHERE:

var reflectVec = new ReflectNode( ReflectNode.VECTOR, this.normal ).build( builder, 'v3' );
var reflectVec = new ReflectNode( ReflectNode.VECTOR ).build( builder, 'v3' );

var code = 'normalize( ( viewMatrix * vec4( ' + reflectVec + ', 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) ).xy * 0.5 + 0.5';

Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/nodes/inputs/CubeTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { InputNode } from '../core/InputNode.js';
import { ReflectNode } from '../accessors/ReflectNode.js';
import { ColorSpaceNode } from '../utils/ColorSpaceNode.js';
import { ExpressionNode } from '../core/ExpressionNode.js';
import { NormalNode } from '../accessors/NormalNode.js';

function CubeTextureNode( value, uv, bias ) {

InputNode.call( this, 'v4', { shared: true } );

this.value = value;
this.uv = uv || new ReflectNode( ReflectNode.CUBE, new NormalNode( NormalNode.BENT ) );
this.uv = uv || new ReflectNode();
this.bias = bias;

}
Expand Down
42 changes: 28 additions & 14 deletions examples/jsm/nodes/materials/nodes/StandardNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ExpressionNode } from '../../core/ExpressionNode.js';
import { ColorNode } from '../../inputs/ColorNode.js';
import { FloatNode } from '../../inputs/FloatNode.js';
import { SpecularMIPLevelNode } from '../../utils/SpecularMIPLevelNode.js';
import { NormalNode } from '../../accessors/NormalNode.js';

function StandardNode() {

Expand All @@ -37,6 +36,7 @@ StandardNode.prototype.build = function ( builder ) {
builder.define('STANDARD');

var useClearcoat = this.clearcoat || this.clearcoatRoughness || this.clearcoatNormal;
var useAnisotropy = !!this.anisotropy;

if( useClearcoat ){

Expand Down Expand Up @@ -147,18 +147,11 @@ StandardNode.prototype.build = function ( builder ) {
var specularRoughness = new ExpressionNode('material.specularRoughness', 'f' );
var clearcoatRoughness = new ExpressionNode('material.clearcoatRoughness', 'f' );

if ( this.anisotropy ) this.anisotropy.analyze( builder );
if ( this.anisotropyRotation ) this.anisotropyRotation.analyze( builder );

var anisotropy = this.anisotropy ? this.anisotropy.flow( builder, 'f' ) : undefined;
var anisotropyRotation = anisotropy && this.anisotropyRotation ? this.anisotropyRotation.flow( builder, 'f' ) : undefined;

var contextEnvironment = {
roughness: specularRoughness,
bias: new SpecularMIPLevelNode( specularRoughness ),
viewNormal: new ExpressionNode('normal', 'vec3'),
gamma: true,
anisotropy: !!anisotropy
viewNormal: useAnisotropy ? new ExpressionNode('getBentNormal( geometry, anisotropyFactor, roughnessFactor )', 'vec3') : new ExpressionNode('normal', 'vec3'),
gamma: true
};

var contextGammaOnly = {
Expand Down Expand Up @@ -188,6 +181,9 @@ StandardNode.prototype.build = function ( builder ) {
if ( this.clearcoatRoughness ) this.clearcoatRoughness.analyze( builder );
if ( this.clearcoatNormal ) this.clearcoatNormal.analyze( builder );

if ( useAnisotropy && this.anisotropy ) this.anisotropy.analyze( builder );
if ( useAnisotropy && this.anisotropyRotation ) this.anisotropyRotation.analyze( builder );

if ( this.reflectivity ) this.reflectivity.analyze( builder );

if ( this.light ) this.light.analyze( builder, { cache: 'light' } );
Expand Down Expand Up @@ -230,6 +226,9 @@ StandardNode.prototype.build = function ( builder ) {
var clearcoatRoughness = this.clearcoatRoughness ? this.clearcoatRoughness.flow( builder, 'f' ) : undefined;
var clearcoatNormal = this.clearcoatNormal ? this.clearcoatNormal.flow( builder, 'v3' ) : undefined;

var anisotropy = useAnisotropy ? this.anisotropy.flow( builder, 'f' ) : undefined;
var anisotropyRotation = useAnisotropy && this.anisotropyRotation ? this.anisotropyRotation.flow( builder, 'f' ) : undefined;

var reflectivity = this.reflectivity ? this.reflectivity.flow( builder, 'f' ) : undefined;

var light = this.light ? this.light.flow( builder, 'v3', { cache: 'light' } ) : undefined;
Expand Down Expand Up @@ -258,7 +257,7 @@ StandardNode.prototype.build = function ( builder ) {
var clearcoatEnv = useClearcoat && environment ? this.environment.flow( builder, 'c', { cache: 'clearcoat', context: contextClearcoatEnvironment, slot: 'environment' } ) : undefined;

var sheen = this.sheen ? this.sheen.flow( builder, 'c' ) : undefined;
builder.requires.uv[0] = builder.requires.uv[0] || !!anisotropy; // if tangents aren't available
builder.requires.uv[0] = builder.requires.uv[0] || useAnisotropy; // if tangents aren't available

builder.requires.transparent = alpha !== undefined;

Expand Down Expand Up @@ -387,10 +386,25 @@ StandardNode.prototype.build = function ( builder ) {

}

if ( anisotropy ) {
if ( useAnisotropy ) {

output.push(
anisotropy.code,
'float anisotropyFactor = ' + anisotropy.result + ';'
);

output.push( 'float anisotropyFactor = ' + anisotropy.result + ';' );
output.push( 'float anisotropyRotationFactor = ' + ( anisotropyRotation ? anisotropyRotation.result : '0.' ) + ';' );
if ( anisotropyRotation ) {

output.push(
anisotropyRotation.code,
'float anisotropyRotationFactor = ' + anisotropyRotation.result + ';'
);

} else {

output.push( 'float anisotropyRotationFactor = 0.;' );

}

}

Expand Down

0 comments on commit 4b23aef

Please sign in to comment.