aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/water-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/water-material.js')
-rw-r--r--js/lib/rdge/materials/water-material.js272
1 files changed, 136 insertions, 136 deletions
diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js
index 5e63ea2c..a0056452 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///////////////////////////////////////////////////////////////////////
38var WaterMaterial = function WaterMaterial() 38var 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 106
107/////////////////////////////////////////////////////////////////////////////////////// 107///////////////////////////////////////////////////////////////////////////////////////
@@ -110,96 +110,96 @@ var WaterMaterial = function WaterMaterial()
110// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 110// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
111var waterMaterialDef = 111var waterMaterialDef =
112{ 'shaders': 112{ 'shaders':
113 { 113 {
114 'defaultVShader': "assets/shaders/Basic.vert.glsl", 114 'defaultVShader': "assets/shaders/Basic.vert.glsl",
115 'defaultFShader': "assets/shaders/Water2.frag.glsl" 115 'defaultFShader': "assets/shaders/Water2.frag.glsl"
116 }, 116 },
117 'techniques': 117 'techniques':
118 { 118 {
119 'default': 119 'default':
120 [ 120 [
121 { 121 {
122 'vshader': 'defaultVShader', 122 'vshader': 'defaultVShader',
123 'fshader': 'defaultFShader', 123 'fshader': 'defaultFShader',
124 // attributes 124 // attributes
125 'attributes': 125 'attributes':
126 { 126 {
127 'vert': { 'type': 'vec3' }, 127 'vert': { 'type': 'vec3' },
128 'normal': { 'type': 'vec3' }, 128 'normal': { 'type': 'vec3' },
129 'texcoord': { 'type': 'vec2' } 129 'texcoord': { 'type': 'vec2' }
130 }, 130 },
131 // parameters 131 // parameters
132 'params': 132 'params':
133 { 133 {
134 'u_tex0': { 'type': 'tex2d' }, 134 'u_tex0': { 'type': 'tex2d' },
135 'u_time': { 'type': 'float' }, 135 'u_time': { 'type': 'float' },
136 'u_emboss': { 'type': 'float' }, 136 'u_emboss': { 'type': 'float' },
137 'u_delta': { 'type': 'float' }, 137 'u_delta': { 'type': 'float' },
138 'u_speed': { 'type': 'float' }, 138 'u_speed': { 'type': 'float' },
139 'u_intensity': { 'type': 'float' }, 139 'u_intensity': { 'type': 'float' },
140 'u_resolution': { 'type': 'vec2' } 140 'u_resolution': { 'type': 'vec2' }
141 }, 141 },
142 142
143 // render states 143 // render states
144 'states': 144 'states':
145 { 145 {
146 'depthEnable': true, 146 'depthEnable': true,
147 'offset': [1.0, 0.1] 147 'offset': [1.0, 0.1]
148 } 148 }
149 } 149 }
150 ] 150 ]
151 } 151 }
152}; 152};
153 153
154var ParisMaterial = function ParisMaterial() 154var ParisMaterial = function ParisMaterial()
155{ 155{
156 // initialize the inherited members 156 // initialize the inherited members
157 this.inheritedFrom = WaterMaterial; 157 this.inheritedFrom = WaterMaterial;
158 this.inheritedFrom(); 158 this.inheritedFrom();
159 159
160 this._name = "Paris"; 160 this._name = "Paris";
161 this._shaderName = "paris"; 161 this._shaderName = "paris";
162 162
163 this._defaultTexMap = 'assets/images/paris.png'; 163 this._defaultTexMap = 'assets/images/paris.png';
164 this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0); 164 this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0);
165 165
166 //this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; 166 //this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
167 //this._propValues[this._propNames[1]] = this._diffuseColor.slice(); 167 //this._propValues[this._propNames[1]] = this._diffuseColor.slice();
168 168
169 this.init = function (world) 169 this.init = function (world)
170 { 170 {