Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas Zooming And Panning #437

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 80 additions & 47 deletions dist/infragram2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ uniform int uColorized;
uniform int uSelectColormap;
uniform int uHsv;
uniform int uColormap;
uniform vec2 uScale;


vec4 greyscale_colormap(float n) {
vec2 x = vec2(0.0, 1.0);
Expand Down
5 changes: 4 additions & 1 deletion dist/shader.vert
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
attribute vec2 aVertexPosition;

varying vec2 vTextureCoord;
uniform vec2 uScale;
uniform vec2 uTranslation;

void main(void)
{
gl_Position = vec4(aVertexPosition, 0.0, 1.0);

gl_Position = vec4((aVertexPosition * uScale) + uTranslation, 0.0, 1.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is a tough one! The translation within webGL is mathematically tough!

What about... would it work to do the panning outside of the image processing flow -- like, after it's been rendered, could we pan around a really large HTML element? Would that be easier? Could we use something like this library to do that? (it uses CSS i believe?)

https://cmorillas.github.io/panzoom/

What do you think? Can you tell us a bit more about what the issues are that you're trying to solve in the panning? What specifically makes you feel it's not working well, or what do you imagine it to be if it were working well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jywarren. Attributing mouse coordinates to the WebGL texture was a headache. The https://cmorillas.github.io/panzoom/ is a life saver. Thank you!

vTextureCoord = (aVertexPosition + 1.0) / 2.0;
}
7 changes: 4 additions & 3 deletions index2.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -22,7 +23,7 @@
<script src="node_modules/webrtc-adapter/out/adapter.js"></script>
<script src="node_modules/getusermedia-js/dist/getUserMedia.min.js"></script>

<script src="dist/infragram2.js"></script>
<script src="dist/infragram.js"></script>

<script type="x-shader/x-vertex" id="shader-vs"></script>
<script type="x-shader/x-fragment" id="shader-fs-template"></script>
Expand Down Expand Up @@ -461,7 +462,7 @@ <h6 style="text-decoration:underline;">BLUE filters <i class="fa fa-filter" aria
</a>
</div>
<div class="zoom btn-group labeled" role="group" aria-label="Second group">
<input type="range" class="form-control-range" id="formControlRange">
<input type="range" min="0.1" max="5" value="1" step=".01" class="form-control-range" id="formControlRange">
</div>
<div class="btn-group" role="group" aria-label="Third group">
<a id="revert" role="button" type="button" class="btn btn-dark">
Expand Down Expand Up @@ -513,7 +514,7 @@ <h6 style="text-decoration:underline;">BLUE filters <i class="fa fa-filter" aria
});

openInPl = function openInPl() {
var dataurl = infragram.options.processor.getCurrentImage();
var dataurl = infragram.options.processor.getCurrentImage();
function postToPL(imgSrc) {
var uniq = Date.now();
var color = $('#m_exp').val().substr(1,3) == "R-B" ? "blue" : "red";
Expand Down
30 changes: 29 additions & 1 deletion src/processors/webgl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.