From d4ca478ad313c6c20834e410ba14ad3a5e7b20bf Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 12 Jun 2012 10:28:26 -0700 Subject: Material cleanup & bug fixes. --- assets/shaders/Mandel.frag.glsl | 9 +- assets/shaders/ReliefTunnel.frag.glsl | 7 +- assets/shaders/SquareTunnel.frag.glsl | 3 +- assets/shaders/Star.frag.glsl | 11 +- assets/shaders/Tunnel.frag.glsl | 3 +- assets/shaders/Twist.frag.glsl | 7 +- assets/shaders/ZInvert.frag.glsl | 7 +- assets/shaders/radialBlur.frag.glsl | 5 +- js/lib/rdge/materials/fly-material.js | 2 +- js/lib/rdge/materials/mandel-material.js | 48 +--- js/lib/rdge/materials/plasma-material.js | 109 +-------- js/lib/rdge/materials/pulse-material.js | 2 + js/lib/rdge/materials/radial-blur-material.js | 119 +--------- js/lib/rdge/materials/radial-gradient-material.js | 274 ++-------------------- js/lib/rdge/materials/relief-tunnel-material.js | 44 ++-- js/lib/rdge/materials/square-tunnel-material.js | 44 ++-- js/lib/rdge/materials/star-material.js | 44 ++-- js/lib/rdge/materials/taper-material.js | 74 +----- js/lib/rdge/materials/tunnel-material.js | 44 ++-- js/lib/rdge/materials/twist-material.js | 57 ++--- js/lib/rdge/materials/twist-vert-material.js | 197 +++------------- js/lib/rdge/materials/z-invert-material.js | 49 ++-- 22 files changed, 245 insertions(+), 914 deletions(-) diff --git a/assets/shaders/Mandel.frag.glsl b/assets/shaders/Mandel.frag.glsl index 6465899d..62be76b9 100644 --- a/assets/shaders/Mandel.frag.glsl +++ b/assets/shaders/Mandel.frag.glsl @@ -4,15 +4,18 @@ precision highp float; uniform vec2 u_resolution; uniform float u_time; +uniform float u_speed; void main(void) { vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / u_resolution.xy; p.x *= u_resolution.x/u_resolution.y; - float zoo = .62+.38*sin(.1*u_time); - float coa = cos( 0.1*(1.0-zoo)*u_time ); - float sia = sin( 0.1*(1.0-zoo)*u_time ); + float time = u_time * u_speed; + + float zoo = .62+.38*sin(.1*time); + float coa = cos( 0.1*(1.0-zoo)*time ); + float sia = sin( 0.1*(1.0-zoo)*time ); zoo = pow( zoo,8.0); vec2 xy = vec2( p.x*coa-p.y*sia, p.x*sia+p.y*coa); vec2 cc = vec2(-.745,.186) + xy*zoo; diff --git a/assets/shaders/ReliefTunnel.frag.glsl b/assets/shaders/ReliefTunnel.frag.glsl index cee707db..5bd727cf 100644 --- a/assets/shaders/ReliefTunnel.frag.glsl +++ b/assets/shaders/ReliefTunnel.frag.glsl @@ -4,6 +4,7 @@ precision highp float; uniform vec2 u_resolution; uniform float u_time; +uniform float u_speed; uniform sampler2D u_tex0; void main(void) @@ -11,8 +12,10 @@ void main(void) vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / u_resolution.xy; vec2 uv; + float time = u_time * u_speed; + float r = sqrt( dot(p,p) ); - float a = atan(p.y,p.x) + 0.5*sin(0.5*r-0.5*u_time); + float a = atan(p.y,p.x) + 0.5*sin(0.5*r-0.5*time); float s = 0.5 + 0.5*cos(7.0*a); s = smoothstep(0.0,1.0,s); @@ -20,7 +23,7 @@ void main(void) s = smoothstep(0.0,1.0,s); s = smoothstep(0.0,1.0,s); - uv.x = u_time + 1.0/( r + .2*s); + uv.x = time + 1.0/( r + .2*s); uv.y = 3.0*a/3.1416; float w = (0.5 + 0.5*s)*r*r; diff --git a/assets/shaders/SquareTunnel.frag.glsl b/assets/shaders/SquareTunnel.frag.glsl index 51ef7b7c..1298a03a 100644 --- a/assets/shaders/SquareTunnel.frag.glsl +++ b/assets/shaders/SquareTunnel.frag.glsl @@ -4,6 +4,7 @@ precision highp float; uniform vec2 u_resolution; uniform float u_time; +uniform float u_speed; uniform sampler2D u_tex0; void main(void) @@ -12,7 +13,7 @@ void main(void) vec2 uv; float r = pow( pow(p.x*p.x,16.0) + pow(p.y*p.y,16.0), 1.0/32.0 ); - uv.x = .5*u_time + 0.5/r; + uv.x = 0.5*u_time*u_speed + 0.5/r; uv.y = 1.0*atan(p.y,p.x)/3.1416; vec3 col = texture2D(u_tex0,uv).xyz; diff --git a/assets/shaders/Star.frag.glsl b/assets/shaders/Star.frag.glsl index f63fe605..f61f43c9 100644 --- a/assets/shaders/Star.frag.glsl +++ b/assets/shaders/Star.frag.glsl @@ -3,6 +3,7 @@ precision highp float; #endif uniform float u_time; +uniform float u_speed; uniform vec2 u_resolution; uniform sampler2D u_tex0; @@ -10,17 +11,19 @@ void main(void) { vec2 uv; + float time = u_time * u_speed; + vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / u_resolution.xy; float a = atan(p.y,p.x); float r = sqrt(dot(p,p)); - float s = r * (1.0+0.8*cos(u_time*1.0)); + float s = r * (1.0+0.8*cos(time*1.0)); - uv.x = .02*p.y+.03*cos(-u_time+a*3.0)/s; - uv.y = .1*u_time +.02*p.x+.03*sin(-u_time+a*3.0)/s; + uv.x = .02*p.y+.03*cos(-time+a*3.0)/s; + uv.y = .1*time +.02*p.x+.03*sin(-time+a*3.0)/s; float w = .9 + pow(max(1.5-r,0.0),4.0); - w*=0.6+0.4*cos(u_time+3.0*a); + w*=0.6+0.4*cos(time+3.0*a); vec3 col = texture2D(u_tex0,uv).xyz; diff --git a/assets/shaders/Tunnel.frag.glsl b/assets/shaders/Tunnel.frag.glsl index 9deb52fb..def28e2e 100644 --- a/assets/shaders/Tunnel.frag.glsl +++ b/assets/shaders/Tunnel.frag.glsl @@ -4,6 +4,7 @@ precision highp float; uniform vec2 u_resolution; uniform float u_time; +uniform float u_speed; uniform sampler2D u_tex0; void main(void) @@ -14,7 +15,7 @@ void main(void) float a = atan(p.y,p.x); float r = sqrt(dot(p,p)); - uv.x = .75*u_time+.1/r; + uv.x = .75*u_time*u_speed + .1/r; uv.y = a/3.1416; vec3 col = texture2D(u_tex0,uv).xyz; diff --git a/assets/shaders/Twist.frag.glsl b/assets/shaders/Twist.frag.glsl index b7477747..ab66cdae 100644 --- a/assets/shaders/Twist.frag.glsl +++ b/assets/shaders/Twist.frag.glsl @@ -4,6 +4,7 @@ precision highp float; uniform vec2 u_resolution; uniform float u_time; +uniform float u_speed; uniform sampler2D u_tex0; void main(void) @@ -14,8 +15,10 @@ void main(void) float a = atan(p.y,p.x); float r = sqrt(dot(p,p)); - uv.x = r - .25*u_time; - uv.y = cos(a*5.0 + 2.0*sin(u_time+7.0*r)) ; + float time = u_time * u_speed; + + uv.x = r - .25*time; + uv.y = cos(a*5.0 + 2.0*sin(time+7.0*r)) ; vec3 col = (.5+.5*uv.y)*texture2D(u_tex0,uv).xyz; diff --git a/assets/shaders/ZInvert.frag.glsl b/assets/shaders/ZInvert.frag.glsl index b1fd1748..1566b881 100644 --- a/assets/shaders/ZInvert.frag.glsl +++ b/assets/shaders/ZInvert.frag.glsl @@ -4,6 +4,7 @@ precision highp float; uniform vec2 u_resolution; uniform float u_time; +uniform float u_speed; uniform sampler2D u_tex0; void main(void) @@ -11,11 +12,13 @@ void main(void) vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / u_resolution.xy; vec2 uv; + float time = u_time * u_speed; + float a = atan(p.y,p.x); float r = sqrt(dot(p,p)); - uv.x = cos(0.6+u_time) + cos(cos(1.2+u_time)+a)/r; - uv.y = cos(0.3+u_time) + sin(cos(2.0+u_time)+a)/r; + uv.x = cos(0.6+time) + cos(cos(1.2+time)+a)/r; + uv.y = cos(0.3+time) + sin(cos(2.0+time)+a)/r; vec3 col = texture2D(u_tex0,uv*.25).xyz; diff --git a/assets/shaders/radialBlur.frag.glsl b/assets/shaders/radialBlur.frag.glsl index 673d082a..c4520e58 100644 --- a/assets/shaders/radialBlur.frag.glsl +++ b/assets/shaders/radialBlur.frag.glsl @@ -3,15 +3,14 @@ precision highp float; uniform vec2 u_resolution; uniform float u_time; -uniform vec4 color; +uniform float u_speed; uniform sampler2D u_tex0; vec3 deform( in vec2 p ) { vec2 uv; - //float time = color.x; - float time = u_time; + float time = u_time * u_speed; vec2 q = vec2( sin(1.1*time+p.x),sin(1.2*time+p.y) ); float a = atan(q.y,q.x); diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js index 12e18f7f..7b880a2e 100644 --- a/js/lib/rdge/materials/fly-material.js +++ b/js/lib/rdge/materials/fly-material.js @@ -36,7 +36,7 @@ var FlyMaterial = function FlyMaterial() { // Material Property Accessors /////////////////////////////////////////////////////////////////////// this.isAnimated = function() { return true; }; - this.getShaderDef = function() { return flyMaterialDef; } + this.getShaderDef = function() { return flyMaterialDef; }; /////////////////////////////////////////////////////////////////////// // Methods diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index e75d74ba..e1c19145 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-material.js @@ -14,7 +14,7 @@ var MandelMaterial = function MandelMaterial() { this._name = "MandelMaterial"; this._shaderName = "mandel"; - this._texMap = 'assets/images/rocky-normal.jpg'; + this._defaultTexMap = 'assets/images/rocky-normal.jpg'; this._time = 0.0; this._dTime = 0.01; @@ -27,32 +27,23 @@ var MandelMaterial = function MandelMaterial() { /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// + var u_tex0_index = 0, u_speed_index = 1; + this._propNames = ["u_tex0", "u_speed" ]; + this._propLabels = ["Texture map", "Speed" ]; + this._propTypes = ["file", "float" ]; + this._propValues = []; + this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); + this._propValues[this._propNames[u_speed_index]] = 1.0; /////////////////////////////////////////////////////////////////////// - this.isAnimated = function() { - return true; - }; + this.isAnimated = function() { return true; }; + this.getShaderDef = function() { return MandelMaterialDef; } /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// // duplcate method requirde - this.dup = function( world ) { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new material - var newMat = new MandelMaterial(); - - // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); - - return newMat; - }; this.init = function( world ) { // save the world @@ -72,27 +63,11 @@ var MandelMaterial = function MandelMaterial() { this._shader['default'].u_time.set( [this._time] ); } - // set up the texture - var texMapName = this._propValues[this._propNames[0]]; - this._glTex = new Texture( world, texMapName ); - // set the shader values in the shader + this.setShaderValues(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); this.update( 0 ); }; - - this.update = function( time ) { - var material = this._materialNode; - if (material) { - var technique = material.shaderProgram['default']; - var renderer = RDGE.globals.engine.getContext().renderer; - if (renderer && technique) { - if (this._shader && this._shader['default']) - this._shader['default'].u_time.set( [this._time] ); - this._time = time; - } - } - }; }; /////////////////////////////////////////////////////////////////////////////////////// @@ -124,6 +99,7 @@ var MandelMaterialDef = { 'u_tex0': { 'type' : 'tex2d' }, 'u_time' : { 'type' : 'float' }, + 'u_speed' : { 'type' : 'float' }, 'u_resolution' : { 'type' : 'vec2' }, }, diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 1db207d6..c1e5524c 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -24,7 +24,7 @@ var PlasmaMaterial = function PlasmaMaterial() { /////////////////////////////////////////////////////////////////////// // Properties /////////////////////////////////////////////////////////////////////// - this._propNames = ["wave", "wave1", "wave2", "speed"]; + this._propNames = ["u_wave", "u_wave1", "u_wave2", "u_speed"]; this._propLabels = ["Wave", "Wave 1", "Wave 2", "Speed"]; this._propTypes = ["float", "float", "float", "float"]; @@ -39,68 +39,17 @@ var PlasmaMaterial = function PlasmaMaterial() { // Property Accessors /////////////////////////////////////////////////////////////////////// this.getShaderName = function() { return this._shaderName; }; - this.isAnimated = function() { return true; }; + this.getShaderDef = function() { return plasmaShaderDef; }; /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - // duplcate method requirde - this.dup = function (world) { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new material - var newMat = new PlasmaMaterial(); - - // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); - - return newMat; - }; - - this.setProperty = function( prop, value ) - { - // make sure we have legitimate imput - var ok = this.validateProperty( prop, value ); - if (!ok) { - console.log( "invalid property in Water Material:" + prop + " : " + value ); - } - - switch (prop) - { - case "wave": - this._wave = value; - break; - - case "wave1": - this._wave1 = value; - break; - - case "wave2": - this._wave2 = value; - break; - - case "speed": - this._speed = value; - break; - } - - this.updateParameters(); - }; - - /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// // duplcate method requirde - this.dup = function() { - return new PlasmaMaterial(); - }; this.init = function( world) { @@ -114,67 +63,23 @@ var PlasmaMaterial = function PlasmaMaterial() { // set the default value this._time = 0; this._shader['default'].u_time.set( [this._time] ); - this._shader['default'].u_speed.set( [this._speed] ); - - this._shader['default'].u_wave.set( [this._wave] ); - this._shader['default'].u_wave1.set( [this._wave1] ); - this._shader['default'].u_wave2.set( [this._wave2] ); // set up the material node this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); - }; - this.updateParameters = function() - { - this._propValues[ this._propNames[0] ] = this._wave; - this._propValues[ this._propNames[1] ] = this._wave1; - this._propValues[ this._propNames[2] ] = this._wave2; - this._propValues[ this._propNames[3] ] = this._speed; - - var material = this._materialNode; - if (material) { - var technique = material.shaderProgram['default']; - var renderer = RDGE.globals.engine.getContext().renderer; - if (renderer && technique) { - technique.u_wave.set( [this._wave] ); - technique.u_wave1.set( [this._wave1] ); - technique.u_wave2.set( [this._wave2] ); - technique.u_speed.set( [this._speed] ); - } + this._time = 0; + if (this._shader && this._shader['default']) { + this._shader['default'].u_time.set( [this._time] ); } + + this.setShaderValues(); }; this.update = function( time ) { this._shader['default'].u_time.set( [this._time] ); this._time += this._dTime; }; - - this.exportJSON = function() - { - var jObj = - { - 'material' : this.getShaderName(), - 'name' : this.getName(), - 'speed' : this._speed, - 'dTime' : this._dTime, - 'wave' : this._wave, - 'wave1' : this._wave1, - 'wave2' : this._wave2 - }; - - return jObj; - }; - - this.importJSON = function( jObj ) - { - this._speed = jObj.speed; - this._dTime = jObj.dTime; - - this._wave = jObj.wave; - this._wave1 = jObj.wave1; - this._wave2 = jObj.wave2; - }; }; /////////////////////////////////////////////////////////////////////////////////////// diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index ca4b940b..2c0fc04c 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -30,6 +30,8 @@ var PulseMaterial = function PulseMaterial() this._time = 0.0; this._dTime = 0.01; + this._glTextures = []; + /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 61ae0017..57f4a6e0 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -4,7 +4,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; var Material = require("js/lib/rdge/materials/material").Material; var RadialBlurMaterial = function RadialBlurMaterial() { @@ -14,8 +13,8 @@ var RadialBlurMaterial = function RadialBlurMaterial() { this._name = "RadialBlurMaterial"; this._shaderName = "radialBlur"; - this._texMap = 'assets/images/cubelight.png'; - this._color = [1, 0, 0, 1]; + this._defaultTexMap = 'assets/images/cubelight.png'; + this._defaultColor = [1, 0, 0, 1]; this._time = 0.0; this._dTime = 0.01; @@ -23,68 +22,27 @@ var RadialBlurMaterial = function RadialBlurMaterial() { /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// - this.getName = function () { return this._name; }; - this.getShaderName = function () { return this._shaderName; }; - - this.getTextureMap = function () { return this._texMap.slice(0); }; - this.setTextureMap = function (m) { this._propValues[this._propNames[0]] = m.slice(0); this.updateTexture(); }; - - this.isAnimated = function () { return true; }; + this.getName = function () { return this._name; }; + this.getShaderName = function () { return this._shaderName; }; + this.getShaderDef = function() { return radialBlurMaterialDef; }; + this.isAnimated = function () { return true; }; /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["texmap", "color"]; - this._propLabels = ["Texture map", "Color"]; - this._propTypes = ["file", "color"]; + this._propNames = ["u_tex0", "u_speed"]; + this._propLabels = ["Texture map", "Speed" ]; + this._propTypes = ["file", "float" ]; this._propValues = []; - this._propValues[this._propNames[0]] = this._texMap.slice(0); - this._propValues[this._propNames[1]] = this._color.slice(0); - - this.setProperty = function (prop, value) { - // make sure we have legitimate imput - var ok = this.validateProperty(prop, value); - if (!ok) { - console.log("invalid property in Radial Gradient Material:" + prop + " : " + value); - } - - switch (prop) { - case "texmap": - this.setTextureMap(value); - break; - - case "color": - this._propValues[prop] = value.slice(0); - if (this._shader && this._shader['default']) { - this._shader['default'][prop].set(value); - } - break; - } - }; + this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0); + this._propValues[this._propNames[1]] = 1.0; /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// - // duplicate method required - this.dup = function () { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new material - var newMat = new RadialBlurMaterial(); - - // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); - - return newMat; - }; - this.init = function (world) { // save the world if (world) this.setWorld(world); @@ -101,31 +59,13 @@ var RadialBlurMaterial = function RadialBlurMaterial() { this._time = 0; if (this._shader && this._shader['default']) this._shader['default'].u_time.set([this._time]); - this.setProperty("color", [this._time, 0, 0, 1]); // set the shader values in the shader - this.updateTexture(); + this.setShaderValues(); this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); this.update(0); }; - this.updateTexture = function () { - var material = this._materialNode; - if (material) { - var technique = material.shaderProgram['default']; - var renderer = RDGE.globals.engine.getContext().renderer; - if (renderer && technique) { - var texMapName = this._propValues[this._propNames[0]]; - var tex = renderer.getTextureByName(texMapName, 'REPEAT'); - // if (tex) - // { - // var res = [tex.image.naturalWidth, tex.image.naturalHeight]; - // this.setResoloution( res ); - // } - technique.u_tex0.set(tex); - } - } - }; this.update = function () { var material = this._materialNode; @@ -136,11 +76,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() { if (this._shader && this._shader['default']) { this._shader['default'].u_time.set([this._time]); } - - var color = this.getProperty("color"); - color[0] = this._time; - this.setProperty("color", color); - //console.log( "update color to: " + color ); this._time += this._dTime; } } @@ -156,34 +91,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() { } } }; - - this.exportJSON = function () { - var jObj = - { - 'material': this.getShaderName(), - 'name': this.getName(), - 'color': this._propValues["color"], - 'texture': this._propValues[this._propNames[0]] - }; - - return jObj; - }; - - this.importJSON = function (jObj) { - if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); - this.setName(jObj.name); - - var rtnStr; - try { - this._propValues[this._propNames[0]] = jObj.texture; - this.updateTexture(); - } - catch (e) { - throw new Error("could not import material: " + importStr); - } - - return rtnStr; - }; }; /////////////////////////////////////////////////////////////////////////////////////// @@ -215,8 +122,8 @@ var radialBlurMaterialDef = { 'u_tex0': { 'type': 'tex2d' }, 'u_time': { 'type': 'float' }, + 'u_speed': { 'type': 'float' }, 'u_resolution': { 'type': 'vec2' }, - 'color': { 'type': 'vec4' } }, // render states diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index 67a85041..b5ffd01a 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js @@ -15,201 +15,49 @@ var RadialGradientMaterial = function RadialGradientMaterial() { this._name = "RadialGradientMaterial"; this._shaderName = "radialGradient"; - 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; + this._defaultColor1 = [1, 0, 0, 1]; + this._defaultColor2 = [0, 1, 0, 1]; + this._defaultColor3 = [0, 0, 1, 1]; + this._defaultColor4 = [0, 1, 1, 1]; + this._defaultColorStop1 = 0.0; + this._defaultColorStop2 = 0.3; + this._defaultColorStop3 = 0.6; + this._defaultColorStop4 = 1.0; + // this._defaultColorCount = 4; this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// - this.getName = function () { - return this._name; - }; - - this.getShaderName = function () { - return this._shaderName; - }; - - this.getColor1 = function () { - return this._color1; - }; - - this.setColor1 = function (c) { - this._color1 = c.slice(); - this._propValues[this._propNames[0]] = this._color1.slice(0); - 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(); - this._propValues[this._propNames[1]] = this._color2.slice(0); - 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(); - this._propValues[this._propNames[2]] = this._color3.slice(0); - 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(); - this._propValues[this._propNames[3]] = this._color4.slice(0); - 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 false; - }; + + this.isAnimated = function () { return false; }; + this.getShaderDef = function() { return radialGradientMaterialDef; }; /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["color1", "color2", "color3", "color4", "colorStop1", "colorStop2", "colorStop3", "colorStop4" ]; + this._propNames = ["u_color1", "u_color2", "u_color3", "u_color4", "u_colorStop1", "u_colorStop2", "u_colorStop3", "u_colorStop4" ]; this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4" ]; this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float" ]; this._propValues = []; - this._propValues[this._propNames[0]] = this._color1.slice(0); - this._propValues[this._propNames[1]] = this._color2.slice(0); - this._propValues[this._propNames[2]] = this._color3.slice(0); - this._propValues[this._propNames[3]] = this._color4.slice(0); + this._propValues[this._propNames[0]] = this._defaultColor1.slice(0); + this._propValues[this._propNames[1]] = this._defaultColor2.slice(0); + this._propValues[this._propNames[2]] = this._defaultColor3.slice(0); + this._propValues[this._propNames[3]] = this._defaultColor4.slice(0); - this._propValues[this._propNames[4]] = this._colorStop1; - this._propValues[this._propNames[5]] = this._colorStop2; - this._propValues[this._propNames[6]] = this._colorStop3; - this._propValues[this._propNames[7]] = this._colorStop4; - - this.setProperty = function (prop, value) { - if (prop === "color") prop = "color1"; - - // make sure we have legitimate imput - var ok = this.validateProperty(prop, value); - if (!ok) { - console.log("invalid property in Radial Gradient Material:" + prop + " : " + value); - } - - switch (prop) { - case "color1": this.setColor1(value); break; - case "color2": this.setColor2(value); break; - case "color3": this.setColor3(value); break; - case "color4": this.setColor4(value); break; - case "colorStop1": this.setColorStop1(value); break; - case "colorStop2": this.setColorStop2(value); break; - case "colorStop3": this.setColorStop3(value); break; - case "colorStop4": this.setColorStop4(value); break; - } - - //this.updateValuesInShader(); - }; + this._propValues[this._propNames[4]] = this._defaultColorStop1; + this._propValues[this._propNames[5]] = this._defaultColorStop2; + this._propValues[this._propNames[6]] = this._defaultColorStop3; + this._propValues[this._propNames[7]] = this._defaultColorStop4; /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// - // duplcate method requirde - this.dup = function () { - // allocate a new material - var newMat = new RadialGradientMaterial(); - - // copy over the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties( propNames, propValues, propTypes, propLabels); - var n = propNames.length; - for (var i=0; i