Is it possible to use GL_ACCUM at all?

Mar 15, 2008 at 6:06pm

Is it possible to use GL_ACCUM at all?

I would really like to use the accumulation buffer in Jitter, but the
problem seems to be that it has needs to be activated when the context is
initialized. For example:

glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_ACCUM|GLUT_SINGLE);

Is it possible to have this kind of control from an ob3d external?

I’ve tied to use RTT instead, accumulating multiple render passes into a
texture, but that appears to be way to slow for want i want to do. For
example an 8 pass motion blur on a single rendered quad using a 1280×720
floating point texture gives me a framerate of about 15fps, so that’s really
no alternative. The FBO backend option is currently not working on my
system.

Am I naive to think its as simple as adding an @accumbuffer attribute to
jit.window and passing the flag to the window init? Please consider it a
feature request;-)

Thijs

#36362
Mar 15, 2008 at 6:27pm

How were you doing the RTT accumulation? Did you use feedback?
wes

2008/3/15 Thijs Koerselman

:
> I would really like to use the accumulation buffer in Jitter, but the
> problem seems to be that it has needs to be activated when the context is
> initialized. For example:
>
> glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_ACCUM|GLUT_SINGLE);
>
> Is it possible to have this kind of control from an ob3d external?
>
> I’ve tied to use RTT instead, accumulating multiple render passes into a
> texture, but that appears to be way to slow for want i want to do. For
> example an 8 pass motion blur on a single rendered quad using a 1280×720
> floating point texture gives me a framerate of about 15fps, so that’s really
> no alternative. The FBO backend option is currently not working on my
> system.
>
> Am I naive to think its as simple as adding an @accumbuffer attribute to
> jit.window and passing the flag to the window init? Please consider it a
> feature request;-)
>
> Thijs
>
>
>

#124740
Mar 15, 2008 at 7:59pm

On Sat, Mar 15, 2008 at 6:27 PM, Wesley Smith wrote:

> How were you doing the RTT accumulation? Did you use feedback?
> wes
>

Below is the Lua script I used. The shaders are taken from Randy Jones’
render node.

I realize that the performance hit mainly comes from calling
begincapture/endcapture for every frame, but I couldn’t figure out how to
make multiple renders add up in the same texture. Doing that and filtering
the texture once afterwards would be more efficient. I suspect there must be
a better way to clear the accum texture at the end as well. Still, the
framerate has to improve dramatically for this to be useful though.

Thijs

scene = jit.new(“jit.gl.texture”, this.drawto)
scene.dim = {1280, 720}
scene.type = “float32″

slabAccum = jit.new(“jit.gl.slab”, this.drawto)
slabAccum.file = “passthru.jxs”
slabAccum.dim = scene.dim

slabAdd = jit.new(“jit.gl.slab”, this.drawto)
slabAdd.file = “twowayadd.jxs”
slabAdd.dim = scene.dim

slabPass = jit.new(“jit.gl.slab”, this.drawto)
slabPass.file = “passthru.jxs”
slabPass.dim = scene.dim

vplane = jit.new(“jit.gl.videoplane”, this.drawto)
vplane.automatic = 0
vplane.transform_reset = 2
vplane.texture = slabAccum.out_name

gAccumWindow = 20
gAccumCount = 16

function draw(t)

slabAdd:param(“a”, (1/gAccumCount))
slabAdd:param(“b”, 1)

for i=1, gAccumCount, 1 do
— start capture
jit.gl.begincapture(scene.name, 0)
— render scene
tslice = t – ((i/gAccumCount) * gAccumWindow)
renderQuad(tslice)
— end capture
jit.gl.endcapture(scene.name, 0)

— accum add texture
doSlab(slabAdd, scene.name, slabPass.out_name)
doSlab(slabPass, slabAdd.out_name)
end

— pass on final accumulated texture
doSlab(slabAccum, slabPass.out_name)

— draw to screen
vplane:draw()

— clear accum texture
slabAdd:param(“a”, 0)
slabAdd:param(“b”, 0)
doSlab(slabAdd, scene.name, slabPass.out_name)
doSlab(slabPass, slabAdd.out_name)

end

function renderQuad(t)

local angle = t * 0.001 * 360.

gl.Color(1, 0, 0, 1)
gl.PushMatrix()
gl.Rotate(angle, 0, 0, 1)
gl.Begin(“QUADS”)
gl.Vertex(-0.01,1,0)
gl.Vertex(0.01,1,0)
gl.Vertex(0.01,-1,0)
gl.Vertex(-0.01,-1,0)
gl.End()
gl.PopMatrix()
end

function doSlab(slab, …)
local textures = {…}
slab.texture = textures;
slab:draw()
end

#124741
Mar 15, 2008 at 8:10pm

In your script, variable t is undefined.
wes

2008/3/15 Thijs Koerselman

:
> On Sat, Mar 15, 2008 at 6:27 PM, Wesley Smith wrote:
>
> > How were you doing the RTT accumulation? Did you use feedback?
> > wes
> >
>
> Below is the Lua script I used. The shaders are taken from Randy Jones’
> render node.
>
> I realize that the performance hit mainly comes from calling
> begincapture/endcapture for every frame, but I couldn’t figure out how to
> make multiple renders add up in the same texture. Doing that and filtering
> the texture once afterwards would be more efficient. I suspect there must be
> a better way to clear the accum texture at the end as well. Still, the
> framerate has to improve dramatically for this to be useful though.
>
> Thijs
>
>
> scene = jit.new(“jit.gl.texture”, this.drawto)
> scene.dim = {1280, 720}
> scene.type = “float32″
>
> slabAccum = jit.new(“jit.gl.slab”, this.drawto)
> slabAccum.file = “passthru.jxs”
> slabAccum.dim = scene.dim
>
> slabAdd = jit.new(“jit.gl.slab”, this.drawto)
> slabAdd.file = “twowayadd.jxs”
> slabAdd.dim = scene.dim
>
> slabPass = jit.new(“jit.gl.slab”, this.drawto)
> slabPass.file = “passthru.jxs”
> slabPass.dim = scene.dim
>
> vplane = jit.new(“jit.gl.videoplane”, this.drawto)
> vplane.automatic = 0
> vplane.transform_reset = 2
> vplane.texture = slabAccum.out_name
>
> gAccumWindow = 20
> gAccumCount = 16
>
>
> function draw(t)
>
> slabAdd:param(“a”, (1/gAccumCount))
> slabAdd:param(“b”, 1)
>
> for i=1, gAccumCount, 1 do
> — start capture
> jit.gl.begincapture(scene.name, 0)
> — render scene
> tslice = t – ((i/gAccumCount) * gAccumWindow)
> renderQuad(tslice)
> — end capture
> jit.gl.endcapture(scene.name, 0)
>
> — accum add texture
> doSlab(slabAdd, scene.name, slabPass.out_name)
> doSlab(slabPass, slabAdd.out_name)
> end
>
> — pass on final accumulated texture
> doSlab(slabAccum, slabPass.out_name)
>
> — draw to screen
> vplane:draw()
>
> — clear accum texture
> slabAdd:param(“a”, 0)
> slabAdd:param(“b”, 0)
> doSlab(slabAdd, scene.name, slabPass.out_name)
> doSlab(slabPass, slabAdd.out_name)
>
> end
>
> function renderQuad(t)
>
> local angle = t * 0.001 * 360.
>
> gl.Color(1, 0, 0, 1)
> gl.PushMatrix()
> gl.Rotate(angle, 0, 0, 1)
> gl.Begin(“QUADS”)
> gl.Vertex(-0.01,1,0)
> gl.Vertex(0.01,1,0)
> gl.Vertex(0.01,-1,0)
> gl.Vertex(-0.01,-1,0)
> gl.End()
> gl.PopMatrix()
> end
>
> function doSlab(slab, …)
> local textures = {…}
> slab.texture = textures;
> slab:draw()
> end
>
>
>
>
>
>

#124742
Mar 15, 2008 at 8:15pm

On Sat, Mar 15, 2008 at 8:10 PM, Wesley Smith wrote:

> In your script, variable t is undefined.
> wes
>

I use jit.gl.lua in @automatic 0 and call draw explicitly with a time
argument in ms, so t is the argument.

Thijs

>
> 2008/3/15 Thijs Koerselman

:
> > On Sat, Mar 15, 2008 at 6:27 PM, Wesley Smith
> wrote:
> >
> > > How were you doing the RTT accumulation? Did you use feedback?
> > > wes
> > >
> >
> > Below is the Lua script I used. The shaders are taken from Randy Jones’
> > render node.
> >
> > I realize that the performance hit mainly comes from calling
> > begincapture/endcapture for every frame, but I couldn’t figure out how
> to
> > make multiple renders add up in the same texture. Doing that and
> filtering
> > the texture once afterwards would be more efficient. I suspect there
> must be
> > a better way to clear the accum texture at the end as well. Still, the
> > framerate has to improve dramatically for this to be useful though.
> >
> > Thijs
> >
> >
> > scene = jit.new(“jit.gl.texture”, this.drawto)
> > scene.dim = {1280, 720}
> > scene.type = “float32″
> >
> > slabAccum = jit.new(“jit.gl.slab”, this.drawto)
> > slabAccum.file = “passthru.jxs”
> > slabAccum.dim = scene.dim
> >
> > slabAdd = jit.new(“jit.gl.slab”, this.drawto)
> > slabAdd.file = “twowayadd.jxs”
> > slabAdd.dim = scene.dim
> >
> > slabPass = jit.new(“jit.gl.slab”, this.drawto)
> > slabPass.file = “passthru.jxs”
> > slabPass.dim = scene.dim
> >
> > vplane = jit.new(“jit.gl.videoplane”, this.drawto)
> > vplane.automatic = 0
> > vplane.transform_reset = 2
> > vplane.texture = slabAccum.out_name
> >
> > gAccumWindow = 20
> > gAccumCount = 16
> >
> >
> > function draw(t)
> >
> > slabAdd:param(“a”, (1/gAccumCount))
> > slabAdd:param(“b”, 1)
> >
> > for i=1, gAccumCount, 1 do
> > — start capture
> > jit.gl.begincapture(scene.name, 0)
> > — render scene
> > tslice = t – ((i/gAccumCount) * gAccumWindow)
> > renderQuad(tslice)
> > — end capture
> > jit.gl.endcapture(scene.name, 0)
> >
> > — accum add texture
> > doSlab(slabAdd, scene.name, slabPass.out_name)
> > doSlab(slabPass, slabAdd.out_name)
> > end
> >
> > — pass on final accumulated texture
> > doSlab(slabAccum, slabPass.out_name)
> >
> > — draw to screen
> > vplane:draw()
> >
> > — clear accum texture
> > slabAdd:param(“a”, 0)
> > slabAdd:param(“b”, 0)
> > doSlab(slabAdd, scene.name, slabPass.out_name)
> > doSlab(slabPass, slabAdd.out_name)
> >
> > end
> >
> > function renderQuad(t)
> >
> > local angle = t * 0.001 * 360.
> >
> > gl.Color(1, 0, 0, 1)
> > gl.PushMatrix()
> > gl.Rotate(angle, 0, 0, 1)
> > gl.Begin(“QUADS”)
> > gl.Vertex(-0.01,1,0)
> > gl.Vertex(0.01,1,0)
> > gl.Vertex(0.01,-1,0)
> > gl.Vertex(-0.01,-1,0)
> > gl.End()
> > gl.PopMatrix()
> > end
> >
> > function doSlab(slab, …)
> > local textures = {…}
> > slab.texture = textures;
> > slab:draw()
> > end
> >
> >
> >
> >
> >
> >
>

#124743
Mar 15, 2008 at 8:16pm

> On Sat, Mar 15, 2008 at 8:10 PM, Wesley Smith wrote:
> > In your script, variable t is undefined.
> >
> > wes
> >
>
> I use jit.gl.lua in @automatic 0 and call draw explicitly with a time
> argument in ms, so t is the argument.

Ah, I see that now. Anyway, I believe I have a solution I’ll post in a bit.
wes

#124744
Mar 15, 2008 at 8:29pm

Hopefully this will work for you. This script is equivalent to
jit.gl.render @erase_color 0 0 0 0.1 but does it with shaders.

–scene texture
local scene = jit.new(“jit.gl.texture”, this.drawto)
scene.dim = {1280, 720}
scene.type = “float32″

–accumulation and decay (equivalent to jit.gl.render @erase_color)
local accum = jit.new(“jit.gl.slab”, this.drawto)
accum.file = “co.accum.jxs”
accum:param(“erase_color”, {0, 0, 0, 0.1})
accum.dim = scene.dim

–pass thru for copy
local passthru = jit.new(“jit.gl.slab”, this.drawto)
passthru.dim = scene.dim

–set slab textures
accum.texture = {scene.name, passthru.out_name}
passthru.texture = accum.out_name

local vplane = jit.new(“jit.gl.videoplane”, this.drawto)
vplane.automatic = 0
vplane.transform_reset = 2
vplane.texture = accum.out_name

local t = 0
local dt = 1/33

function draw()
jit.gl.begincapture(scene.name, 0)
renderQuad(t)
jit.gl.endcapture(scene.name, 0)

–process texture
accum:draw() –accumulate and decay
passthru:draw() –copy texture for feedback

vplane:draw()

t = t + dt
end

function renderQuad(t)

local angle = t*20

gl.Color(1, 0, 0, 1)
gl.PushMatrix()
gl.Rotate(angle, 0, 0, 1)
gl.Begin(“QUADS”)
gl.Vertex(-0.01,1,0)
gl.Vertex(0.01,1,0)
gl.Vertex(0.01,-1,0)
gl.Vertex(-0.01,-1,0)
gl.End()
gl.PopMatrix()
end

—————————————————– And the shader
//co.accum.jxs



Accumulator

fade amount




< ![CDATA[

// texcoords
varying vec2 texcoord0;
varying vec2 texcoord1;

// samplers
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;

// accum amount
uniform vec4 erase_color;

// entry point
void main()
{
vec4 current = texture2DRect(tex0, texcoord0);
vec4 previous = texture2DRect(tex1, texcoord1);

//simulation of jit.gl.render’s @erase_color attribute
vec4 framebuffer = mix(previous, erase_color, erase_color.a);

gl_FragColor = framebuffer + current;
// gl_FragColor = framebuffer;
}

]]>

#124745
Mar 15, 2008 at 10:39pm

Thanks a lot for your help Wes, but I’m afraid this approach doesn’t make
much of a difference for me. I understand that adding frames like this gives
a lot better performance, since you only do one render pass per frame. For a
real motion blur this doesn’t cut it, because I need to render in-between
frames, rather than accumulating previous ones.

I also intended to use the accumulation buffer to do DOF and possibly anti
aliasing. Since there is no way around multiple render passes for this, I
need to utilize the full power of the GPU. I know DOF and motion blur can be
faked as a post processing effect, but I really want to do these in high
quality. The post processing alternative is not very useful for what I had
in mind, since it gives very obvious artifacts in certain situations.

I really hope you / C74 will consider enabling the accumulation buffer for
the render context. Even though none of the current Jitter objects make use
of this buffer, at least it gives people the option to use it through C and
Lua and such.

I’m curious to see what performance boost FBO will give, and once Apple
finally sorts out the 8800 support for pre 2008 macs I’ll consider upgrading
my graphics card. For now I’ll just have to forget about this and be
patient.

Cheers,
Thijs

On Sat, Mar 15, 2008 at 8:29 PM, Wesley Smith wrote:

> Hopefully this will work for you. This script is equivalent to
> jit.gl.render @erase_color 0 0 0 0.1 but does it with shaders.
>
> –scene texture
> local scene = jit.new(“jit.gl.texture”, this.drawto)
> scene.dim = {1280, 720}
> scene.type = “float32″
>
> –accumulation and decay (equivalent to jit.gl.render @erase_color)
> local accum = jit.new(“jit.gl.slab”, this.drawto)
> accum.file = “co.accum.jxs”
> accum:param(“erase_color”, {0, 0, 0, 0.1})
> accum.dim = scene.dim
>
> –pass thru for copy
> local passthru = jit.new(“jit.gl.slab”, this.drawto)
> passthru.dim = scene.dim
>
> –set slab textures
> accum.texture = {scene.name, passthru.out_name}
> passthru.texture = accum.out_name
>
>
> local vplane = jit.new(“jit.gl.videoplane”, this.drawto)
> vplane.automatic = 0
> vplane.transform_reset = 2
> vplane.texture = accum.out_name
>
>
> local t = 0
> local dt = 1/33
>
> function draw()
> jit.gl.begincapture(scene.name, 0)
> renderQuad(t)
> jit.gl.endcapture(scene.name, 0)
>
> –process texture
> accum:draw() –accumulate and decay
> passthru:draw() –copy texture for feedback
>
> vplane:draw()
>
> t = t + dt
> end
>
> function renderQuad(t)
>
> local angle = t*20
>
> gl.Color(1, 0, 0, 1)
> gl.PushMatrix()
> gl.Rotate(angle, 0, 0, 1)
> gl.Begin(“QUADS”)
> gl.Vertex(-0.01,1,0)
> gl.Vertex(0.01,1,0)
> gl.Vertex(0.01,-1,0)
> gl.Vertex(-0.01,-1,0)
> gl.End()
> gl.PopMatrix()
> end
>
>
>
> —————————————————– And the shader
> //co.accum.jxs
>
>
>
> Accumulator
>

>

> fade amount
>
>

>

>
>
>
>
>

> < ![CDATA[
>
> // texcoords
> varying vec2 texcoord0;
> varying vec2 texcoord1;
>
> // samplers
> uniform sampler2DRect tex0;
> uniform sampler2DRect tex1;
>
> // accum amount
> uniform vec4 erase_color;
>
> // entry point
> void main()
> {
> vec4 current = texture2DRect(tex0, texcoord0);
> vec4 previous = texture2DRect(tex1, texcoord1);
>
> //simulation of jit.gl.render’s @erase_color attribute
> vec4 framebuffer = mix(previous, erase_color, erase_color.a);
>
> gl_FragColor = framebuffer + current;
> // gl_FragColor = framebuffer;
> }
>
> ]]>
>
>

>
>

#124746
Sep 30, 2011 at 1:31pm

is there any documentation on how to use the co.accum.jxs shader? I want an endless feedback (as in erase_color 0 0 0 0) on a sketch that is captured into a texture. But the above post is on lua?
any help would be welcome

best

pieter

#124747

You must be logged in to reply to this topic.