diff options
author | Ananya Sen | 2012-07-09 16:52:49 -0700 |
---|---|---|
committer | Ananya Sen | 2012-07-09 16:52:49 -0700 |
commit | 2eb84584f44b8c774479d1af2ee1d810597474cf (patch) | |
tree | 64cb3e09a8daeb340261dd7f3869c73f7b90b643 /js/lib/rdge/materials/julia-material.js | |
parent | bf9dba001ec84243e2f12cd13b0c0ae020fba4a2 (diff) | |
parent | cee0deca695359ab468bd06d0e05ed3b2010b338 (diff) | |
download | ninja-2eb84584f44b8c774479d1af2ee1d810597474cf.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into codemirror-custom-theme-removal
Conflicts:
js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css
js/code-editor/codemirror-ninja/theme/xq-dark-ninja.css
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/julia-material.js')
-rw-r--r-- | js/lib/rdge/materials/julia-material.js | 162 |
1 files changed, 86 insertions, 76 deletions
diff --git a/js/lib/rdge/materials/julia-material.js b/js/lib/rdge/materials/julia-material.js index eed9e79a..ceab3340 100644 --- a/js/lib/rdge/materials/julia-material.js +++ b/js/lib/rdge/materials/julia-material.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -35,100 +36,109 @@ var JuliaMaterial = function JuliaMaterial() { | |||
35 | /////////////////////////////////////////////////////////////////////// | 36 | /////////////////////////////////////////////////////////////////////// |
36 | // Instance variables | 37 | // Instance variables |
37 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
38 | this._name = "Julia"; | 39 | this._name = "Julia"; |
39 | this._shaderName = "julia"; | 40 | this._shaderName = "julia"; |
40 | 41 | ||
41 | this._defaultTexMap = 'assets/images/rocky-normal.jpg'; | 42 | this._defaultTexMap = 'assets/images/rocky-normal.jpg'; |
42 | 43 | ||
43 | this._time = 0.0; | 44 | this._time = 0.0; |
44 | this._dTime = 0.01; | 45 | this._dTime = 0.01; |
45 | 46 | ||
46 | /////////////////////////////////////////////////////////////////////// | 47 | /////////////////////////////////////////////////////////////////////// |
47 | // Properties | 48 | // Properties |
48 | /////////////////////////////////////////////////////////////////////// | 49 | /////////////////////////////////////////////////////////////////////// |
49 | var u_speed_index = 0; | 50 | var u_speed_index = 0; |
50 | this._propNames = [ "u_speed" ]; | 51 | this._propNames = [ "u_speed" ]; |
51 | this._propLabels = [ "Speed" ]; | 52 | this._propLabels = [ "Speed" ]; |
52 | this._propTypes = [ "float" ]; | 53 | this._propTypes = [ "float" ]; |
53 | this._propValues = []; | 54 | this._propValues = []; |
54 | this._propValues[this._propNames[u_speed_index]] = 1.0; | 55 | this._propValues[this._propNames[u_speed_index]] = 1.0; |
55 | 56 | ||
56 | /////////////////////////////////////////////////////////////////////// | 57 | /////////////////////////////////////////////////////////////////////// |
57 | // Material Property Accessors | 58 | // Material Property Accessors |
58 | /////////////////////////////////////////////////////////////////////// | 59 | /////////////////////////////////////////////////////////////////////// |
59 | this.isAnimated = function() { return true; }; | 60 | this.isAnimated = function() { return true; }; |
60 | this.getShaderDef = function() { return JuliaMaterialDef; } | 61 | this.getShaderDef = function() { return JuliaMaterialDef; } |
61 | 62 | ||
62 | /////////////////////////////////////////////////////////////////////// | 63 | /////////////////////////////////////////////////////////////////////// |
63 | // Methods | 64 | // Methods |
64 | /////////////////////////////////////////////////////////////////////// | 65 | /////////////////////////////////////////////////////////////////////// |
65 | 66 | ||
66 | this.init = function( world ) { | 67 | this.init = function( world ) { |
67 | // save the world | 68 | // save the world |
68 | if (world) this.setWorld( world ); | 69 | if (world) this.setWorld( world ); |
69 | 70 | ||
70 | // set up the shader | 71 | // set up the shader |
71 | this._shader = new RDGE.jshader(); | 72 | this._shader = new RDGE.jshader(); |
72 | this._shader.def = JuliaMaterialDef; | 73 | this._shader.def = JuliaMaterialDef; |
73 | this._shader.init(); | 74 | this._shader.init(); |
74 | 75 | ||
75 | // set up the material node | 76 | // set up the material node |
76 | this._materialNode = RDGE.createMaterialNode("juliaMaterial" + "_" + world.generateUniqueNodeID()); | 77 | this._materialNode = RDGE.createMaterialNode("juliaMaterial" + "_" + world.generateUniqueNodeID()); |
77 | this._materialNode.setShader(this._shader); | 78 | this._materialNode.setShader(this._shader); |
78 | 79 | ||
79 | this._time = 0; | 80 | this._time = 0; |
80 | if (this._shader && this._shader['default']) { | 81 | if (this._shader && this._shader['default']) { |
81 | this._shader['default'].u_time.set( [this._time] ); | 82 | this._shader['default'].u_time.set( [this._time] ); |
82 | } | 83 | } |
83 | 84 | ||
84 | // set the shader values in the shader | 85 | // set the shader values in the shader |
85 | this.setShaderValues(); | 86 | this.setShaderValues(); |
86 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | 87 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); |
87 | this.update( 0 ); | 88 | this.update( 0 ); |
89 | }; | ||
90 | |||
91 | this.resetToDefault = function() | ||
92 | { | ||
93 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
94 | |||
95 | var nProps = this._propNames.length; | ||
96 | for (var i=0; i<nProps; i++) | ||
97 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | ||
88 | }; | 98 | }; |
89 | } | 99 | } |
90 | 100 | ||
91 | /////////////////////////////////////////////////////////////////////////////////////// | 101 | /////////////////////////////////////////////////////////////////////////////////////// |
92 | // RDGE shader | 102 | // RDGE shader |
93 | 103 | ||
94 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | 104 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) |
95 | var JuliaMaterialDef = | 105 | var JuliaMaterialDef = |
96 | {'shaders': | 106 | {'shaders': |
97 | { | 107 | { |
98 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | 108 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", |
99 | 'defaultFShader':"assets/shaders/Julia.frag.glsl" | 109 | 'defaultFShader':"assets/shaders/Julia.frag.glsl" |
100 | }, | 110 | }, |
101 | 'techniques': | 111 | 'techniques': |
102 | { | 112 | { |
103 | 'default': | 113 | 'default': |
104 | [ | 114 | [ |
105 | { | 115 | { |
106 | 'vshader' : 'defaultVShader', | 116 | 'vshader' : 'defaultVShader', |
107 | 'fshader' : 'defaultFShader', | 117 | 'fshader' : 'defaultFShader', |
108 | // attributes | 118 | // attributes |
109 | 'attributes' : | 119 | 'attributes' : |
110 | { | 120 | { |
111 | 'vert' : { 'type' : 'vec3' }, | 121 | 'vert' : { 'type' : 'vec3' }, |
112 | 'normal' : { 'type' : 'vec3' }, | 122 | 'normal' : { 'type' : 'vec3' }, |
113 | 'texcoord' : { 'type' : 'vec2' } | 123 | 'texcoord' : { 'type' : 'vec2' } |
114 | }, | 124 | }, |
115 | // parameters | 125 | // parameters |
116 | 'params' : | 126 | 'params' : |
117 | { | 127 | { |
118 | 'u_time' : { 'type' : 'float' }, | 128 | 'u_time' : { 'type' : 'float' }, |
119 | 'u_speed' : { 'type' : 'float' }, | 129 | 'u_speed' : { 'type' : 'float' }, |
120 | 'u_resolution' : { 'type' : 'vec2' }, | 130 | 'u_resolution' : { 'type' : 'vec2' }, |
121 | }, | 131 | }, |
122 | 132 | ||
123 | // render states | 133 | // render states |
124 | 'states' : | 134 | 'states' : |
125 | { | 135 | { |
126 | 'depthEnable' : true, | 136 | 'depthEnable' : true, |
127 | 'offset':[1.0, 0.1] | 137 | 'offset':[1.0, 0.1] |
128 | } | 138 | } |
129 | } | 139 | } |
130 | ] | 140 | ] |
131 | } | 141 | } |
132 | }; | 142 | }; |
133 | 143 | ||
134 | JuliaMaterial.prototype = new PulseMaterial(); | 144 | JuliaMaterial.prototype = new PulseMaterial(); |