Re: Re: RE: Depth of field style blur shader + global illum/soft shadow shader?

Feb 10, 2009 at 7:27pm

Re: Re: RE: Depth of field style blur shader + global illum/soft shadow shader?

Havent had the chance to try it out yet, been busy with freelance and this installation im working on for MOCA. Anyone else?

I was thinking it might work to use a modified blur shader that detects distance from camera and blurs each object based on that, but im still a baby at this.

#41823
Feb 22, 2009 at 2:07am

I was looking at the different messages that you can send to jit.gl.render, and I saw something that I cant find again, but it was somethign along the lines of capture depth buffer… or something like that.. is there a way to get the depth buffer into a texture or matrix?

http://farm4.static.flickr.com/3523/3297621481_1419f26916.jpg?v=0

wow finally links and images… I could go without the smilies…

____. .____
,.__________________._._. < <____/ |::| ____>>._._.__________________.,
-~=:!{[,,___________ ,.-~=:!ili!({[{[{[ http://www.axiom-crux.net ]}]}]})!ili!:=~-.,___________,,]}!:=~-
._/-_/-_/,.-----------' " \_, ,_, ,_// / ''' ' ' `----------.,__-_-_.
..----------------------../

#149078
Feb 22, 2009 at 3:07am
Axiom-Crux wrote on Sat, 21 February 2009 19:07
wow finally links and images… I could go without the smilies…

It’s not permanent. Remember that you can turn them off in your post (“Disable smilies in this post”).

After it got to 24 hours, I figured people would rather have an imperfect, yet being worked on forum back rather than no forum at all.

w

#149079
Feb 22, 2009 at 4:54am

are you referring to the smilies or the other tools as well? I quite like having images and html links… I think those speed up things alot, no more copy paste, just click. Images are nice too so we can show patch stills and such without also having to copy paste a link.

#149080
Feb 22, 2009 at 4:55am

#149081
Feb 22, 2009 at 12:29pm
Axiom-Crux wrote on Sun, 22 February 2009 03:07
is there a way to get the depth buffer into a texture or matrix

Yes, there’s a depth_grab message that copies the contents of the depth buffer to a named texture.

We’ve been using it to create depth of field type effect where the blur amount is based on the distance of the pixel from the focal point – this is a common technique for most games, imo.

After some investigation, we found out that depth_grab is pretty expensive operation, so we made a shader that writes depth info to gl_FragColor and render the whole scene twice, which in our case proved to be far more efficient that depth_grab.

#149082
Feb 23, 2009 at 12:24am

can I check out your depth of field effect? I have been looking for something like that. I am trying to learn shaders to do it myself but its taking a while to get up to speed.

Thank you either way nesa, your always a big help!

also, any thoughts on the technique on this page near the bottom:
http://fly.srk.fer.hr/~unreal/theredbook/chapter10.html

looks like they use the frame accumulation buffer to draw the frame a few times from slight different camera positions and that makes it slightly blurred ish.. I dont know if thats realistic for complex scenes in reatime.. maybe your technique with shaders is best.

#149083
Feb 23, 2009 at 7:13am

I would definitely recommend writing out depth information via a shader. This is how most real-time graphics engines do it these days (as opposed to using the depth buffer). Aside from potential performance issues, the reason for going this route is to have a linear encoding of distance. The depth buffer is non-linear for reasons I won’t go into suffice to say that it’s difficult/expensive to apply certain operations when the data is nonlinear.

If you’re going to try this out, be sure to set your texture type to float32 otherwise depth values will be clamped to [0, 1].

wes

#149084
Feb 23, 2009 at 7:48am
Axiom-Crux wrote on Sat, 21 February 2009 21:54
are you referring to the smilies or the other tools as well?

Just the smilies.

#149085
Feb 25, 2009 at 12:02am
Axiom-Crux wrote on Mon, 23 February 2009 01:24
can I check out your depth of field effect?

Well, the problem is that our shaders do a lot of stuff that’s particular to the system we’re building that it would make more sense to write new shader. Unfortunately at the moment I don’t have time to do it…
But I’d be glad to help you with building your own!

For the depth grabing shader you could use:

gl_FragCoord.z (more info here)

and use it to calculate gl_FragColor.

Then you apply this shader to whole scene and capture it to the texture that will contain depth info.

After this, you render&capture the whole scene again, but without ‘depthshader’

Now you can send both textures to a modified blur shader that changes the width of blur kernel based on the values from depth texture.

So there’s a lot of things to do to make DOF shader, even more to make it look good, but for start I would suggest just writing a simple shader that displays depth of each pixel, and when that is working we can continue for next step.

Quote:
also, any thoughts on the technique on this page near the bottom:
http://fly.srk.fer.hr/~unreal/theredbook/chapter10.html

This is how my grandpa would do it. And he would still get one WHAO! from me.

#149086
Feb 26, 2009 at 7:03pm

cool, Ill get to work on it as soon as I am done with my current installation project for MOCA.

I had figured that it would work like what you mentioned, though I wasn’t aware I would need to do 3 seperate renders for the whole thing. Also, to make the whole scene 1 shader(for the depth), do I have to assign each object to that shader seperately, or is there a way to send the whole render context to a shader, then bang that to a capture, then turn that shader off, bang that to another capture, and then apply the final blur kernel shader combinding the two and yet another render bang.

Is this crazy low fps?? can you do this at hd resolution or will it just be way too slow? do you need a really good graphics card to be able to do this at realtime smooth speeds?

Thanks for all the help! Id love to see any documentation (pictures or videos or anything) of the project your working on, as Im curious to see how this looks in the end. I am also just curious to see your work, as Ive seen many of your patches through the list and they are always quite innovative and clever.

Thanks again nesa, and wes!

#149087
Feb 28, 2009 at 2:26am

I was looking around and I remembered seeing a shader for vvvv that does depth of field. I went to their site and found it, its attached here. It says on their info page that they use HLSL, high level shader language. Is this usable in jitter? I remember hearing GLSL and CG and other abbreviations for shader types but I dont recall HLSL. I am curious if the attached files can be converted to work with jitter. Ive also added some links to the vvvv pages I referenced.

links:

http://vvvv.org/tiki-index.php?page=User+Shaders
http://vvvv.org/tiki-index.php?page=pixelshader_for_newbies

#149088
Mar 17, 2009 at 7:45am

Ok I have some time to work on this now, Im making the basic depth shader right now. I am curious if I can do the entire depth of field inside 1 shader? or do I have to do as I mentioned before and use a bunch of textures and combine them?

#149089
Mar 27, 2009 at 4:25am


Shader using color imported from opengl
//________________Variables


//________________vertex shader

< ![CDATA[
varying vec4 color;
void main(void)
{
color = gl_Color;
gl_Position = ftransform();
}
]]>
//__________________end vertex shader

//________________fragment shader

< ![CDATA[

varying vec4 color;
void main()
{
gl_FragColor.r = (color.r*(1./gl_FragCoord.w));
gl_FragColor.g = (color.g*(1./gl_FragCoord.w));
gl_FragColor.b = (color.b*(1./gl_FragCoord.w));
gl_FragColor.a = color.a;

}
]]>

//__________________end fragment shader

So here is my first shader, its a basic depth shader, you can set the focus distance by setting the brightness of the object. Any thoughts on where to go from here? Id like to slowly build it up into a full fledged crazy shader with textures for specular, bump, normal, displacement, depth of field, fog, etc… but obviously I need to start small. I want to try and make a nice depth of field shader first. So any recommendations from here?

#149090
Mar 27, 2009 at 4:54am

I think the one thing I am quite lost at is making a blur that references a texture for the blur amount. I understand it conceptually, but I don’t know where to start with making a blur that responds to each pixel and blurs based on the brightness of that pixel.

#149091
Mar 27, 2009 at 11:49am

Hi N,

Axiom-Crux wrote on Fri, 27 March 2009 05:54
I think the one thing I am quite lost at is making a blur that references a texture for the blur amount.

Basically, you need multiple render passes to display the final image:

grab depth
grab color
postproces+display

your blur/DOF shader would be in a slab used in postprocess part.
One input to slab would be the color texture, other input is the depth texture.

That shader can be a modified gaussian blur – cf.gaussian.2p.jxs

You would need to add additional texture input to it, then (for a start) you could just use the value of your depth texture to do a dry/wet mix between blurred and input texture, perhaps with something like this:

modify this line:

gl_FragColor = 0.1752 * sampleM + 0.1658 * (sampleB0 + sampleF0) + 0.1403 * (sampleB1 + sampleF1) + 0.1063 * (sampleB2 + sampleF2);

to

vec4 blurred = 0.1752 * sampleM + 0.1658 * (sampleB0 + sampleF0) + 0.1403 * (sampleB1 + sampleF1) + 0.1063 * (sampleB2 + sampleF2);

with this you have stored blurred pixel, and in next step you can sample the depth texture and use that value to do the final mix:

float depth = texture2DRect(depth,texcoordM);
gl_FragColor = mix(sampleM, blurred, depth);

I don’t know if this code is 100% correct as I typed it directly in browser, but it should work as pseudocode:)

For a nicer effect, you could use depth information to modify the width of the kernel instead of just mix amount.

#149092
Mar 27, 2009 at 2:00pm

Yeah thats what I was thinking of doing, modifying the blur width rather then the mix, but I am not sure how to make a blur based on a texture. Ill look around and see if I can find something on the net in that realm, but for now your mix method seems like a good way to get a quick proof of concept version done.

Thanks again Very Happy

#149093
Mar 27, 2009 at 3:00pm

Is the code you typed glsl? I wasn’t sure if it was just your pseudocoding, it seemed like it was a bit different.

Man I been reading the orange book and studying tutorials for 2 days, and I can say that I am way geeked to finally be getting into this, after seeing various demos on the net I think that shaders are really the only way to go for creating lush high resolution imagery in jitter. Its really cool to know that they will be adaptable into a higher level language if I ever have the need too!

#149094
Mar 27, 2009 at 5:38pm

Not sure how much this helps your cause, but I had written a luminance-based version of the built-in cf.gaussian.2p.jxs awhile back and finally got around to making it a little more presentable. It will probably be a lot more effective in a multi-pass setup (a la jit.gl.slab.gauss6x). HTH.

Andrew B.

#149095
Mar 27, 2009 at 11:33pm

perfect, sounds like exactly what I needed, thanks andrew! Ill check it out and try and hook up a depth of field shader in the mornin.

on a side note, Im also trying to figure out how to do shadows. I found very little documentation on the things I need in jitter. In the texture reference here is what I found:

>>>>this part talks about shadow mapping, only reference to shadows in all of the jitter distro!!!

compare_func symbol Sets the comparison function for shadow mapping when the texture is a depth texture.
compare_mode symbol Sets the comparison mode for shadow mapping when the texture is a depth texture.

other relevant info_____________________

capture_buffer symbol The word capture_buffer, followed by a symbol, sets which buffer to capture when the target of an ob3d @capture attribute. Valid options are:
color
depth
capture_depthbits int The word capture_depthbits, followed by a number, sets the number of bits of the depth buffer for render-to-texture mode.
capture_source symbol The word capture_source, followed by a symbol, sets the name of the target buffer to read from (such as the depth buffer) of an RTT texture.
colormode symbol The colorspace mode to use. (default = auto) Supported modes are:
alpha
depth
intensity
luminance
lumalpha
rgb
argb
uyvy
auto

so what symbol should I send? how do I set something up to make a shadow texture buffer? has anyone done it ever?? Ive looked a ton!!

thanks guys!

#149096
Mar 29, 2009 at 9:47pm

so here is a basic implementation with just jitter depth and andrews blur, make sure you download the file andrew posted if your going to try this out. Im curious if others get the same error I do, which is that hardware doesn’t support depth textures, even though it works fine, maybe its a loadbang order thing.

going to put in my shader version shortly, but that wont take long, more concerned with figuring out how to calculate accessability in realtime for the ambient occlusion shader, and tryng really hard to figure out how the heck to get shadows working, I cant believe I cant find anyone who has done shadows in jitter before..??!!? I found one thing from a long time ago where wes or someone did a basic shadow type thing, but it wasn’t real shadows, just a flat capture texture that was emulating a shadow, and it doesn’t seem to work in my computer. Is there anyone who has done shadows in jitter? I know im not the first to try it.

#149097
Mar 30, 2009 at 2:15pm

i get
jit.gl.texture: unsupported texture format!
in the max window, but also the shader done not work not my graphics card, if i load the patch with out the shader in the search pat i get the same error

#149098
Apr 4, 2009 at 7:02pm

the blur shader doesn’t work on your card? thats odd.. does anyone else know what this might be from? which card do you have and what computer/max version?

#149099
Apr 5, 2009 at 6:54am

I had the same error, which is quite strange:
unsupported texture format

My specs:
MCP 10.5.6, 2.53 GHz+4 GB
NVIDIA 9400M+NVIDIA 9600M
Max 5.0.6

Emmanuel

#149100
Apr 6, 2009 at 12:18pm

i have a macbook
2 ghz intel core 2 duo
1 gb ram
graphic card GMA 950
osx 10.4.11
max 5.0.2

any ideas?

thanks ben

#149101
Apr 6, 2009 at 10:43pm

but did it work? did you try clicking the :jitter fbo or rtt boxes?

#149102
Apr 7, 2009 at 7:37pm

no did not work, tried the the box but nothing, when i change the shader in the slab i get a torus in the window

#149103
Mar 19, 2010 at 1:02pm

Hello,

Can someone re-post Andrew’s luminance-based blur shader ?
It seems it has been lost with the new forum.

Thanks

Léo

#149104
Mar 20, 2010 at 8:12pm

Hi Léo

Here it is.

#149105
Mar 21, 2010 at 10:29am

Thanks

Léo

#149106

You must be logged in to reply to this topic.