From 86a801c057fc3b0580d6130be5740c2ee503444f Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 27 Jan 2012 15:52:36 -0800 Subject: updated from old repo --- .../RDGE/Materials/BumpMetalMaterial.js | 66 ++++++-- js/helper-classes/RDGE/Materials/FlatMaterial.js | 2 + .../RDGE/Materials/IridescentScalesMaterial.js | 5 +- js/helper-classes/RDGE/Materials/JuliaMaterial.js | 3 + .../RDGE/Materials/KeleidoscopeMaterial.js | 3 + .../RDGE/Materials/LinearGradientMaterial.js | 4 + js/helper-classes/RDGE/Materials/MandelMaterial.js | 4 + js/helper-classes/RDGE/Materials/PulseMaterial.js | 15 +- .../RDGE/Materials/RadialBlurMaterial.js | 3 + .../RDGE/Materials/RadialGradientMaterial.js | 188 +++++++++++++-------- js/helper-classes/RDGE/Materials/TunnelMaterial.js | 3 + js/helper-classes/RDGE/Materials/TwistMaterial.js | 3 + js/helper-classes/RDGE/Materials/UberMaterial.js | 25 ++- 13 files changed, 225 insertions(+), 99 deletions(-) (limited to 'js/helper-classes/RDGE/Materials') diff --git a/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js b/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js index 0aa3ee78..17be0cd7 100644 --- a/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js +++ b/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js @@ -22,9 +22,9 @@ function BumpMetalMaterial() this._shaderName = "bumpMetal"; this._lightDiff = [0.3, 0.3, 0.3, 1.0]; - this._diffuseTexture = "metal"; - this._specularTexture = "silver"; - this._normalTexture = "normalMap"; + this._diffuseTexture = "assets/images/metal.png"; + this._specularTexture = "assets/images/silver.png"; + this._normalTexture = "assets/images/normalMap.png"; /////////////////////////////////////////////////////////////////////// // Property Accessors @@ -37,17 +37,16 @@ function BumpMetalMaterial() if (this._shader && this._shader.default) this._shader.default.u_light0Diff.set( ld ); } - this.getDiffuseTexture = function() { return this._diffuseTexture; } - this.setDiffuseTexture = function(dt) { this._diffuseTexture = dt; - if (this._materialNode) this._materialNode.setDiffuseTexture( dt ); } + this.getDiffuseTexture = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null } + this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.updateTexture(1); } - this.getSpecularTexture = function() { return this._specularTexture; } - this.setSpecularTexture = function(st) { this._specularTexture = st; - if (this._materialNode) this._materialNode.setSpecularTexture( st ); } + this.getNormalTexture = function() { return this._propValues[this._propNames[2]] ? this._propValues[this._propNames[2]].slice() : null } + this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.updateTexture(2); } - this.getNormalTexture = function() { return this._normalTexture; } - this.setNormalTexture = function(nt) { this._normalTexture = nt; - if (this._materialNode) this._materialNode.setNormalTexture( nt ); } + this.getSpecularTexture = function() { return this._propValues[this._propNames[3]] ? this._propValues[this._propNames[3]].slice() : null } + this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.updateTexture(3); } + + this.isAnimated = function() { return true; } /////////////////////////////////////////////////////////////////////// // Material Property Accessors @@ -59,7 +58,7 @@ function BumpMetalMaterial() this._propValues[ this._propNames[0] ] = this._lightDiff.slice(0); this._propValues[ this._propNames[1] ] = this._diffuseTexture.slice(0); - this._propValues[ this._propNames[2] ] = this._specularTexture.slice(0); + this._propValues[ this._propNames[2] ] = this._normalTexture.slice(0); this._propValues[ this._propNames[3] ] = this._specularTexture.slice(0); // TODO - shader techniques are not all named the same, i.e., FlatMaterial uses "colorMe" and BrickMaterial uses "default" @@ -95,8 +94,11 @@ function BumpMetalMaterial() // duplcate method requirde this.dup = function() { return new BumpMetalMaterial(); } - this.init = function() + this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = bumpMetalMaterialDef; @@ -108,9 +110,36 @@ function BumpMetalMaterial() this._materialNode.setShader(this._shader); // set some image maps - this._materialNode.setDiffuseTexture( this.getDiffuseTexture() ); - this._materialNode.setSpecTexture( this.getSpecularTexture() ); - this._materialNode.setNormalTexture( this.getNormalTexture() ); + this.updateTexture(1); + this.updateTexture(2); + this.updateTexture(3); + } + + this.updateTexture = function( index ) + { + var material = this._materialNode; + if (material) + { + var technique = material.shaderProgram.default; + var renderer = g_Engine.getContext().renderer; + if (renderer && technique) + { + var texMapName = this._propValues[this._propNames[index]]; + var wrap = 'REPEAT', mips = true; + var tex = this.loadTexture( texMapName, wrap, mips ); + + if (tex) + { + switch (index) + { + case 1: technique.u_colMap.set( tex ); break; + case 2: technique.u_normalMap.set( tex ); break; + case 3: technique.u_glowMap.set( tex ); break; + default: console.log( "invalid map index in BumpMetalMaterial, " + index ); + } + } + } + } } this.export = function() @@ -229,6 +258,9 @@ bumpMetalShaderDef = { 'u_light0Diff' : { 'type' : 'vec4' }, //'u_matDiffuse' : { 'type' : 'vec4' } + 'u_colMap': { 'type' : 'tex2d' }, + 'u_normalMap': { 'type' : 'tex2d' }, + 'u_glowMap': { 'type' : 'tex2d' }, }, // render states diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index 5177a8a0..db66ca42 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js @@ -29,6 +29,8 @@ function FlatMaterial() this.getColor = function() { return this._color; } this.getShaderName = function() { return this._shaderName; } + this.isAnimated = function() { return true; } + //////////////////////////////////s///////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// diff --git a/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js b/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js index ac1d3fe7..a8b1c18b 100644 --- a/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js +++ b/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js @@ -80,8 +80,11 @@ function IridescentScalesMaterial() /////////////////////////////////////////////////////////////////////// this.dup = function() { return new IridescentScalesMaterial(); } - this.init = function() + this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = iridescentScalesShaderDef; diff --git a/js/helper-classes/RDGE/Materials/JuliaMaterial.js b/js/helper-classes/RDGE/Materials/JuliaMaterial.js index 69884d18..f95263f4 100644 --- a/js/helper-classes/RDGE/Materials/JuliaMaterial.js +++ b/js/helper-classes/RDGE/Materials/JuliaMaterial.js @@ -64,6 +64,9 @@ function JuliaMaterial() this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = JuliaMaterialDef; diff --git a/js/helper-classes/RDGE/Materials/KeleidoscopeMaterial.js b/js/helper-classes/RDGE/Materials/KeleidoscopeMaterial.js index 8f94f47b..1547aca9 100644 --- a/js/helper-classes/RDGE/Materials/KeleidoscopeMaterial.js +++ b/js/helper-classes/RDGE/Materials/KeleidoscopeMaterial.js @@ -62,6 +62,9 @@ function KeleidoscopeMaterial() this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = keleidoscopeMaterialDef; diff --git a/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js b/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js index 357ce275..f026cd15 100644 --- a/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js +++ b/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js @@ -98,6 +98,8 @@ function LinearGradientMaterial() this._shader.default.u_cos_sin_angle.set([Math.cos(a), Math.sin(a)]); } + this.isAnimated = function() { return true; } + /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// @@ -146,6 +148,8 @@ function LinearGradientMaterial() // send the current values to the shader this.updateShaderValues(); + + console.log( "**** LinearGradientMaterial initialized" ); } this.updateShaderValues= function() diff --git a/js/helper-classes/RDGE/Materials/MandelMaterial.js b/js/helper-classes/RDGE/Materials/MandelMaterial.js index 76083b76..25b08404 100644 --- a/js/helper-classes/RDGE/Materials/MandelMaterial.js +++ b/js/helper-classes/RDGE/Materials/MandelMaterial.js @@ -42,6 +42,7 @@ function MandelMaterial() /////////////////////////////////////////////////////////////////////// + this.isAnimated = function() { return true; } /////////////////////////////////////////////////////////////////////// // Methods @@ -64,6 +65,9 @@ function MandelMaterial() this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = MandelMaterialDef; diff --git a/js/helper-classes/RDGE/Materials/PulseMaterial.js b/js/helper-classes/RDGE/Materials/PulseMaterial.js index 5bee818e..3d6107fb 100644 --- a/js/helper-classes/RDGE/Materials/PulseMaterial.js +++ b/js/helper-classes/RDGE/Materials/PulseMaterial.js @@ -33,9 +33,11 @@ function PulseMaterial() this.getName = function() { return this._name; } this.getShaderName = function() { return this._shaderName; } - this.getTextureMap = function() { return this._texMap.slice(0); } + this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null } this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); } + this.isAnimated = function() { return true; } + /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// @@ -72,6 +74,9 @@ function PulseMaterial() // duplcate method requirde this.dup = function( world ) { + // save the world + if (world) this.setWorld( world ); + // allocate a new uber material var newMat = new PulseMaterial(); @@ -87,6 +92,9 @@ function PulseMaterial() this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = pulseMaterialDef; @@ -116,7 +124,10 @@ function PulseMaterial() if (renderer && technique) { var texMapName = this._propValues[this._propNames[0]]; - var tex = renderer.getTextureByName(texMapName, 'REPEAT'); + var wrap = 'REPEAT', mips = true; + //var tex = renderer.getTextureByName(texMapName, wrap, mips ); + //this.registerTexture( tex ); + var tex = this.loadTexture( texMapName, wrap, mips ); if (tex) technique.u_tex0.set( tex ); } diff --git a/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js b/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js index 25331b54..9acb4213 100644 --- a/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js +++ b/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js @@ -92,6 +92,9 @@ function RadialBlurMaterial() this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = radialBlurMaterialDef; diff --git a/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js b/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js index 70c0e952..5f912dec 100644 --- a/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js +++ b/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js @@ -21,13 +21,15 @@ function RadialGradientMaterial() this._name = "RadialGradientMaterial"; this._shaderName = "radialGradient"; - this._startColor = [1, 0, 0, 1]; - this._stopColor = [0, 1, 0, 1]; - - this._mainCircleRadius = 0.5; - this._innerCircleRadius = 0.05; - this._innerCircleCenter = [0.5, 0.5]; - this._mainCircleCenter = [0.5, 0.5]; + this._color1 = [1,0,0,1]; + this._color2 = [0,1,0,1]; + this._color3 = [0,0,1,1]; + this._color4 = [0,1,1,1]; + this._colorStop1 = 0.0; + this._colorStop2 = 0.3; + this._colorStop3 = 0.6; + this._colorStop4 = 1.0; + this._colorCount = 4; /////////////////////////////////////////////////////////////////////// // Property Accessors @@ -35,42 +37,79 @@ function RadialGradientMaterial() this.getName = function() { return this._name; } this.getShaderName = function() { return this._shaderName; } - this.getStartColor = function() { return this._startColor.slice(0); } - this.setStartColor = function(c) { this._startColor = c.slice(0); } - - this.getStopColor = function() { return this._stopColor.slice(0); } - this.setStopColor = function(c) { this._stopColor = c.slice(0); } - - this.getMainCircleRadius = function() { return this._mainCircleRadius; } - this.setMainCircleRadius = function(r) { this._mainCircleRadius = r; } - - this.getInnerCircleRadius = function() { return this._innerCircleRadius; } - this.setInnerCircleRadius = function(r) { this._innerCircleRadius = r; } + + this.getColor1 = function() { return this._color1; } + this.setColor1 = function(c) { this._color1 = c.slice(); + if (this._shader && this._shader.default) + this._shader.default.u_color1.set(c); + } + + this.getColor2 = function() { return this._color2; } + this.setColor2 = function(c) { this._color2 = c.slice(); + if (this._shader && this._shader.default) + this._shader.default.u_color2.set(c); + } + + this.getColor3 = function() { return this._color3; } + this.setColor3 = function(c) { this._color3 = c.slice(); + if (this._shader && this._shader.default) + this._shader.default.u_color3.set(c); + } + + this.getColor4 = function() { return this._color4; } + this.setColor4 = function(c) { this._color4 = c.slice(); + if (this._shader && this._shader.default) + this._shader.default.u_color4.set(c); + } + + this.getColorStop1 = function() { return this._colorStop1; } + this.setColorStop1 = function(s) { this._colorStop1 = s; + if (this._shader && this._shader.default) + this._shader.default.u_colorStop1.set([s]); + } + + this.getColorStop2 = function() { return this._colorStop2; } + this.setColorStop2 = function(s) { this._colorStop2 = s; + if (this._shader && this._shader.default) + this._shader.default.u_colorStop2.set([s]); + } + + this.getColorStop3 = function() { return this._colorStop3; } + this.setColorStop3 = function(s) { this._colorStop3 = s; + if (this._shader && this._shader.default) + this._shader.default.u_colorStop3.set([s]); + } + + this.getColorStop4 = function() { return this._colorStop4; } + this.setColorStop4 = function(s) { this._colorStop4 = s; + if (this._shader && this._shader.default) + this._shader.default.u_colorStop4.set([s]); + } + + this.getColorCount = function() { return this._colorCount; } + this.setColorCount = function(c) { this._colorCount = c; + if (this._shader && this._shader.default) + this._shader.default.u_colorCount.set([c]); + } + + this.isAnimated = function() { return true; } - this.getInnerCircleCenter = function() { return this._innerCircleCenter; } - this.setInnerCircleCenter = function(c) { this._innerCircleCenter = c; } - - this.getMainCircleCenter = function() { return this._mainCircleCenter; } - this.setMainCircleCenter = function(c) { this._mainCircleCenter = c; } /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["startColor", "stopColor", "mainCircleRadius", "innerCircleRadius", "mainCircleCenter", "innerCircleCenter"]; - this._propLabels = ["Start Color", "Stop Color", "Main Circle Radius", "Inner Circle Radius", "Main Circle Center", "Inner Circle Center"]; - this._propTypes = ["color", "color", "float", "float", "vector2d", "vector2d"]; + this._propNames = ["color1", "color2", "angle"]; + this._propLabels = ["Start Color", "Stop Color", "Angle"]; + this._propTypes = ["color", "color", "float"]; this._propValues = []; - this._propValues[ this._propNames[0] ] = this._startColor.slice(0); - this._propValues[ this._propNames[1] ] = this._stopColor.slice(0); - this._propValues[ this._propNames[2] ] = this.getMainCircleRadius(); - this._propValues[ this._propNames[3] ] = this.getInnerCircleRadius(); - this._propValues[ this._propNames[4] ] = this.getMainCircleCenter(); - this._propValues[ this._propNames[5] ] = this.getInnerCircleCenter(); + this._propValues[ this._propNames[0] ] = this._color1.slice(0); + this._propValues[ this._propNames[1] ] = this._color4.slice(0); + this._propValues[ this._propNames[2] ] = this._angle; this.setProperty = function( prop, value ) { - if (prop === "color") prop = "startColor"; + if (prop === "color") prop = "color1"; // make sure we have legitimate imput var ok = this.validateProperty( prop, value ); @@ -79,12 +118,9 @@ function RadialGradientMaterial() switch (prop) { - case "startColor": this.setStartColor(value); break; - case "stopColor": this.setStopColor(value); break; - case "innerCircleRadius": this.setInnerCircleRadius( value ); break; - case "mainCircleRadius": this.setMainCircleRadius( value ); break; - case "innerCircleCenter": this.setInnerCircleCenter( value ); break; - case "mainCircleCenter": this.setMainCircleCenter( value ); break; + case "color1": this.setColor1( value ); break; + case "color2": this.setColor2( value ); break; + case "angle": this.setAngle( value ); break; } this.updateValuesInShader(); @@ -115,25 +151,30 @@ function RadialGradientMaterial() this.updateValuesInShader = function() { - if (!this._shader || !this._shader.default) return; - - // calculate values - var mainCircleRadius = this.getMainCircleRadius(); - var innerCircleRadius = this.getInnerCircleRadius(); - var innerCircleCenter = this.getInnerCircleCenter(); - var mainCircleCenter = this.getMainCircleCenter(); - var radiusDelta = innerCircleRadius - mainCircleRadius; - var innerCircleCenterMinusCenter = VecUtils.vecSubtract( 2, innerCircleCenter, mainCircleCenter ); - var u_A = VecUtils.vecDot( 2, innerCircleCenterMinusCenter, innerCircleCenterMinusCenter) - (radiusDelta * radiusDelta) - - // set values - this._shader.default.u_center.set( innerCircleCenter ); - this._shader.default.u_startColor.set( this.getStartColor() ); - this._shader.default.u_stopColor.set( this.getStopColor() ); - this._shader.default.u_innerCircleCenterMinusCenter.set( innerCircleCenterMinusCenter ); - this._shader.default.u_radius.set( [mainCircleRadius] ); - this._shader.default.u_A.set( [ u_A] ); - this._shader.default.u_radiusDelta.set( [radiusDelta] ); + if (this._shader && this._shader.default) + { + //this._shader.default.u_colorCount.set( [4] ); + + var c; + c = this.getColor1(); + this._shader.default.u_color1.set( c ); + c = this.getColor2(); + this._shader.default.u_color2.set( c ); + c = this.getColor3(); + this._shader.default.u_color3.set( c ); + c = this.getColor4(); + this._shader.default.u_color4.set( c ); + + var s; + s = this.getColorStop1(); + this._shader.default.u_colorStop1.set( [s] ); + s = this.getColorStop2(); + this._shader.default.u_colorStop2.set( [s] ); + s = this.getColorStop3(); + this._shader.default.u_colorStop3.set( [s] ); + s = this.getColorStop4(); + this._shader.default.u_colorStop4.set( [s] ); + } } this.export = function() @@ -190,13 +231,13 @@ function RadialGradientMaterial() /////////////////////////////////////////////////////////////////////////////////////// // RDGE shader - + // shader spec (can also be loaded from a .JSON file, or constructed at runtime) var radialGradientMaterialDef = {'shaders': { 'defaultVShader':"assets/shaders/radialGradient.vert.glsl", - 'defaultFShader':"assets/shaders/radialGradient.frag.glsl", + 'defaultFShader':"assets/shaders/radialGradient.frag.glsl" }, 'techniques': { @@ -210,18 +251,21 @@ var radialGradientMaterialDef = { 'vert' : { 'type' : 'vec3' }, 'normal' : { 'type' : 'vec3' }, - 'texcoord' : { 'type' : 'vec2' }, + 'texcoord' : { 'type' : 'vec2' } }, // parameters 'params' : { - 'u_startColor' : { 'type' : 'vec4' }, - 'u_stopColor' : { 'type' : 'vec4' }, - 'u_center' : { 'type' : 'vec2' }, - 'u_radius' : { 'type' : 'float' }, - 'u_A' : { 'type' : 'float' }, - 'u_radiusDelta' : { 'type' : 'float' }, - 'u_innerCircleCenterMinusCenter' : { 'type' : 'vec2' }, + 'u_color1' : { 'type' : 'vec4' }, + 'u_color2' : { 'type' : 'vec4' }, + 'u_color3' : { 'type' : 'vec4' }, + 'u_color4' : { 'type' : 'vec4' }, + 'u_colorStop1': { 'type' : 'float' }, + 'u_colorStop2': { 'type' : 'float' }, + 'u_colorStop3': { 'type' : 'float' }, + 'u_colorStop4': { 'type' : 'float' }, + 'u_cos_sin_angle' : { 'type' : 'vec2' } + //'u_colorCount': {'type' : 'int' } }, // render states @@ -229,12 +273,8 @@ var radialGradientMaterialDef = { 'depthEnable' : true, 'offset':[1.0, 0.1] - }, - }, + } + } ] } }; - - - - diff --git a/js/helper-classes/RDGE/Materials/TunnelMaterial.js b/js/helper-classes/RDGE/Materials/TunnelMaterial.js index fe277af6..9b12e197 100644 --- a/js/helper-classes/RDGE/Materials/TunnelMaterial.js +++ b/js/helper-classes/RDGE/Materials/TunnelMaterial.js @@ -62,6 +62,9 @@ function TunnelMaterial() this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = tunnelMaterialDef; diff --git a/js/helper-classes/RDGE/Materials/TwistMaterial.js b/js/helper-classes/RDGE/Materials/TwistMaterial.js index c3094621..b113965b 100644 --- a/js/helper-classes/RDGE/Materials/TwistMaterial.js +++ b/js/helper-classes/RDGE/Materials/TwistMaterial.js @@ -62,6 +62,9 @@ function TwistMaterial() this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = twistMaterialDef; diff --git a/js/helper-classes/RDGE/Materials/UberMaterial.js b/js/helper-classes/RDGE/Materials/UberMaterial.js index a8254465..afb745d1 100644 --- a/js/helper-classes/RDGE/Materials/UberMaterial.js +++ b/js/helper-classes/RDGE/Materials/UberMaterial.js @@ -270,6 +270,7 @@ function UberMaterial() if (renderer && technique) { var tex = renderer.getTextureByName(value, caps.environmentMap.wrap); + this.registerTexture( tex ); technique.s_environmentMap.set( tex ); } } @@ -307,6 +308,7 @@ function UberMaterial() if (renderer && technique) { var tex = renderer.getTextureByName(value, caps.diffuseMap.wrap); + this.registerTexture( tex ); technique.s_diffuseMap.set( tex ); } } @@ -344,6 +346,7 @@ function UberMaterial() if (renderer && technique) { var tex = renderer.getTextureByName(value, caps.specularMap.wrap); + this.registerTexture( tex ); technique.s_specularMap.set( tex ); } } @@ -381,6 +384,7 @@ function UberMaterial() if (renderer && technique) { var tex = renderer.getTextureByName(value, caps.normalMap.wrap); + this.registerTexture( tex ); technique.s_normalMap.set( tex ); } } @@ -411,8 +415,11 @@ function UberMaterial() return newMat; } - this.init = function() + this.init = function( world ) { + // save the world + if (world) this.setWorld( world ); + // set up the shader this._shader = this.buildUberShader( this._ubershaderCaps ); @@ -579,16 +586,24 @@ function UberMaterial() renderer = g_Engine.getContext().renderer; if(this._useDiffuseMap) { - technique.s_diffuseMap.set(renderer.getTextureByName(caps.diffuseMap.texture, caps.diffuseMap.wrap, caps.diffuseMap.mips)); + var tex = renderer.getTextureByName(caps.diffuseMap.texture, caps.diffuseMap.wrap, caps.diffuseMap.mips); + this.registerTexture( tex ); + technique.s_diffuseMap.set( tex ); } if(this._useNormalMap) { - technique.s_normalMap.set(renderer.getTextureByName(caps.normalMap.texture, caps.normalMap.wrap, caps.normalMap.mips)); + var tex = renderer.getTextureByName(caps.normalMap.texture, caps.normalMap.wrap, caps.normalMap.mips); + this.registerTexture( tex ); + technique.s_normalMap.set( tex ); } if(this._useSpecularMap) { - technique.s_specMap.set(renderer.getTextureByName(caps.specularMap.texture, caps.specularMap.wrap)); + var tex = renderer.getTextureByName(caps.specularMap.texture, caps.specularMap.wrap); + this.registerTexture( tex ); + technique.s_specMap.set( tex ); } if(this._useEnvironmentMap) { - technique.s_envMap.set(renderer.getTextureByName(caps.environmentMap.texture, caps.environmentMap.wrap)); + var tex = renderer.getTextureByName(caps.environmentMap.texture, caps.environmentMap.wrap); + this.registerTexture( tex ); + technique.s_envMap.set( tex ); technique.u_envReflection.set([ caps.environmentMap.envReflection || 1.0 ] ); } -- cgit v1.2.3 From 8e43a46e3d79323fe06dc7771bc611a2c3c85c5c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 30 Jan 2012 16:15:12 -0800 Subject: Renderer startup handling of non-animated materials. Changed zoom from the document bar to keep the location center of the viewable portion of the document fixed. --- js/helper-classes/RDGE/Materials/FlatMaterial.js | 2 +- js/helper-classes/RDGE/Materials/LinearGradientMaterial.js | 2 +- js/helper-classes/RDGE/Materials/RadialGradientMaterial.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'js/helper-classes/RDGE/Materials') diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index db66ca42..f342eef8 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js @@ -29,7 +29,7 @@ function FlatMaterial() this.getColor = function() { return this._color; } this.getShaderName = function() { return this._shaderName; } - this.isAnimated = function() { return true; } + this.isAnimated = function() { return false; } //////////////////////////////////s///////////////////////////////////// // Methods diff --git a/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js b/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js index f026cd15..ce965296 100644 --- a/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js +++ b/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js @@ -98,7 +98,7 @@ function LinearGradientMaterial() this._shader.default.u_cos_sin_angle.set([Math.cos(a), Math.sin(a)]); } - this.isAnimated = function() { return true; } + this.isAnimated = function() { return false; } /////////////////////////////////////////////////////////////////////// // Material Property Accessors diff --git a/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js b/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js index 5f912dec..cf91f1aa 100644 --- a/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js +++ b/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js @@ -92,7 +92,7 @@ function RadialGradientMaterial() this._shader.default.u_colorCount.set([c]); } - this.isAnimated = function() { return true; } + this.isAnimated = function() { return false; } /////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From b2ce8b819cc85a558d862c04965b7e65a6ce8640 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 1 Feb 2012 13:05:32 -0800 Subject: changes to allow minimal rendering ofnon-animated materials. --- js/helper-classes/RDGE/Materials/FlatMaterial.js | 41 +++++++++++++----------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'js/helper-classes/RDGE/Materials') diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index f342eef8..3e3ae25e 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js @@ -50,6 +50,12 @@ function FlatMaterial() // set up the material node this._materialNode = createMaterialNode("flatMaterial"); this._materialNode.setShader(this._shader); + + // initialize the taper properties +// this._shader.colorMe.u_limit1.set( [0.25] ); +// this._shader.colorMe.u_limit2.set( [0.5] ); +// this._shader.colorMe.u_limit3.set( [0.75] ); +// this._shader.colorMe.u_taperAmount.set( [0.5] ); } @@ -102,10 +108,11 @@ function FlatMaterial() var rtnStr = importStr.substr( index ); return rtnStr; } -} -// used to create unique names -var flatMaterialCounter = 0; + this.update = function( time ) + { + } +} /////////////////////////////////////////////////////////////////////////////////////// // RDGE shader @@ -114,35 +121,31 @@ var flatMaterialCounter = 0; flatShaderDef = { 'shaders': { // shader files - 'defaultVShader': "\ - uniform mat4 u_mvMatrix;\ - uniform mat4 u_projMatrix;\ - attribute vec3 a_pos;\ - void main() {\ - gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\ - }", - 'defaultFShader': "\ - precision highp float;\ - uniform vec4 color;\ - void main() {\ - gl_FragColor = color;\ - }", + 'defaultVShader':"assets/shaders/Basic.vert.glsl", + 'defaultFShader':"assets/shaders/Basic.frag.glsl", }, 'techniques': { // rendering control 'colorMe':[ // simple color pass { 'vshader' : 'defaultVShader', 'fshader' : 'defaultFShader', - + // attributes 'attributes' : { - 'a_pos' : { 'type' : 'vec3' } // only using position for this shader + 'vert' : { 'type' : 'vec3' }, + 'normal' : { 'type' : 'vec3' }, + 'texcoord' : { 'type' : 'vec2' }, }, // attributes 'params' : { - 'color' : { 'type' : 'vec4' } + 'color' : { 'type' : 'vec4' }, + + //'u_limit1': { 'type': 'float' }, + //'u_limit2': { 'type': 'float' }, + //'u_limit3': { 'type': 'float' }, + //'u_taperAmount': { 'type': 'float' } }, }, ] -- cgit v1.2.3 From 4222db97e353fb65fab787ba5927d16d9fa4e1f7 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 1 Feb 2012 16:18:26 -0800 Subject: Removed a console log and set the Plasma material to animating. --- js/helper-classes/RDGE/Materials/PlasmaMaterial.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/helper-classes/RDGE/Materials') diff --git a/js/helper-classes/RDGE/Materials/PlasmaMaterial.js b/js/helper-classes/RDGE/Materials/PlasmaMaterial.js index f900b35a..a65f3a33 100644 --- a/js/helper-classes/RDGE/Materials/PlasmaMaterial.js +++ b/js/helper-classes/RDGE/Materials/PlasmaMaterial.js @@ -32,6 +32,8 @@ function PlasmaMaterial() /////////////////////////////////////////////////////////////////////// this.getShaderName = function() { return this._shaderName; } + this.isAnimated = function() { return true; } + /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// -- cgit v1.2.3