diff options
author | hwc487 | 2012-05-31 17:07:10 -0700 |
---|---|---|
committer | hwc487 | 2012-05-31 17:07:10 -0700 |
commit | 335ce503996e3ccbd2909086328d0a31fbd03370 (patch) | |
tree | e54d588e0993572f1d794ff5b75a5082aa2035b1 | |
parent | 129b5282ef35f320ea39d1878d2b5f77ae73a3e2 (diff) | |
download | ninja-335ce503996e3ccbd2909086328d0a31fbd03370.tar.gz |
Added the flag shader to the runtime.
-rw-r--r-- | assets/canvas-runtime.js | 82 | ||||
-rw-r--r-- | assets/descriptor.json | 2 | ||||
-rw-r--r-- | js/io/system/ninjalibrary.json | 2 | ||||
-rw-r--r-- | js/lib/rdge/materials/flag-material.js | 31 |
4 files changed, 113 insertions, 4 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index f4bfa0ae..918dffdc 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -580,9 +580,17 @@ NinjaCvsRt.RuntimeGeomObj = Object.create(Object.prototype, { | |||
580 | case "zinvert": | 580 | case "zinvert": |
581 | case "keleidoscope": | 581 | case "keleidoscope": |
582 | case "radialBlur": | 582 | case "radialBlur": |
583 | case "pulse": mat = Object.create(NinjaCvsRt.RuntimePulseMaterial, {}); break; | 583 | case "pulse": |
584 | mat = Object.create(NinjaCvsRt.RuntimePulseMaterial, {}); | ||
585 | break; | ||
584 | 586 | ||
585 | case "twistVert": mat = Object.create(NinjaCvsRt.RuntimeTwistVertMaterial, {}); break; | 587 | case "twistVert": |
588 | mat = Object.create(NinjaCvsRt.RuntimeTwistVertMaterial, {}); | ||
589 | break; | ||
590 | |||
591 | case "flag": | ||
592 | mat = Object.create(NinjaCvsRt.RuntimeFlagMaterial, {}); | ||
593 | break; | ||
586 | 594 | ||
587 | default: | 595 | default: |
588 | console.log( "material type: " + shaderName + " is not supported" ); | 596 | console.log( "material type: " + shaderName + " is not supported" ); |
@@ -1381,6 +1389,7 @@ NinjaCvsRt.RuntimeFlatMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1381 | 1389 | ||
1382 | }); | 1390 | }); |
1383 | 1391 | ||
1392 | |||
1384 | NinjaCvsRt.RuntimeTwistVertMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | 1393 | NinjaCvsRt.RuntimeTwistVertMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { |
1385 | _name: { value: "TwistVertMaterial", writable: true }, | 1394 | _name: { value: "TwistVertMaterial", writable: true }, |
1386 | _shaderName: { value: "twistVert", writable: true }, | 1395 | _shaderName: { value: "twistVert", writable: true }, |
@@ -1410,7 +1419,7 @@ NinjaCvsRt.RuntimeTwistVertMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, | |||
1410 | 1419 | ||
1411 | init: { | 1420 | init: { |
1412 | value: function(world) { | 1421 | value: function(world) { |
1413 | var material = this._materialNode; | 1422 | var material = this._materialNode; |
1414 | if (material) | 1423 | if (material) |
1415 | { | 1424 | { |
1416 | var technique = material.shaderProgram["twistMe"]; | 1425 | var technique = material.shaderProgram["twistMe"]; |
@@ -1488,6 +1497,7 @@ NinjaCvsRt.RuntimePulseMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1488 | if (tex) | 1497 | if (tex) |
1489 | technique.u_tex0.set( tex ); | 1498 | technique.u_tex0.set( tex ); |
1490 | 1499 | ||
1500 | this._shader["default"].u_speed.set( [1.0] ); | ||
1491 | this._shader["default"].u_time.set( [this._time] ); | 1501 | this._shader["default"].u_time.set( [this._time] ); |
1492 | } | 1502 | } |
1493 | } | 1503 | } |
@@ -1516,6 +1526,72 @@ NinjaCvsRt.RuntimePulseMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1516 | } | 1526 | } |
1517 | }); | 1527 | }); |
1518 | 1528 | ||
1529 | |||
1530 | NinjaCvsRt.RuntimeFlagMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | ||
1531 | _name: { value: "FlagMaterial", writable: true }, | ||
1532 | _shaderName: { value: "flag", writable: true }, | ||
1533 | |||
1534 | // default values | ||
1535 | _texMap: { value: 'assets/images/cubelight.png', writable: true }, | ||
1536 | _speed: { value: 1.0, writable: true }, | ||
1537 | _waveWidth: { value: 1.0, writable: true }, | ||
1538 | _waveHeight: { value: 1.0, writable: true }, | ||
1539 | _dTime: { value: 0.1, writable: true }, | ||
1540 | |||
1541 | importJSON: { | ||
1542 | value: function(jObj) { | ||
1543 | this._texMap = jObj.texMap; | ||
1544 | this._waveWidth = jObj.waveWidth; | ||
1545 | this._waveHeight = jObj.waveHeight; | ||
1546 | this._speed = jObj.speed; | ||
1547 | } | ||
1548 | }, | ||
1549 | |||
1550 | init: { | ||
1551 | value: function(world) { | ||
1552 | if (this._shader) { | ||
1553 | var material = this._materialNode; | ||
1554 | if (material) | ||
1555 | { | ||
1556 | var technique = material.shaderProgram['default']; | ||
1557 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
1558 | if (renderer && technique) | ||
1559 | { | ||
1560 | |||
1561 | if (this._shader && this._shader['default']) { | ||
1562 | var wrap = 'REPEAT', mips = true; | ||
1563 | var tex = renderer.getTextureByName(this._texMap, wrap, mips ); | ||
1564 | if (tex) technique.u_tex0.set( tex ); | ||
1565 | |||
1566 | technique.u_speed.set( [this._speed] ); | ||
1567 | technique.u_waveWidth.set( [this._waveWidth] ); | ||
1568 | technique.u_waveHeight.set( [this._waveHeight] ); | ||
1569 | } | ||
1570 | } | ||
1571 | } | ||
1572 | } | ||
1573 | } | ||
1574 | }, | ||
1575 | |||
1576 | update: { | ||
1577 | value: function(time) { | ||
1578 | var material = this._materialNode; | ||
1579 | if (material) | ||
1580 | { | ||
1581 | var technique = material.shaderProgram['default']; | ||
1582 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
1583 | if (renderer && technique) | ||
1584 | { | ||
1585 | if (this._shader && this._shader['default']) { | ||
1586 | this._shader['default'].u_time.set( [this._time] ); | ||
1587 | } | ||
1588 | this._time += this._dTime * this._speed; | ||
1589 | } | ||
1590 | } | ||
1591 | } | ||
1592 | } | ||
1593 | }); | ||
1594 | |||
1519 | NinjaCvsRt.RuntimeRadialGradientMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | 1595 | NinjaCvsRt.RuntimeRadialGradientMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { |
1520 | _name: { value: "RadialGradientMaterial", writable: true }, | 1596 | _name: { value: "RadialGradientMaterial", writable: true }, |
1521 | _shaderName: { value: "radialGradient", writable: true }, | 1597 | _shaderName: { value: "radialGradient", writable: true }, |
diff --git a/assets/descriptor.json b/assets/descriptor.json index 85fbc996..2873205f 100644 --- a/assets/descriptor.json +++ b/assets/descriptor.json | |||
@@ -24,6 +24,7 @@ | |||
24 | "images/paris.png", | 24 | "images/paris.png", |
25 | "images/powderblue.png", | 25 | "images/powderblue.png", |
26 | "images/raiders.png", | 26 | "images/raiders.png", |
27 | "images/us_flag.png", | ||
27 | "shaders/Basic.frag.glsl", | 28 | "shaders/Basic.frag.glsl", |
28 | "shaders/TwistVert.vert.glsl", | 29 | "shaders/TwistVert.vert.glsl", |
29 | "shaders/Basic.vert.glsl", | 30 | "shaders/Basic.vert.glsl", |
@@ -31,6 +32,7 @@ | |||
31 | "shaders/Deform.frag.glsl", | 32 | "shaders/Deform.frag.glsl", |
32 | "shaders/Water2.frag.glsl", | 33 | "shaders/Water2.frag.glsl", |
33 | "shaders/Flag.vert.glsl", | 34 | "shaders/Flag.vert.glsl", |
35 | "shaders/Flag.frag.glsl", | ||
34 | "shaders/ZInvert.frag.glsl", | 36 | "shaders/ZInvert.frag.glsl", |
35 | "shaders/Fly.frag.glsl", | 37 | "shaders/Fly.frag.glsl", |
36 | "shaders/linearGradient.frag.glsl", | 38 | "shaders/linearGradient.frag.glsl", |
diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json index 9547c1e8..bee603ae 100644 --- a/js/io/system/ninjalibrary.json +++ b/js/io/system/ninjalibrary.json | |||
@@ -1,6 +1,6 @@ | |||
1 | { | 1 | { |
2 | "libraries": [ | 2 | "libraries": [ |
3 | {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.8.0.0"}, | 3 | {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.8.0.0"}, |
4 | {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.6.4"} | 4 | {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.6.6"} |
5 | ] | 5 | ] |
6 | } \ No newline at end of file | 6 | } \ No newline at end of file |
diff --git a/js/lib/rdge/materials/flag-material.js b/js/lib/rdge/materials/flag-material.js index fa844cc3..d1788fb8 100644 --- a/js/lib/rdge/materials/flag-material.js +++ b/js/lib/rdge/materials/flag-material.js | |||
@@ -160,6 +160,37 @@ var FlagMaterial = function FlagMaterial() { | |||
160 | this.updateTexture(); | 160 | this.updateTexture(); |
161 | this.update( 0 ); | 161 | this.update( 0 ); |
162 | } | 162 | } |
163 | |||
164 | this.exportJSON = function () { | ||
165 | var jObj = | ||
166 | { | ||
167 | 'material' : this.getShaderName(), | ||
168 | 'name' : this.getName(), | ||
169 | |||
170 | 'texMap' : this._propValues[this._propNames[0]], | ||
171 | 'waveWidth' : this._propValues[this._propNames[1]], | ||
172 | 'waveHeight' : this._propValues[this._propNames[2]], | ||
173 | 'speed' : this._propValues[this._propNames[3]] | ||
174 | }; | ||
175 | |||
176 | return jObj; | ||
177 | }; | ||
178 | |||
179 | this.importJSON = function (jObj) { | ||
180 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); | ||
181 | this.setName(jObj.name); | ||
182 | |||
183 | try { | ||
184 | |||
185 | this._texMap = this._propValues[this._propNames[0]] = jObj.texMap; | ||
186 | this._waveWidth = this._propValues[this._propNames[1]] = jObj.waveWidth; | ||
187 | this._waveHeight = this._propValues[this._propNames[2]] = jObj.waveHeight; | ||
188 | this._speed = this._propValues[this._propNames[3]] = jObj.speed; | ||
189 | } | ||
190 | catch (e) { | ||
191 | throw new Error("could not import material: " + importStr); | ||
192 | } | ||
193 | }; | ||
163 | }; | 194 | }; |
164 | 195 | ||
165 | /////////////////////////////////////////////////////////////////////////////////////// | 196 | /////////////////////////////////////////////////////////////////////////////////////// |