diff options
Diffstat (limited to 'js/lib/rdge/materials/water-material.js')
-rw-r--r-- | js/lib/rdge/materials/water-material.js | 274 |
1 files changed, 137 insertions, 137 deletions
diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js index 0b8c8235..c7b401f0 100644 --- a/js/lib/rdge/materials/water-material.js +++ b/js/lib/rdge/materials/water-material.js | |||
@@ -37,71 +37,71 @@ var Texture = require("js/lib/rdge/texture").Texture; | |||
37 | /////////////////////////////////////////////////////////////////////// | 37 | /////////////////////////////////////////////////////////////////////// |
38 | var WaterMaterial = function WaterMaterial() | 38 | var WaterMaterial = function WaterMaterial() |
39 | { | 39 | { |
40 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
41 | // Instance variables | 41 | // Instance variables |
42 | /////////////////////////////////////////////////////////////////////// | 42 | /////////////////////////////////////////////////////////////////////// |
43 | this._name = "Water"; | 43 | this._name = "Water"; |
44 | this._shaderName = "water"; | 44 | this._shaderName = "water"; |
45 | 45 | ||
46 | this._defaultTexMap = 'assets/images/rocky-normal.jpg'; | 46 | this._defaultTexMap = 'assets/images/rocky-normal.jpg'; |
47 | 47 | ||
48 | this._time = 0.0; | 48 | this._time = 0.0; |
49 | this._dTime = 0.01; | 49 | this._dTime = 0.01; |
50 | 50 | ||
51 | // array textures indexed by shader uniform name | 51 | // array textures indexed by shader uniform name |
52 | this._glTextures = []; | 52 | this._glTextures = []; |
53 | 53 | ||
54 | this.isAnimated = function() { return true; }; | 54 | this.isAnimated = function() { return true; }; |
55 | this.getShaderDef = function() { return waterMaterialDef; }; | 55 | this.getShaderDef = function() { return waterMaterialDef; }; |
56 | 56 | ||
57 | /////////////////////////////////////////////////////////////////////// | 57 | /////////////////////////////////////////////////////////////////////// |
58 | // Properties | 58 | // Properties |
59 | /////////////////////////////////////////////////////////////////////// | 59 | /////////////////////////////////////////////////////////////////////// |
60 | // all defined in parent PulseMaterial.js | 60 | // all defined in parent PulseMaterial.js |
61 | // load the local default value | 61 | // load the local default value |
62 | this._propNames = ["u_tex0", "u_emboss", "u_delta", "u_intensity", "u_speed"]; | 62 | this._propNames = ["u_tex0", "u_emboss", "u_delta", "u_intensity", "u_speed"]; |
63 | this._propLabels = ["Texture map", "Emboss", "Delta", "Intensity", "Speed"]; | 63 | this._propLabels = ["Texture map", "Emboss", "Delta", "Intensity", "Speed"]; |
64 | this._propTypes = ["file", "float", "float", "float", "float"]; | 64 | this._propTypes = ["file", "float", "float", "float", "float"]; |
65 | 65 | ||
66 | var u_tex_index = 0, | 66 | var u_tex_index = 0, |
67 | u_emboss_index = 1, | 67 | u_emboss_index = 1, |
68 | u_delta_index = 2, | 68 | u_delta_index = 2, |
69 | u_intensity_index = 3, | 69 | u_intensity_index = 3, |
70 | u_speed_index = 4; | 70 | u_speed_index = 4; |
71 | 71 | ||
72 | this._propValues = []; | 72 | this._propValues = []; |
73 | this._propValues[ this._propNames[u_tex_index ] ] = this._defaultTexMap.slice(0); | 73 | this._propValues[ this._propNames[u_tex_index ] ] = this._defaultTexMap.slice(0); |
74 | this._propValues[ this._propNames[u_emboss_index ] ] = 0.3; | 74 | this._propValues[ this._propNames[u_emboss_index ] ] = 0.3; |
75 | this._propValues[ this._propNames[u_delta_index ] ] = 20.0; | 75 | this._propValues[ this._propNames[u_delta_index ] ] = 20.0; |
76 | this._propValues[ this._propNames[u_intensity_index ] ] = 3.0; | 76 | this._propValues[ this._propNames[u_intensity_index ] ] = 3.0; |
77 | this._propValues[ this._propNames[u_speed_index ] ] = 0.2; | 77 | this._propValues[ this._propNames[u_speed_index ] ] = 0.2; |
78 | 78 | ||
79 | /////////////////////////////////////////////////////////////////////// | 79 | /////////////////////////////////////////////////////////////////////// |
80 | // Methods | 80 | // Methods |
81 | /////////////////////////////////////////////////////////////////////// | 81 | /////////////////////////////////////////////////////////////////////// |
82 | 82 | ||
83 | this.init = function (world) { | 83 | this.init = function (world) { |
84 | // save the world | 84 | // save the world |
85 | if (world) this.setWorld(world); | 85 | if (world) this.setWorld(world); |
86 | 86 | ||
87 | // set up the shader | 87 | // set up the shader |
88 | this._shader = new RDGE.jshader(); | 88 | this._shader = new RDGE.jshader(); |
89 | this._shader.def = waterMaterialDef; | 89 | this._shader.def = waterMaterialDef; |
90 | this._shader.init(); | 90 | this._shader.init(); |
91 | 91 | ||
92 | // set up the material node | 92 | // set up the material node |
93 | this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID()); | 93 | this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID()); |
94 | this._materialNode.setShader(this._shader); | 94 | this._materialNode.setShader(this._shader); |
95 | 95 | ||
96 | this._time = 0; | 96 | this._time = 0; |
97 | if (this._shader && this._shader['default']) | 97 | if (this._shader && this._shader['default']) |
98 | this._shader['default'].u_time.set([this._time]); | 98 | this._shader['default'].u_time.set([this._time]); |
99 | 99 | ||
100 | // set the shader values in the shader | 100 | // set the shader values in the shader |
101 | this.setShaderValues(); | 101 | this.setShaderValues(); |
102 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); | 102 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); |
103 | this.update(0); | 103 | this.update(0); |
104 | }; | 104 | }; |
105 | 105 | ||
106 | this.resetToDefault = function() | 106 | this.resetToDefault = function() |
107 | { | 107 | { |
@@ -114,7 +114,7 @@ var WaterMaterial = function WaterMaterial() | |||
114 | var nProps = this._propNames.length; | 114 | var nProps = this._propNames.length; |
115 | for (var i=0; i<nProps; i++) | 115 | for (var i=0; i<nProps; i++) |
116 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | 116 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); |
117 | }; | 117 | }; |
118 | }; | 118 | }; |
119 | 119 | ||
120 | /////////////////////////////////////////////////////////////////////////////////////// | 120 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -123,96 +123,96 @@ var WaterMaterial = function WaterMaterial() | |||
123 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | 123 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) |
124 | var waterMaterialDef = | 124 | var waterMaterialDef = |
125 | { 'shaders': | 125 | { 'shaders': |
126 | { | 126 | { |
127 | 'defaultVShader': "assets/shaders/Basic.vert.glsl", | 127 | 'defaultVShader': "assets/shaders/Basic.vert.glsl", |
128 | 'defaultFShader': "assets/shaders/Water2.frag.glsl" | 128 | 'defaultFShader': "assets/shaders/Water2.frag.glsl" |
129 | }, | 129 | }, |
130 | 'techniques': | 130 | 'techniques': |
131 | { | 131 | { |
132 | 'default': | 132 | 'default': |
133 | [ | 133 | [ |
134 | { | 134 | { |
135 | 'vshader': 'defaultVShader', | 135 | 'vshader': 'defaultVShader', |
136 | 'fshader': 'defaultFShader', | 136 | 'fshader': 'defaultFShader', |
137 | // attributes | 137 | // attributes |
138 | 'attributes': | 138 | 'attributes': |
139 | { | 139 | { |
140 | 'vert': { 'type': 'vec3' }, | 140 | 'vert': { 'type': 'vec3' }, |
141 | 'normal': { 'type': 'vec3' }, | 141 | 'normal': { 'type': 'vec3' }, |
142 | 'texcoord': { 'type': 'vec2' } | 142 | 'texcoord': { 'type': 'vec2' } |
143 | }, | 143 | }, |
144 | // parameters | 144 | // parameters |
145 | 'params': | 145 | 'params': |
146 | { | 146 | { |
147 | 'u_tex0': { 'type': 'tex2d' }, | 147 | 'u_tex0': { 'type': 'tex2d' }, |
148 | 'u_time': { 'type': 'float' }, | 148 | 'u_time': { 'type': 'float' }, |
149 | 'u_emboss': { 'type': 'float' }, | 149 | 'u_emboss': { 'type': 'float' }, |
150 | 'u_delta': { 'type': 'float' }, | 150 | 'u_delta': { 'type': 'float' }, |
151 | 'u_speed': { 'type': 'float' }, | 151 | 'u_speed': { 'type': 'float' }, |
152 | 'u_intensity': { 'type': 'float' }, | 152 | 'u_intensity': { 'type': 'float' }, |
153 | 'u_resolution': { 'type': 'vec2' } | 153 | 'u_resolution': { 'type': 'vec2' } |
154 | }, | 154 | }, |
155 | 155 | ||
156 | // render states | 156 | // render states |
157 | 'states': | 157 | 'states': |
158 | { | 158 | { |
159 | 'depthEnable': true, | 159 | 'depthEnable': true, |
160 | 'offset': [1.0, 0.1] | 160 | 'offset': [1.0, 0.1] |
161 | } | 161 | } |
162 | } | 162 | } |
163 | ] | 163 | ] |
164 | } | 164 | } |
165 | }; | 165 | }; |
166 | 166 | ||
167 | var ParisMaterial = function ParisMaterial() | 167 | var ParisMaterial = function ParisMaterial() |
168 | { | 168 | { |
169 | // initialize the inherited members | 169 | // initialize the inherited members |
170 | this.inheritedFrom = WaterMaterial; | 170 | this.inheritedFrom = WaterMaterial; |
171 | this.inheritedFrom(); | 171 | this.inheritedFrom(); |
172 | 172 | ||
173 | this._name = "Paris"; | 173 | this._name = "Paris"; |
174 | this._shaderName = "paris"; | 174 | this._shaderName = "paris"; |
175 | 175 | ||
176 | this._defaultTexMap = 'assets/images/paris.png'; | 176 | this._defaultTexMap = 'assets/images/paris.png'; |
177 | this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0); | 177 | this._ |