0

Is there a way to add camera roll to third party webgl application?

Lets say, I have a webgl application, lets take ESRI Manhattan Skyscrappers Explorer as example.

ESRI camera api doesn't have Roll angle for camera, but still it's webgl application.

First part of the question: can I get the same context as a running application with the following code:

var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");

Saying same context I mean, If I add a shader via gl.useProgram(shaderProgram); is that possible to get access to the results of previously run shaders? Or are all of the shader programs isolated?

Next step: if I can submit a shader which will be able to modify vertex coordinates, how should I control the order of shader programs execution?

And finnaly if all that is possible maybe there is already something what I can use to calculate a right transform to get roll?

Is that even possible to "hijack" webgl camera or did I get the webgl pipline working principles wrong and it's impossible? Also I know that I can rotate the whole canvas element, but I'm looking for better approach, (canvas rotation is slow, and image quality is quite poor).

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
dkiselev
  • 890
  • 8
  • 20

1 Answers1

1

is that possible to get access to the results of previously run shaders? Or are all of the shader programs isolated?

That depends on what you mean by "results". You can read the contents of the canvas with gl.readPixels. You can copy the contents of the canvas to a texture for use in more rendering with either gl.texImage2D or gl.copyTexImage2D

Next step: if I can submit a shader which will be able to modify vertex coordinates, how should I control the order of shader programs execution?

Probably not

And finnaly if all that is possible maybe there is already something what I can use to calculate a right transform to get roll?

It is possible to roll

Is that even possible to "hijack" webgl camera or did I get the webgl pipline working principles wrong and it's impossible? Also I know that I can rotate the whole canvas element, but I'm looking for better approach, (canvas rotation is slow, and image quality is quite poor).

There's really nothing WebGL about adding roll to an existing program. You'd have to modify the program and modify where it calculates its view matrix or model view matrix in JavaScript.

Might I suggest you read some tutorials on WebGL and maybe it will be clearer that the changes you'd need to make would be in JavaScript, not in the shaders.

gman
  • 100,619
  • 31
  • 269
  • 393
  • Can I access the results of previously run vertex shader? Here in the accepted answer example https://stackoverflow.com/questions/7328472/how-webgl-works vertex shader fills the `gl_Position` array, is that variable shared between different shaders? Can I submit another vertex shader and rotate vertices within array filled by onother vertex shader? – dkiselev Nov 14 '17 at 14:55
  • 1
    No, gl_Position not shared between different shaders. No, you can not rotate vertices from one shader in a different shader. – gman Nov 14 '17 at 15:00