Commits

Philipp Tiefenbacher committed 68e4580 Draft

cleanup :)

Comments (0)

Files changed (4)

src/game/CellSpace.js

 
 
 			// Dishinteraction INTERACTION /////////////////////////////////////////////
+/*
 			var framebuffer = shipExplosionDish.getNextFramebuffer();
 			var bindCallback = function(gl, progCA)
 			{
 				gl.uniform1f(gl.getUniformLocation(progCA, "state"), 3./255.);
 			}
 			reactor.applyShader(intersectSpawnShader, framebuffer, bindCallback);
-			shipDish.flip();			
-
+			shipDish.flip();		
+	*/
+	
+			reactor.mixDish(intersectSpawnShader, shipExplosionDish, {tex1: shipDish, tex2: enemyDish}, {state: (shipExplosionRule.nrStates-1)/255.});
+			reactor.mixDish(intersectSpawnShader, enemyDish, {tex1: enemyDish, tex2: shipExplosionDish}, {state: 1./255.});
+			reactor.mixDish(intersectSpawnShader, shipDish, {tex1: shipDish, tex2: shipExplosionDish}, {state: 3./255.});	
 
 			// COMPOSE ////////////////////////////////////////////
 			reactor.applyShaderOnDish(clearShader, renderDish);
-			reactor.mixDish(mixShader, renderDish, {newTexture: enemy2Dish}, {palette: enemy2Colors.getTexture()});
-			reactor.mixDish(mixShader, renderDish, {newTexture: enemyDish}, {palette: enemyColors.getTexture()});
-			reactor.mixDish(mixShader, renderDish, {newTexture: shipDish}, {palette: shipColors.getTexture()});
-			reactor.mixDish(mixShader, renderDish, {newTexture: shipExplosionDish}, {palette: shipExplosionColors.getTexture()});
+			reactor.mixDish(mixShader, renderDish, {texNew: enemy2Dish}, {texPalette: enemy2Colors.getTexture()});
+			reactor.mixDish(mixShader, renderDish, {texNew: enemyDish}, {texPalette: enemyColors.getTexture()});
+			reactor.mixDish(mixShader, renderDish, {texNew: shipDish}, {texPalette: shipColors.getTexture()});
+			reactor.mixDish(mixShader, renderDish, {texNew: shipExplosionDish}, {texPalette: shipExplosionColors.getTexture()});
 
 			
 			//RENDER

src/game/gl/Reactor.js

 		this.applyShader(paintShader, null, bindCallback)
 	}
 
-	Reactor.prototype.mixDish = function(mixShader, mainDish, paramDishes, textures, callback)
+	Reactor.prototype.mixDish = function(mixShader, mainDish, paramDishes, parameters, callback)
 	{
 		var framebuffer = mainDish.getNextFramebuffer();
 		var bindCallback = function(gl, progCA)
 		{
 			// set param for shader to TEXTURE0
-			gl.uniform1i(gl.getUniformLocation(progCA, "mainTexture"), 0);
+			gl.uniform1i(gl.getUniformLocation(progCA, "texFrame"), 0);
 			// set glcontext TEXTURE0 to current frame of mainDish
 			gl.activeTexture(gl.TEXTURE0);    
 			gl.bindTexture(gl.TEXTURE_2D, mainDish.getCurrentTexture());
 				gl.bindTexture(gl.TEXTURE_2D, paramDishes[paramName].getCurrentTexture());	
 				textureCount++;
 			}
-			for (var paramName in textures) {
-				gl.uniform1i(gl.getUniformLocation(progCA, paramName), textureCount);
-				gl.activeTexture(gl.TEXTURE0 + textureCount);    
-				gl.bindTexture(gl.TEXTURE_2D, textures[paramName]);	
-				textureCount++;
+			for (var paramName in parameters) {
+				var param = parameters[paramName];
+				if (param instanceof WebGLTexture) {
+					gl.uniform1i(gl.getUniformLocation(progCA, paramName), textureCount);
+					gl.activeTexture(gl.TEXTURE0 + textureCount);    
+					gl.bindTexture(gl.TEXTURE_2D, param);	
+					textureCount++;
+				}
+				else {
+					//if (param is int) 
+					if (typeof param === "number") {
+						gl.uniform1f(gl.getUniformLocation(progCA, paramName), param);
+					}
+					else {
+						var l = param.length;
+						if (l == 2) {
+							gl.uniform2f(gl.getUniformLocation(progCA, paramName), param[0], param[1]);
+						}
+					}
+				}
 			}
 			
 			if (callback) {

src/game/shaders/intersectSpawn.shader

 	precision highp float;
 #endif
 
-uniform sampler2D intersect1;
-uniform sampler2D intersect2;
-uniform sampler2D background;
+uniform sampler2D texFrame;
+uniform sampler2D tex1;
+uniform sampler2D tex2;
+
 uniform float state;
 
 varying vec2 vTexCoord;
 void main(void) {
-	vec4 color1 = texture2D(intersect1, vTexCoord);
-	vec4 color2 = texture2D(intersect2, vTexCoord);
-	vec4 oldColor = texture2D(background, vTexCoord);
+	vec4 color1 = texture2D(tex1, vTexCoord);
+	vec4 color2 = texture2D(tex2, vTexCoord);
+	vec4 oldColor = texture2D(texFrame, vTexCoord);
 
 	if (color1.a > 0. && color2.a > 0.)
 	{

src/game/shaders/mixPalette.shader

 	precision highp float;
 #endif
 
-uniform sampler2D mainTexture;
-uniform sampler2D newTexture;
-uniform sampler2D palette;
+uniform sampler2D texFrame;
+uniform sampler2D texNew;
+uniform sampler2D texPalette;
 
 varying vec2 vTexCoord;
 void main(void) {
-	vec4 color = texture2D(newTexture, vTexCoord);
-	vec4 mappedColor = texture2D(palette, vec2(color.a, 0.5));
-	vec4 oldColor = texture2D(mainTexture, vTexCoord);
+	vec4 color = texture2D(texNew, vTexCoord);
+	vec4 mappedColor = texture2D(texPalette, vec2(color.a, 0.5));
+	vec4 oldColor = texture2D(texFrame, vTexCoord);
 
 	if (color.a > 0.)
 	{