Commit 9cc33b08 authored by amandaghassaei's avatar amandaghassaei

adding in boundary program

parent ed182096
......@@ -17,6 +17,28 @@
}
</script>
<script id="boundaryShader" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D u_texture;
uniform float u_scale;
uniform vec2 u_textureSize;
void main() {
vec2 fragCoord = gl_FragCoord.xy;
vec4 neighborVal;
if (fragCoord.x < 1.0){
neighborVal = texture2D(u_texture, (fragCoord + vec2(1.0, 0.0))/u_textureSize);
gl_FragColor = u_scale*neighborVal;
return;
}
gl_FragColor = texture2D(u_texture, (fragCoord)/u_textureSize);
}
</script>
<script id="2d-render-shader" type="x-shader/x-fragment">
precision mediump float;
......@@ -204,9 +226,9 @@
<script type="text/javascript" src="dependencies/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="dependencies/flat-ui.min.js"></script>
<script type="text/javascript" src="GLBoilerplate.js"></script>
<script type="text/javascript" src="GPUMath.js"></script>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript" src="js/GLBoilerplate.js"></script>
<script type="text/javascript" src="js/GPUMath.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
......
......@@ -122,7 +122,8 @@ function initBoilerPlate(){
function loadVertexData(gl, program) {
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ -1,-1, 1,-1, -1, 1, 1, 1]), gl.STATIC_DRAW);
var val = 0.9;
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ -val,-val, val,-val, -val, val, val, val, val, val, val, -val, -val, val, -val, -val]), gl.STATIC_DRAW);
// look up where the vertex data needs to go.
var positionLocation = gl.getAttribLocation(program, "a_position");
......
......@@ -110,6 +110,17 @@ function initGPUMath(){
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);//draw to framebuffer
};
GPUMath.prototype.stepBoundary = function(programName, inputTextures, outputTexture){
gl.useProgram(this.programs[programName].program);
gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffers[outputTexture]);
for (var i=0;i<inputTextures.length;i++){
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, this.textures[inputTextures[i]]);
}
gl.drawArrays(gl.LINES, 0, 8);//draw to framebuffer
};
GPUMath.prototype.swapTextures = function(texture1Name, texture2Name){
var temp = this.textures[texture1Name];
this.textures[texture1Name] = this.textures[texture2Name];
......
......@@ -65,6 +65,9 @@ function initGL() {
GPU.createProgram("render", "2d-vertex-shader", "2d-render-shader");
GPU.setUniformForProgram("render", "u_material", 0, "1i");
GPU.createProgram("boundary", "2d-vertex-shader", "boundaryShader");
GPU.setUniformForProgram("boundary", "u_texture", 0, "1i");
resetWindow();
render();
......@@ -80,7 +83,10 @@ function render(){
GPU.setUniformForProgram("advect" ,"u_textureSize", [width, height], "2f");
GPU.setUniformForProgram("advect" ,"u_scale", 1, "1f");
GPU.step("advect", ["velocity", "velocity"], "nextVelocity");
GPU.swapTextures("velocity", "nextVelocity");
// GPU.setProgram("boundary");
// GPU.setUniformForProgram("boundary", "u_scale", -1, "1f");
// GPU.stepBoundary("boundary", ["nextVelocity"], "velocity");
//diffuse velocity
GPU.setProgram("jacobi");
......@@ -143,7 +149,7 @@ function resetWindow(){
actualHeight = body.clientHeight;
var maxDim = Math.max(actualHeight, actualWidth);
var _scale = maxDim/200;
var _scale = maxDim/150;
width = Math.floor(actualWidth/_scale);
height = Math.floor(actualHeight/_scale);
......@@ -168,6 +174,8 @@ function resetWindow(){
GPU.setUniformForProgram("jacobi" ,"u_textureSize", [width, height], "2f");
GPU.setProgram("render");
GPU.setUniformForProgram("render" ,"u_textureSize", [actualWidth, actualHeight], "2f");
GPU.setProgram("boundary");
GPU.setUniformForProgram("boundary" ,"u_textureSize", [width, height], "2f");
var velocity = new Float32Array(width*height*4);
// for (var i=0;i<height;i++){
......
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