From 9e812f35ffa751e9215c5427c0c44005bd357924 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 7 Mar 2012 17:18:38 -0800 Subject: Fixed a few problems with Plasma material. --- assets/shaders/plasma.frag.glsl | 4 +--- js/document/html-document.js | 1 - js/lib/rdge/materials/plasma-material.js | 30 +++++++--------------------- js/lib/rdge/runtime/RuntimeGeomObj.js | 4 +++- js/lib/rdge/runtime/RuntimeMaterial.js | 34 ++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/assets/shaders/plasma.frag.glsl b/assets/shaders/plasma.frag.glsl index 2ab8f49c..248288a6 100644 --- a/assets/shaders/plasma.frag.glsl +++ b/assets/shaders/plasma.frag.glsl @@ -22,11 +22,9 @@ void main(void) { float x = v_uv.x ; float y = v_uv.y ; - float time = color.x; + float time = u_time; float wave = (cos(time + y / 0.2 + cos(x / 0.3 + cos((y / 0.1))))); float wave1 = (sin(abs(wave + y/0.6))); float wave2 = (sin(abs(wave1 + y/0.8))); - float tmp = u_time * 0.1; gl_FragColor = vec4( abs(vec3(wave2,wave1,wave)),1.0); - //gl_FragColor = color; } diff --git a/js/document/html-document.js b/js/document/html-document.js index 44f90d41..0a3497f1 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -190,7 +190,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { var loadForRuntime = true; if (loadForRuntime) { - //console.log( "load canvas data: " , value ); var cdm = new CanvasDataManager(); cdm.loadGLData(elt, value, NJUtils); } diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 62d0db70..86b1a93c 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -17,8 +17,6 @@ var PlasmaMaterial = function PlasmaMaterial() { this._dTime = 0.01; this._speed = 1.0; - this._color = [1,0,0,1]; - /////////////////////////////////////////////////////////////////////// // Property Accessors @@ -30,20 +28,12 @@ var PlasmaMaterial = function PlasmaMaterial() { /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["color"]; - this._propLabels = ["Color"]; - this._propTypes = ["color"]; - this._propValues = []; - - this._propValues[ this._propNames[0] ] = this._color; - - this.setProperty = function( prop, value ) { - // make sure we have legitimate imput - if (this.validateProperty( prop, value )) { - this._color = value.slice(0); - this._shader['default'][prop].set(value); - } + + this.setProperty = function( prop, value ) + { + // plasma has no properties }; + /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// @@ -65,8 +55,7 @@ var PlasmaMaterial = function PlasmaMaterial() { // set the default value this._time = 0; - this._shader['default'].u_time = this._time; - this.setProperty( "color", [this._time, 0, 0, 1] ); + this._shader['default'].u_time.set( [this._time] ); // set up the material node this._materialNode = createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); @@ -74,11 +63,7 @@ var PlasmaMaterial = function PlasmaMaterial() { }; this.update = function( time ) { - this._shader['default'].u_time = this._time; - var color = this.getProperty( "color" ); - color[0] = this._time; - this.setProperty( "color", color ); - //console.log( "update color to: " + color ); + this._shader['default'].u_time.set( [this._time] ); this._time += this._dTime; } @@ -112,7 +97,6 @@ var plasmaShaderDef = 'params' : { 'u_time' : { 'type' : 'float' }, - 'color' : { 'type' : 'vec4' } }, // render states diff --git a/js/lib/rdge/runtime/RuntimeGeomObj.js b/js/lib/rdge/runtime/RuntimeGeomObj.js index 5b212dce..93d4d9a1 100644 --- a/js/lib/rdge/runtime/RuntimeGeomObj.js +++ b/js/lib/rdge/runtime/RuntimeGeomObj.js @@ -11,7 +11,8 @@ var RuntimeFlatMaterial = RuntimeMaterial.RuntimeFlatMaterial, RuntimeLinearGradientMaterial = RuntimeMaterial.RuntimeLinearGradientMaterial, RuntimeBumpMetalMaterial = RuntimeMaterial.RuntimeBumpMetalMaterial, RuntimeUberMaterial = RuntimeMaterial.RuntimeUberMaterial, - RuntimePulseMaterial = RuntimeMaterial.RuntimePulseMaterial; + RuntimePulseMaterial = RuntimeMaterial.RuntimePulseMaterial, + RuntimePlasmaMaterial = RuntimeMaterial.RuntimePlasmaMaterial; @@ -94,6 +95,7 @@ var RuntimeGeomObj = function RuntimeGeomObj() case "linearGradient": mat = new RuntimeLinearGradientMaterial(); break; case "bumpMetal": mat = new RuntimeBumpMetalMaterial(); break; case "uber": mat = new RuntimeUberMaterial(); break; + case "plasma": mat = new RuntimePlasmaMaterial(); break; case "deform": case "water": diff --git a/js/lib/rdge/runtime/RuntimeMaterial.js b/js/lib/rdge/runtime/RuntimeMaterial.js index 294c4787..1bbbc3b1 100644 --- a/js/lib/rdge/runtime/RuntimeMaterial.js +++ b/js/lib/rdge/runtime/RuntimeMaterial.js @@ -54,6 +54,10 @@ var RuntimeMaterial = function RuntimeMaterial( world ) { } + this.import = function( importStr ) + { + } + this.getPropertyFromString = function( prop, str ) { var index = str.indexOf( prop ); @@ -304,6 +308,35 @@ function RuntimeUberMaterial() { } +function RuntimePlasmaMaterial() +{ + // inherit the members of RuntimeMaterial + this.inheritedFrom = RuntimeMaterial; + this.inheritedFrom(); + + this.init = function( ) + { + this.update(); + } + + this.update = function( time ) + { + var material = this._materialNode; + if (material) + { + var technique = material.shaderProgram.default; + var renderer = g_Engine.getContext().renderer; + if (renderer && technique) + { + if (this._shader && this._shader.default) + this._shader.default.u_time.set( [this._time] ); + this._time += this._dTime; + if (this._time > 200.0) this._time = 0.0; + } + } + } +} + if (typeof exports === "object") { @@ -314,4 +347,5 @@ if (typeof exports === "object") exports.RuntimeLinearGradientMaterial = RuntimeLinearGradientMaterial; exports.RuntimeBumpMetalMaterial = RuntimeBumpMetalMaterial; exports.RuntimeUberMaterial = RuntimeUberMaterial; + exports.RuntimePlasmaMaterial = RuntimePlasmaMaterial; } -- cgit v1.2.3