Commit 4cd227cc authored by amandaghassaei's avatar amandaghassaei
Browse files

new k and d workin in shader

parent c38c7995
...@@ -555,71 +555,71 @@ define(['underscore', 'backbone', 'threeModel', 'lattice', 'plist', 'emWire', 'G ...@@ -555,71 +555,71 @@ define(['underscore', 'backbone', 'threeModel', 'lattice', 'plist', 'emWire', 'G
iter: function(time, runConstants, shouldRender){ iter: function(time, runConstants, shouldRender){
////gpuMath.step("quaternionCalc", ["u_lastTranslation", "u_lastQuaternion", "u_fixed", "u_neighborsXMapping", //gpuMath.step("quaternionCalc", ["u_lastTranslation", "u_lastQuaternion", "u_fixed", "u_neighborsXMapping",
//// "u_neighborsYMapping", "u_compositeKs"], "u_quaternion", "u_wires", "u_wiresMeta", time); // "u_neighborsYMapping", "u_compositeKs"], "u_quaternion", "u_wires", "u_wiresMeta", time);
//gpuMath.step("velocityCalc", ["u_lastVelocity", "u_lastTranslation", "u_mass", "u_neighborsXMapping", gpuMath.step("velocityCalc", ["u_lastVelocity", "u_lastTranslation", "u_mass", "u_neighborsXMapping",
// "u_neighborsYMapping", "u_compositeKs", "u_compositeDs", "u_originalPosition", "u_lastQuaternion", "u_wires", "u_neighborsYMapping", "u_compositeKs", "u_compositeDs", "u_originalPosition", "u_lastQuaternion", "u_wires",
// "u_wiresMeta"], "u_velocity", time); "u_wiresMeta"], "u_velocity", time);
//gpuMath.step("positionCalc", ["u_velocity", "u_lastTranslation", "u_mass"], "u_translation"); gpuMath.step("positionCalc", ["u_velocity", "u_lastTranslation", "u_mass"], "u_translation");
//
//if (shouldRender) { if (shouldRender) {
// var textureSize = this.textureSize[0]*this.textureSize[1]; var textureSize = this.textureSize[0]*this.textureSize[1];
//
// //get position //get position
// var vectorLength = 3; var vectorLength = 3;
// gpuMath.setProgram("packToBytes"); gpuMath.setProgram("packToBytes");
// gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f"); gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
// gpuMath.setSize(this.textureSize[0]*vectorLength, this.textureSize[1]); gpuMath.setSize(this.textureSize[0]*vectorLength, this.textureSize[1]);
// gpuMath.step("packToBytes", ["u_translation"], "outputPositionBytes"); gpuMath.step("packToBytes", ["u_translation"], "outputPositionBytes");
// var pixels = new Uint8Array(textureSize * 4*vectorLength); var pixels = new Uint8Array(textureSize * 4*vectorLength);
// if (gpuMath.readyToRead()) { if (gpuMath.readyToRead()) {
// gpuMath.readPixels(0, 0, this.textureSize[0] * vectorLength, this.textureSize[1], pixels); gpuMath.readPixels(0, 0, this.textureSize[0] * vectorLength, this.textureSize[1], pixels);
// var parsedPixels = new Float32Array(pixels.buffer); var parsedPixels = new Float32Array(pixels.buffer);
// var cells = lattice.getCells(); var cells = lattice.getCells();
// var multiplier = 1 / (plist.allUnitTypes[lattice.getUnits()].multiplier); var multiplier = 1 / (plist.allUnitTypes[lattice.getUnits()].multiplier);
// for (var i = 0; i < textureSize; i++) { for (var i = 0; i < textureSize; i++) {
// var rgbaIndex = 4 * i; var rgbaIndex = 4 * i;
// if (this.mass[rgbaIndex+1] < 0) continue;//no more cells if (this.mass[rgbaIndex+1] < 0) continue;//no more cells
// var index = [this.cellsArrayMapping[rgbaIndex], this.cellsArrayMapping[rgbaIndex + 1], this.cellsArrayMapping[rgbaIndex + 2]]; var index = [this.cellsArrayMapping[rgbaIndex], this.cellsArrayMapping[rgbaIndex + 1], this.cellsArrayMapping[rgbaIndex + 2]];
// var parsePixelsIndex = vectorLength * i; var parsePixelsIndex = vectorLength * i;
// var translation = [parsedPixels[parsePixelsIndex], parsedPixels[parsePixelsIndex + 1], parsedPixels[parsePixelsIndex + 2]]; var translation = [parsedPixels[parsePixelsIndex], parsedPixels[parsePixelsIndex + 1], parsedPixels[parsePixelsIndex + 2]];
// var position = [this.originalPosition[rgbaIndex], this.originalPosition[rgbaIndex + 1], this.originalPosition[rgbaIndex + 2]]; var position = [this.originalPosition[rgbaIndex], this.originalPosition[rgbaIndex + 1], this.originalPosition[rgbaIndex + 2]];
// position[0] += multiplier * translation[0]; position[0] += multiplier * translation[0];
// position[1] += multiplier * translation[1]; position[1] += multiplier * translation[1];
// position[2] += multiplier * translation[2]; position[2] += multiplier * translation[2];
// cells[index[0]][index[1]][index[2]].object3D.position.set(position[0], position[1], position[2]); cells[index[0]][index[1]][index[2]].object3D.position.set(position[0], position[1], position[2]);
// } }
// } }
//
// vectorLength = 4; vectorLength = 4;
// gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f"); gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
// gpuMath.setSize(this.textureSize[0]*vectorLength, this.textureSize[1]); gpuMath.setSize(this.textureSize[0]*vectorLength, this.textureSize[1]);
// gpuMath.step("packToBytes", ["u_quaternion"], "outputQuaternionBytes"); gpuMath.step("packToBytes", ["u_quaternion"], "outputQuaternionBytes");
// pixels = new Uint8Array(textureSize * 4*vectorLength); pixels = new Uint8Array(textureSize * 4*vectorLength);
// if (gpuMath.readyToRead()) { if (gpuMath.readyToRead()) {
// gpuMath.readPixels(0, 0, this.textureSize[0] * vectorLength, this.textureSize[1], pixels); gpuMath.readPixels(0, 0, this.textureSize[0] * vectorLength, this.textureSize[1], pixels);
// parsedPixels = new Float32Array(pixels.buffer); parsedPixels = new Float32Array(pixels.buffer);
// for (var i = 0; i < textureSize; i++) { for (var i = 0; i < textureSize; i++) {
// var rgbaIndex = 4 * i; var rgbaIndex = 4 * i;
// if (this.mass[rgbaIndex+1] < 0) break;//no more cells if (this.mass[rgbaIndex+1] < 0) break;//no more cells
// var index = [this.cellsArrayMapping[rgbaIndex], this.cellsArrayMapping[rgbaIndex + 1], this.cellsArrayMapping[rgbaIndex + 2]]; var index = [this.cellsArrayMapping[rgbaIndex], this.cellsArrayMapping[rgbaIndex + 1], this.cellsArrayMapping[rgbaIndex + 2]];
// var parsePixelsIndex = vectorLength * i; var parsePixelsIndex = vectorLength * i;
//
// var quaternion = this._multiplyQuaternions([parsedPixels[parsePixelsIndex], parsedPixels[parsePixelsIndex + 1], parsedPixels[parsePixelsIndex + 2], parsedPixels[parsePixelsIndex + 3]], var quaternion = this._multiplyQuaternions([parsedPixels[parsePixelsIndex], parsedPixels[parsePixelsIndex + 1], parsedPixels[parsePixelsIndex + 2], parsedPixels[parsePixelsIndex + 3]],
// [this.originalQuaternion[rgbaIndex], this.originalQuaternion[rgbaIndex+1], this.originalQuaternion[rgbaIndex+2], this.originalQuaternion[rgbaIndex+3]]); [this.originalQuaternion[rgbaIndex], this.originalQuaternion[rgbaIndex+1], this.originalQuaternion[rgbaIndex+2], this.originalQuaternion[rgbaIndex+3]]);
// var rotation = this._eulerFromQuaternion(quaternion); var rotation = this._eulerFromQuaternion(quaternion);
//
// cells[index[0]][index[1]][index[2]].object3D.rotation.set(rotation[0], rotation[1], rotation[2]); cells[index[0]][index[1]][index[2]].object3D.rotation.set(rotation[0], rotation[1], rotation[2]);
// } }
// } }
//
// gpuMath.setSize(this.textureSize[0], this.textureSize[1]); gpuMath.setSize(this.textureSize[0], this.textureSize[1]);
//} }
//
//gpuMath.swapTextures("u_velocity", "u_lastVelocity"); gpuMath.swapTextures("u_velocity", "u_lastVelocity");
//gpuMath.swapTextures("u_translation", "u_lastTranslation"); gpuMath.swapTextures("u_translation", "u_lastTranslation");
////gpuMath.swapTextures("u_quaternion", "u_lastQuaternion"); //gpuMath.swapTextures("u_quaternion", "u_lastQuaternion");
//return; return;
var gravity = runConstants.gravity; var gravity = runConstants.gravity;
var groundHeight = runConstants.groundHeight; var groundHeight = runConstants.groundHeight;
......
...@@ -217,16 +217,6 @@ void main(){ ...@@ -217,16 +217,6 @@ void main(){
vec2 mappingIndex = vec2(xIndex/(u_textureDim.x*2.0), scaledFragCoord.y); vec2 mappingIndex = vec2(xIndex/(u_textureDim.x*2.0), scaledFragCoord.y);
vec3 neighborsXMapping = texture2D(u_neighborsXMapping, mappingIndex).xyz; vec3 neighborsXMapping = texture2D(u_neighborsXMapping, mappingIndex).xyz;
vec3 neighborsYMapping = texture2D(u_neighborsYMapping, mappingIndex).xyz; vec3 neighborsYMapping = texture2D(u_neighborsYMapping, mappingIndex).xyz;
vec3 longitudalK = texture2D(u_compositeKs, mappingIndex).xyz;
vec3 shearK1 = vec3(10,10,10);
vec3 shearK2 = vec3(10,10,10);
vec3 longitudalD = texture2D(u_compositeDs, mappingIndex).xyz;
vec3 shearD1 = vec3(0.03, 0.03, 0.03);
vec3 shearD2 = vec3(0.03, 0.03, 0.03);
for (int j=0;j<3;j++){ for (int j=0;j<3;j++){
if (neighborsXMapping[j] < 0.0) continue;//no neighbor if (neighborsXMapping[j] < 0.0) continue;//no neighbor
...@@ -271,6 +261,11 @@ void main(){ ...@@ -271,6 +261,11 @@ void main(){
//else if (neighborAxis == 1) actuatedD[1] *= 1.0+actuation; //else if (neighborAxis == 1) actuatedD[1] *= 1.0+actuation;
//else if (neighborAxis == 2) actuatedD[2] *= 1.0+actuation; //else if (neighborAxis == 2) actuatedD[2] *= 1.0+actuation;
float kIndex_x = ((fragCoord.x-0.5)*12.0 + 2.0*(i*3.0+float(j)) + 0.5)/(u_textureDim.x*12.0);
vec2 kIndex = vec2(kIndex_x, scaledFragCoord.y);
vec3 translationalK = texture2D(u_compositeKs, kIndex).xyz;
vec3 translationalD = texture2D(u_compositeDs, kIndex).xyz;
vec4 averageQuaternion = averageQuaternions(quaternion, neighborQuaternion); vec4 averageQuaternion = averageQuaternions(quaternion, neighborQuaternion);
vec4 averageQuaternionInverse = invertQuaternion(averageQuaternion); vec4 averageQuaternionInverse = invertQuaternion(averageQuaternion);
...@@ -279,24 +274,7 @@ void main(){ ...@@ -279,24 +274,7 @@ void main(){
vec3 velocityDelta = neighborVelocity-velocity; vec3 velocityDelta = neighborVelocity-velocity;
vec3 velocityDeltaXYZ = applyQuaternion(velocityDelta, averageQuaternionInverse); vec3 velocityDeltaXYZ = applyQuaternion(velocityDelta, averageQuaternionInverse);
vec3 _force = vec3(0.0,0.0,0.0); vec3 _force = translationalK*translationalDeltaXYZ + translationalD*velocityDeltaXYZ;
//longitudal and shear
for (int _axis = 0; _axis < 3; _axis++) {
if (_axis == neighborAxis) {
_force[_axis] += longitudalK[_axis] * translationalDeltaXYZ[_axis] + longitudalD[_axis] * velocityDeltaXYZ[_axis];
} else {
if (neighborAxis == 0){
if (_axis == 1) _force[_axis] += shearK1[0] * translationalDeltaXYZ[_axis] + shearD1[0] * velocityDeltaXYZ[_axis];
else if (_axis == 2) _force[_axis] += shearK1[1] * translationalDeltaXYZ[_axis] + shearD1[1] * velocityDeltaXYZ[_axis];
} else if (neighborAxis == 1){
if (_axis == 0) _force[_axis] += shearK1[2] * translationalDeltaXYZ[_axis] + shearD1[2] * velocityDeltaXYZ[_axis];
else if (_axis == 2) _force[_axis] += shearK2[0] * translationalDeltaXYZ[_axis] + shearD2[0] * velocityDeltaXYZ[_axis];
} else if (neighborAxis == 2){
if (_axis == 0) _force[_axis] += shearK2[1] * translationalDeltaXYZ[_axis] + shearD2[1] * velocityDeltaXYZ[_axis];
else if (_axis == 1) _force[_axis] += shearK2[2] * translationalDeltaXYZ[_axis] + shearD2[2] * velocityDeltaXYZ[_axis];
}
}
}
//convert _force vector back into world reference frame //convert _force vector back into world reference frame
_force = applyQuaternion(_force, averageQuaternion); _force = applyQuaternion(_force, averageQuaternion);
force += _force; force += _force;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment