diff options
Diffstat (limited to 'js/lib/rdge')
27 files changed, 3362 insertions, 2927 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 3db3df1d..02540033 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-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 |
@@ -40,92 +41,104 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
40 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
41 | // Instance variables | 42 | // Instance variables |
42 | /////////////////////////////////////////////////////////////////////// | 43 | /////////////////////////////////////////////////////////////////////// |
43 | this._name = "Bump Metal"; | 44 | this._name = "Bump Metal"; |
44 | this._shaderName = "bumpMetal"; | 45 | this._shaderName = "bumpMetal"; |
45 | 46 | ||
46 | 47 | ||
48 | this._defaultLightDiff = [0.3, 0.3, 0.3, 1.0]; | ||
47 | this._defaultDiffuseTexture = "assets/images/metal.png"; | 49 | this._defaultDiffuseTexture = "assets/images/metal.png"; |
48 | this._defaultSpecularTexture = "assets/images/silver.png"; | 50 | this._defaultSpecularTexture = "assets/images/silver.png"; |
49 | this._defaultNormalTexture = "assets/images/normalMap.png"; | 51 | this._defaultNormalTexture = "assets/images/normalMap.png"; |
50 | 52 | ||
51 | // array textures indexed by shader uniform name | 53 | // array textures indexed by shader uniform name |
52 | this._glTextures = []; | 54 | this._glTextures = []; |
53 | 55 | ||
54 | this._speed = 1.0; | 56 | this._speed = 1.0; |
55 | 57 | ||
56 | /////////////////////////////////////////////////////////////////////// | 58 | /////////////////////////////////////////////////////////////////////// |
57 | // Property Accessors | 59 | // Property Accessors |
58 | /////////////////////////////////////////////////////////////////////// | 60 | /////////////////////////////////////////////////////////////////////// |
59 | this.isAnimated = function() { return true; }; | 61 | this.isAnimated = function() { return true; }; |
60 | this.getShaderDef = function() { return bumpMetalMaterialDef; }; | 62 | this.getShaderDef = function() { return bumpMetalMaterialDef; }; |
61 | 63 | ||
62 | /////////////////////////////////////////////////////////////////////// | 64 | /////////////////////////////////////////////////////////////////////// |
63 | // Material Property Accessors | 65 | // Material Property Accessors |
64 | /////////////////////////////////////////////////////////////////////// | 66 | /////////////////////////////////////////////////////////////////////// |
65 | this._propNames = ["u_light0Diff", "u_colMap", "u_normalMap", "u_glowMap" ]; | 67 | this._propNames = ["u_light0Diff", "u_colMap", "u_normalMap", "u_glowMap" ]; |
66 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map" ]; | 68 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map" ]; |
67 | this._propTypes = ["color", "file", "file", "file" ]; | 69 | this._propTypes = ["color", "file", "file", "file" ]; |
68 | this._propValues = []; | 70 | this._propValues = []; |
69 | 71 | ||
70 | this._propValues[ this._propNames[0] ] = [0.3, 0.3, 0.3, 1.0]; | 72 | this._propValues[ this._propNames[0] ] = this._defaultLightDiff; |
71 | this._propValues[ this._propNames[1] ] = this._defaultDiffuseTexture.slice(0); | 73 | this._propValues[ this._propNames[1] ] = this._defaultDiffuseTexture.slice(0); |
72 | this._propValues[ this._propNames[2] ] = this._defaultNormalTexture.slice(0); | 74 | this._propValues[ this._propNames[2] ] = this._defaultNormalTexture.slice(0); |
73 | this._propValues[ this._propNames[3] ] = this._defaultSpecularTexture.slice(0); | 75 | this._propValues[ this._propNames[3] ] = this._defaultSpecularTexture.slice(0); |
74 | 76 | ||
75 | 77 | ||
76 | /////////////////////////////////////////////////////////////////////// | 78 | /////////////////////////////////////////////////////////////////////// |
77 | // Methods | 79 | // Methods |
78 | /////////////////////////////////////////////////////////////////////// | 80 | /////////////////////////////////////////////////////////////////////// |
79 | 81 | ||
80 | this.init = function( world ) | 82 | this.init = function( world ) |
81 | { | 83 | { |
82 | // save the world | 84 | // save the world |
83 | if (world) { | 85 | if (world) { |
84 | this.setWorld( world ); | 86 | this.setWorld( world ); |
85 | } | 87 | } |
86 | 88 | ||
87 | // set up the shader | 89 | // set up the shader |
88 | this._shader = new RDGE.jshader(); | 90 | this._shader = new RDGE.jshader(); |
89 | this._shader.def = bumpMetalMaterialDef; | 91 | this._shader.def = bumpMetalMaterialDef; |
90 | this._shader.init(); | 92 | this._shader.init(); |
93 | |||
94 | // set up the material node | ||
95 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); | ||
96 | this._materialNode.setShader(this._shader); | ||
91 | 97 | ||
92 | // set up the material node | 98 | this.setShaderValues(); |
93 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); | 99 | this.update(0); |
94 | this._materialNode.setShader(this._shader); | 100 | }; |
95 | 101 | ||
96 | this.setShaderValues(); | 102 | this.resetToDefault = function() |
97 | this.update(0); | 103 | { |
98 | }; | 104 | this._propValues[ this._propNames[0] ] = this._defaultLightDiff; |
105 | this._propValues[ this._propNames[1] ] = this._defaultDiffuseTexture.slice(0); | ||
106 | this._propValues[ this._propNames[2] ] = this._defaultNormalTexture.slice(0); | ||
107 | this._propValues[ this._propNames[3] ] = this._defaultSpecularTexture.slice(0); | ||
108 | for (var i=0; i<4; i++) | ||
109 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | ||
110 | }; | ||
99 | }; | 111 | }; |
100 | 112 | ||
113 | |||
101 | /////////////////////////////////////////////////////////////////////////////////////// | 114 | /////////////////////////////////////////////////////////////////////////////////////// |
102 | // RDGE shader | 115 | // RDGE shader |
103 | 116 | ||
104 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | 117 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) |
105 | var bumpMetalMaterialDef = bumpMetalShaderDef = | 118 | var bumpMetalMaterialDef = bumpMetalShaderDef = |
106 | { | 119 | { |
107 | 'shaders': | 120 | 'shaders': |
108 | { | 121 | { |
109 | // this shader is being referenced by file | 122 | // this shader is being referenced by file |
110 | 'defaultVShader':"assets/shaders/test_vshader.glsl", | 123 | 'defaultVShader':"assets/shaders/test_vshader.glsl", |
111 | 'defaultFShader':"assets/shaders/test_fshader.glsl", | 124 | 'defaultFShader':"assets/shaders/test_fshader.glsl", |
112 | 125 | ||
113 | // this shader is inline | < |