PDA

View Full Version : Multiple renders in one



jonipichoni
01-11-2012, 06:00 AM
here's my problem:

I want to particionate the canvas in 4 virtual quadrants and in every quadrant I want to render the same scene with different colors(with different fragment shaders), to compare some effects in real time. I am not sure how to do that. Should I render the same scene 4 times in 4 different textures and then refill 4 rectangles with those textures? Or should I make another fshader and manually fill all the fragments with those textures? Any posibility to user render buffer objects to increase performance?

Thanks in advance,

greggman
01-20-2012, 02:41 AM
For rendering to quadrants you can set the viewport and scissor



var views = [
{ left: 0,
bottom: 0,
width: canvas.width / 2,
height: canvas.height,
eye: [0, 0, -10],
target: [0, 0, 0],
up: [0,1, 0]
},
{ left: canvas.width / 2,
bottom: 0,
width: canvas.width / 2,
height: canvas.height,
eye: [-10, 0, 0],
target: [0, 0, 0],
up: [0,1, 0]
},
];

gl.enable(gl.SCISSOR_TEST);
for (var ii = 0; ii < views.length; ++ii) {
var view = views[ii];
gl.scissor(view.left. view.bottom, view.width, view.height);
gl.viewport(view.left, view.bottom, view.width, view.height);
drawScene(view.eye, view.target, view.up, view.fov);
}


Something like that.

There's a sample here
http://webglsamples.googlecode.com/hg/m ... views.html (http://webglsamples.googlecode.com/hg/multiple-views/multiple-views.html)

As far as rendering each one differently I think you'll need to draw everything 4 times, once with each set of different shaders.