diff options
author | Jose Antonio Marquez | 2012-02-23 10:37:04 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-23 10:37:04 -0800 |
commit | 287a0bad5b774a380ec6c8b3ddf24dc03234e248 (patch) | |
tree | edffa1dd9df53f26da4135068686997ccfbdf083 /js/helper-classes/RDGE/Materials/JuliaMaterial.js | |
parent | 14a8f4c4e373db213b3d42d30edaea8354ae57e3 (diff) | |
parent | cc295dd0fb873505eed01c232bd987cf6e2dcdd9 (diff) | |
download | ninja-287a0bad5b774a380ec6c8b3ddf24dc03234e248.tar.gz |
Merge branch 'refs/heads/NinjaInternal' into FileIO
Diffstat (limited to 'js/helper-classes/RDGE/Materials/JuliaMaterial.js')
-rw-r--r-- | js/helper-classes/RDGE/Materials/JuliaMaterial.js | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/Materials/JuliaMaterial.js b/js/helper-classes/RDGE/Materials/JuliaMaterial.js new file mode 100644 index 00000000..f95263f4 --- /dev/null +++ b/js/helper-classes/RDGE/Materials/JuliaMaterial.js | |||
@@ -0,0 +1,150 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | |||
8 | |||
9 | /////////////////////////////////////////////////////////////////////// | ||
10 | // Class GLMaterial | ||
11 | // RDGE representation of a material. | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | function JuliaMaterial() | ||
14 | { | ||
15 | // initialize the inherited members | ||
16 | this.inheritedFrom = PulseMaterial; | ||
17 | this.inheritedFrom(); | ||
18 | |||
19 | /////////////////////////////////////////////////////////////////////// | ||
20 | // Instance variables | ||
21 | /////////////////////////////////////////////////////////////////////// | ||
22 | this._name = "JuliaMaterial"; | ||
23 | this._shaderName = "julia"; | ||
24 | |||
25 | this._texMap = 'assets/images/rocky-normal.jpg'; | ||
26 | |||
27 | this._time = 0.0; | ||
28 | this._dTime = 0.01; | ||
29 | |||
30 | /////////////////////////////////////////////////////////////////////// | ||
31 | // Properties | ||
32 | /////////////////////////////////////////////////////////////////////// | ||
33 | // no properties | ||
34 | this._propNames = []; | ||
35 | this._propLabels = []; | ||
36 | this._propTypes = []; | ||
37 | this._propValues = []; | ||
38 | |||
39 | /////////////////////////////////////////////////////////////////////// | ||
40 | // Material Property Accessors | ||
41 | /////////////////////////////////////////////////////////////////////// | ||
42 | |||
43 | /////////////////////////////////////////////////////////////////////// | ||
44 | |||
45 | |||
46 | /////////////////////////////////////////////////////////////////////// | ||
47 | // Methods | ||
48 | /////////////////////////////////////////////////////////////////////// | ||
49 | // duplcate method requirde | ||
50 | this.dup = function( world ) | ||
51 | { | ||
52 | // allocate a new uber material | ||
53 | var newMat = new JuliaMaterial(); | ||
54 | |||
55 | // copy over the current values; | ||
56 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
57 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
58 | var n = propNames.length; | ||
59 | for (var i=0; i<n; i++) | ||
60 | newMat.setProperty( propNames[i], propValues[i] ); | ||
61 | |||
62 | return newMat; | ||
63 | } | ||
64 | |||
65 | this.init = function( world ) | ||
66 | { | ||
67 | // save the world | ||
68 | if (world) this.setWorld( world ); | ||
69 | |||
70 | // set up the shader | ||
71 | this._shader = new jshader(); | ||
72 | this._shader.def = JuliaMaterialDef; | ||
73 | this._shader.init(); | ||
74 | |||
75 | // set up the material node | ||
76 | this._materialNode = createMaterialNode("juliaMaterial"); | ||
77 | this._materialNode.setShader(this._shader); | ||
78 | |||
79 | this._time = 0; | ||
80 | if (this._shader && this._shader.default) | ||
81 | this._shader.default.u_time.set( [this._time] ); | ||
82 | |||
83 | // set the shader values in the shader | ||
84 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | ||
85 | this.update( 0 ); | ||
86 | } | ||
87 | |||
88 | this.update = function( time ) | ||
89 | { | ||
90 | var material = this._materialNode; | ||
91 | if (material) | ||
92 | { | ||
93 | var technique = material.shaderProgram.default; | ||
94 | var renderer = g_Engine.getContext().renderer; | ||
95 | if (renderer && technique) | ||
96 | { | ||
97 | if (this._shader && this._shader.default) | ||
98 | this._shader.default.u_time.set( [this._time] ); | ||
99 | this._time = time; | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | /////////////////////////////////////////////////////////////////////////////////////// | ||
106 | // RDGE shader | ||
107 | |||
108 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | ||
109 | var JuliaMaterialDef = | ||
110 | {'shaders': | ||
111 | { | ||
112 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | ||
113 | 'defaultFShader':"assets/shaders/Julia.frag.glsl" | ||
114 | }, | ||
115 | 'techniques': | ||
116 | { | ||
117 | 'default': | ||
118 | [ | ||
119 | { | ||
120 | 'vshader' : 'defaultVShader', | ||
121 | 'fshader' : 'defaultFShader', | ||
122 | // attributes | ||
123 | 'attributes' : | ||
124 | { | ||
125 | 'vert' : { 'type' : 'vec3' }, | ||
126 | 'normal' : { 'type' : 'vec3' }, | ||
127 | 'texcoord' : { 'type' : 'vec2' } | ||
128 | }, | ||
129 | // parameters | ||
130 | 'params' : | ||
131 | { | ||
132 | 'u_tex0': { 'type' : 'tex2d' }, | ||
133 | 'u_time' : { 'type' : 'float' }, | ||
134 | 'u_resolution' : { 'type' : 'vec2' }, | ||
135 | }, | ||
136 | |||
137 | // render states | ||
138 | 'states' : | ||
139 | { | ||
140 | 'depthEnable' : true, | ||
141 | 'offset':[1.0, 0.1] | ||
142 | }, | ||
143 | }, | ||
144 | ] | ||
145 | } | ||
146 | }; | ||
147 | |||
148 | |||
149 | |||
150 | |||