Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
Merge pull request #354 from cedricpinson/remove-normalizeNormalAndEy…
Browse files Browse the repository at this point in the history
…eVector

Removes NormalizeNormalAndEyeVector
  • Loading branch information
cedricpinson committed Jun 24, 2015
2 parents 4480639 + 9d4809d commit 83b355e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 55 deletions.
41 changes: 14 additions & 27 deletions sources/osgShader/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,44 +420,31 @@ define( [
var normal = this._variables[ 'normal' ];
if ( normal )
return normal;
this.normalizeNormalAndEyeVector();
return this._variables[ 'normal' ];
var out = this.createVariable( 'vec3', 'normal' );
factory.getNode( 'Normalize' ).inputs( {
vec: this.getOrCreateFrontNormal()
} ).outputs( {
vec: out
} );
return out;
},


getOrCreateNormalizedPosition: function () {
var eye = this._variables[ 'eyeVector' ];
if ( eye )
return eye;
this.normalizeNormalAndEyeVector();
return this._variables[ 'eyeVector' ];
},


// It should be called by getOrCreateNormalizedNormal or getOrCreateNormalizedPosition ONLY
normalizeNormalAndEyeVector: function () {

var frontNormal = this.getOrCreateFrontNormal();
var inputPosition = this.getOrCreateInputPosition();

// get or create normalized normal
var outputNormal = this.createVariable( 'vec3', 'normal' );

// get or create normalized position
var outputPosition = this.createVariable( 'vec3', 'eyeVector' );

//
factory.getNode( 'NormalizeNormalAndEyeVector' ).inputs( {
normal: frontNormal,
position: inputPosition
var nor = this.createVariable( 'vec3' );
factory.getNode( 'Normalize' ).inputs( {
vec: this.getOrCreateInputPosition()
} ).outputs( {
normal: outputNormal,
eyeVector: outputPosition
vec: nor
} );

var out = this.createVariable( 'vec3', 'eyeVector' );
factory.getNode( 'Mult' ).inputs( nor, this.createVariable( 'float' ).setValue( '-1.0' ) ).outputs( out );
return out;
},


getPremultAlpha: function ( finalColor, alpha ) {

if ( alpha === undefined )
Expand Down
6 changes: 0 additions & 6 deletions sources/osgShader/node/functions.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ vec4 sRGBToLinear(const in vec4 c, const in float gamma)
return v;
}

void normalizeNormalAndEyeVector( const in vec3 inputNormal, const in vec3 inputEye, out vec3 normal, out vec3 eye )
{
normal = normalize( inputNormal );
eye = normalize( -inputEye );
}

//http://graphicrants.blogspot.fr/2009/04/rgbm-color-encoding.html
vec3 RGBMToRGB( const in vec4 rgba )
{
Expand Down
29 changes: 7 additions & 22 deletions sources/osgShader/node/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,15 @@ define( [
} );


var NormalizeNormalAndEyeVector = function () {
var Normalize = function () {
NodeFunctions.apply( this );
};

NormalizeNormalAndEyeVector.prototype = MACROUTILS.objectInherit( NodeFunctions.prototype, {

type: 'NormalizeNormalAndEyeVector',

validInputs: [
'normal',
'position'
],
validOuputs: [
'normal',
'eyeVector'
],

Normalize.prototype = MACROUTILS.objectInherit( NodeFunctions.prototype, {
type: 'Normalize',
validInputs: [ 'vec' ],
validOuputs: [ 'vec' ],
computeShader: function () {
return utils.callFunction( 'normalizeNormalAndEyeVector', undefined, [
this._inputs.normal,
this._inputs.position,
this._outputs.normal,
this._outputs.eyeVector
] );
return utils.callFunction( 'normalize', this._outputs.vec, [ this._inputs.vec ] );
}
} );

Expand Down Expand Up @@ -135,7 +120,7 @@ define( [

return {
NodeFunctions: NodeFunctions,
NormalizeNormalAndEyeVector: NormalizeNormalAndEyeVector,
Normalize: Normalize,
sRGBToLinear: sRGBToLinear,
LinearTosRGB: LinearTosRGB,
FrontNormal: FrontNormal,
Expand Down

0 comments on commit 83b355e

Please sign in to comment.