diff options
author | hwc487 | 2012-06-12 15:31:48 -0700 |
---|---|---|
committer | hwc487 | 2012-06-12 15:31:48 -0700 |
commit | 1d65f82295ea96e019409d08daa5d11e84a44581 (patch) | |
tree | c0d4857862a101f411d23137b486f6741401bb8d /assets | |
parent | d4ca478ad313c6c20834e410ba14ad3a5e7b20bf (diff) | |
download | ninja-1d65f82295ea96e019409d08daa5d11e84a44581.tar.gz |
Runtime material fixes
Diffstat (limited to 'assets')
-rw-r--r-- | assets/canvas-runtime.js | 192 |
1 files changed, 152 insertions, 40 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index 2f728c06..afb9563e 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -596,9 +596,9 @@ NinjaCvsRt.RuntimeGeomObj = Object.create(Object.prototype, { | |||
596 | case "bumpMetal": mat = Object.create(NinjaCvsRt.RuntimeBumpMetalMaterial, {}); break; | 596 | case "bumpMetal": mat = Object.create(NinjaCvsRt.RuntimeBumpMetalMaterial, {}); break; |
597 | case "uber": mat = Object.create(NinjaCvsRt.RuntimeUberMaterial, {}); break; | 597 | case "uber": mat = Object.create(NinjaCvsRt.RuntimeUberMaterial, {}); break; |
598 | case "plasma": mat = Object.create(NinjaCvsRt.RuntimePlasmaMaterial, {}); break; | 598 | case "plasma": mat = Object.create(NinjaCvsRt.RuntimePlasmaMaterial, {}); break; |
599 | case "water": mat = Object.create(NinjaCvsRt.RuntimeWaterMaterial, {}); break; | ||
599 | 600 | ||
600 | case "deform": | 601 | case "deform": |
601 | case "water": | ||
602 | case "paris": | 602 | case "paris": |
603 | case "raiders": | 603 | case "raiders": |
604 | case "tunnel": | 604 | case "tunnel": |
@@ -1438,14 +1438,14 @@ NinjaCvsRt.RuntimeTwistVertMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, | |||
1438 | 1438 | ||
1439 | importJSON: { | 1439 | importJSON: { |
1440 | value: function(jObj) { | 1440 | value: function(jObj) { |
1441 | this._tex0 = jObj.tex0; | 1441 | this._tex0 = jObj.u_tex0; |
1442 | this._tex1 = jObj.tex1; | 1442 | this._tex1 = jObj.u_tex1; |
1443 | 1443 | ||
1444 | this._speed = jObj.speed; | 1444 | this._speed = jObj.speed; |
1445 | 1445 | ||
1446 | this._limit1 = jObj.limit1; | 1446 | this._limit1 = jObj.u_limit1; |
1447 | this._limit2 = jObj.limit2; | 1447 | this._limit2 = jObj.u_limit2; |
1448 | this._twistAmount = jObj.angle; | 1448 | this._twistAmount = jObj.u_twistAmount; |
1449 | } | 1449 | } |
1450 | }, | 1450 | }, |
1451 | 1451 | ||
@@ -1464,7 +1464,7 @@ NinjaCvsRt.RuntimeTwistVertMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, | |||
1464 | tex = renderer.getTextureByName(this._tex1, wrap, mips ); | 1464 | tex = renderer.getTextureByName(this._tex1, wrap, mips ); |
1465 | if (tex) technique.u_tex1.set( tex ); | 1465 | if (tex) technique.u_tex1.set( tex ); |
1466 | 1466 | ||
1467 | technique.u_twistAmount.set( [this._angle] ); | 1467 | technique.u_twistAmount.set( [this._twistAmount] ); |
1468 | technique.u_limit1.set( [this._limit1] ); | 1468 | technique.u_limit1.set( [this._limit1] ); |
1469 | technique.u_limit2.set( [this._limit2] ); | 1469 | technique.u_limit2.set( [this._limit2] ); |
1470 | } | 1470 | } |
@@ -1580,6 +1580,7 @@ NinjaCvsRt.RuntimePulseMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1580 | value: function(jObj) { | 1580 | value: function(jObj) { |
1581 | this._texMap = jObj.u_tex0; | 1581 | this._texMap = jObj.u_tex0; |
1582 | if (jObj.dTime) this._dTime = jObj.dTime; | 1582 | if (jObj.dTime) this._dTime = jObj.dTime; |
1583 | this._speed = jObj.u_speed; | ||
1583 | } | 1584 | } |
1584 | }, | 1585 | }, |
1585 | 1586 | ||
@@ -1595,15 +1596,18 @@ NinjaCvsRt.RuntimePulseMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1595 | if (this._shader && this._shader["default"]) | 1596 | if (this._shader && this._shader["default"]) |
1596 | { | 1597 | { |
1597 | var res = [ renderer.vpWidth, renderer.vpHeight ]; | 1598 | var res = [ renderer.vpWidth, renderer.vpHeight ]; |
1598 | technique.u_resolution.set( res ); | 1599 | if (technique.u_resolution) technique.u_resolution.set( res ); |
1599 | 1600 | ||
1600 | var wrap = 'REPEAT', mips = true; | 1601 | if (this._texMap) |
1601 | var tex = renderer.getTextureByName(this._texMap, wrap, mips ); | 1602 | { |
1602 | if (tex) | 1603 | var wrap = 'REPEAT', mips = true; |
1603 | technique.u_tex0.set( tex ); | 1604 | var tex = renderer.getTextureByName(this._texMap, wrap, mips ); |
1605 | if (tex) | ||
1606 | technique.u_tex0.set( tex ); | ||
1607 | } | ||
1604 | 1608 | ||
1605 | this._shader["default"].u_speed.set( [1.0] ); | 1609 | if (technique.u_speed) this._shader["default"].u_speed.set( [this._speed] ); |
1606 | this._shader["default"].u_time.set( [this._time] ); | 1610 | if (technique.u_time ) this._shader["default"].u_time.set( [this._time] ); |
1607 | } | 1611 | } |
1608 | } | 1612 | } |
1609 | } | 1613 | } |
@@ -1624,7 +1628,6 @@ NinjaCvsRt.RuntimePulseMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1624 | if (this._shader && this._shader["default"]) | 1628 | if (this._shader && this._shader["default"]) |
1625 | this._shader["default"].u_time.set( [this._time] ); | 1629 | this._shader["default"].u_time.set( [this._time] ); |
1626 | this._time += this._dTime; | 1630 | this._time += this._dTime; |
1627 | if (this._time > 200.0) this._time = 0.0; | ||
1628 | } | 1631 | } |
1629 | } | 1632 | } |
1630 | } | 1633 | } |
@@ -1645,10 +1648,10 @@ NinjaCvsRt.RuntimeFlagMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1645 | 1648 | ||
1646 | importJSON: { | 1649 | importJSON: { |
1647 | value: function(jObj) { | 1650 | value: function(jObj) { |
1648 | this._texMap = jObj.texMap; | 1651 | this._texMap = jObj.u_tex0; |
1649 | this._waveWidth = jObj.waveWidth; | 1652 | this._waveWidth = jObj.u_waveWidth; |
1650 | this._waveHeight = jObj.waveHeight; | 1653 | this._waveHeight = jObj.u_waveHeight; |
1651 | this._speed = jObj.speed; | 1654 | this._speed = jObj.u_speed; |
1652 | } | 1655 | } |
1653 | }, | 1656 | }, |
1654 | 1657 | ||
@@ -1690,13 +1693,92 @@ NinjaCvsRt.RuntimeFlagMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | |||
1690 | if (this._shader && this._shader['default']) { | 1693 | if (this._shader && this._shader['default']) { |
1691 | this._shader['default'].u_time.set( [this._time] ); | 1694 | this._shader['default'].u_time.set( [this._time] ); |
1692 | } | 1695 | } |
1693 | this._time += this._dTime * this._speed; | 1696 | this._time += this._dTime; |
1697 | } | ||
1698 | } | ||
1699 | } | ||
1700 | } | ||
1701 | }); | ||
1702 | |||
1703 | |||
1704 | |||
1705 | NinjaCvsRt.RuntimeWaterMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | ||
1706 | _name: { value: "WaterMaterial", writable: true }, | ||
1707 | _shaderName: { value: "water", writable: true }, | ||
1708 | |||
1709 | // default values | ||
1710 | _texMap: { value: 'assets/images/cubelight.png', writable: true }, | ||
1711 | _speed: { value: 1.0, writable: true }, | ||
1712 | _waveWidth: { value: 1.0, writable: true }, | ||
1713 | _waveHeight: { value: 1.0, writable: true }, | ||
1714 | _dTime: { value: 0.1, writable: true }, | ||
1715 | |||
1716 | importJSON: { | ||
1717 | value: function(jObj) { | ||
1718 | for (var prop in jObj) | ||
1719 | { | ||
1720 | if ((prop != 'material') && (prop != 'name')) | ||
1721 | { | ||
1722 | var value = jObj[prop]; | ||
1723 | this[prop] = value; | ||
1724 | } | ||
1725 | } | ||
1726 | |||
1727 | this._dTime = jObj.dTime; | ||
1728 | } | ||
1729 | }, | ||
1730 | |||
1731 | init: { | ||
1732 | value: function(world) { | ||
1733 | if (this._shader) { | ||
1734 | var material = this._materialNode; | ||
1735 | if (material) | ||
1736 | { | ||
1737 | var technique = material.shaderProgram['default']; | ||
1738 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
1739 | if (renderer && technique) | ||
1740 | { | ||
1741 | |||
1742 | if (this._shader && this._shader['default']) { | ||
1743 | var res = [ renderer.vpWidth, renderer.vpHeight ]; | ||
1744 | if (technique.u_resolution) technique.u_resolution.set( res ); | ||
1745 | |||
1746 | |||
1747 | var wrap = 'REPEAT', mips = true; | ||
1748 | var tex = renderer.getTextureByName(this.u_tex0, wrap, mips ); | ||
1749 | if (tex) technique.u_tex0.set( tex ); | ||
1750 | |||
1751 | technique.u_speed.set( [this.u_speed] ); | ||
1752 | technique.u_delta.set( [this.u_delta] ); | ||
1753 | technique.u_emboss.set( [this.u_emboss] ); | ||
1754 | technique.u_intensity.set( [this.u_intensity] ); | ||
1755 | } | ||
1756 | } | ||
1757 | } | ||
1758 | } | ||
1759 | } | ||
1760 | }, | ||
1761 | |||
1762 | update: { | ||
1763 | value: function(time) { | ||
1764 | var material = this._materialNode; | ||
1765 | if (material) | ||
1766 | { | ||
1767 | var technique = material.shaderProgram['default']; | ||
1768 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
1769 | if (renderer && technique) | ||
1770 | { | ||
1771 | if (this._shader && this._shader['default']) { | ||
1772 | this._shader['default'].u_time.set( [this._time] ); | ||
1773 | } | ||
1774 | this._time += this._dTime; | ||
1694 | } | 1775 | } |
1695 | } | 1776 | } |
1696 | } | 1777 | } |
1697 | } | 1778 | } |
1698 | }); | 1779 | }); |
1699 | 1780 | ||
1781 | |||
1700 | NinjaCvsRt.RuntimeRadialGradientMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { | 1782 | NinjaCvsRt.RuntimeRadialGradientMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { |
1701 | _name: { value: "RadialGradientMaterial", writable: true }, | 1783 | _name: { value: "RadialGradientMaterial", writable: true }, |
1702 | _shaderName: { value: "radialGradient", writable: true }, | 1784 | _shaderName: { value: "radialGradient", writable: true }, |
@@ -1735,10 +1817,12 @@ NinjaCvsRt.RuntimeRadialGradientMaterial = Object.create(NinjaCvsRt.RuntimeMater | |||
1735 | this._shader["default"].u_colorStop3.set( [this._colorStop3] ); | 1817 | this._shader["default"].u_colorStop3.set( [this._colorStop3] ); |
1736 | this._shader["default"].u_colorStop4.set( [this._colorStop4] ); | 1818 | this._shader["default"].u_colorStop4.set( [th |