Jump to content

Post-processing effects test (SSAO/HDR/Bloom)


Recommended Posts

The LOD thing we were talking about yesterday. Effects that recede into the background should be able to replace themselves with less resource-intensive alternatives.

Are you aware of the <depth func="..."/> tag that can be specified per <pass>? It maps to glDepthFunc. Doesn't that effectively allow one to specify the distances at which a given shader should apply?

I think that would require us to recompile each shader for every frame. Not really efficient.

Maybe "defines" would be used, then? But then the configuration system should be able to get a list of possible defines from somewhere...

Link to comment
Share on other sites

Are you aware of the <depth func="..."/> tag that can be specified per <pass>? It maps to glDepthFunc. Doesn't that effectively allow one to specify the distances at which a given shader should apply?

That's the comparison function for the depth buffer, so geometry that is behind other geometry doesn't get drawn. Completely different thing.

Maybe "defines" would be used, then? But then the configuration system should be able to get a list of possible defines from somewhere...

Define is for compiling, so same problem. We need something that does the comparison dynamically in the engine. It should be easy to do, though I'm afraid it'll have to wait till the weekend (as usual).

Link to comment
Share on other sites

Add to this the possibility of hardware detection and automatic enabling/disabling of some effects. I don't like the possibility of not allowing a user to even access an effect because it would be too slow, though.

I quite agree, though a warning is always nice (we could deactivate specific stuff it they would cause a bug, however).

Link to comment
Share on other sites

For the final game release, we probably want a build script, that is perhaps separate from the main build scripts, that detects what meshes have been added/changed and calls Blender to bake their AO automatically.

It would be handy to have a Blender script for automating the multiple UV set creation and AO baking. My thinking is even if AO support is added to the engine today, requiring artists to import every DAE, add a second UV set, export a new DAE and bake the AO texture, allowing for human error at every step, will be so time-consuming and boring that it will be put off due to higher priorities and interests.

Several minutes is probably too long to generate a high quality AO texture on the fly and we have to consider slower computers (mine can handle about 8 threads at a time) :( I don't see that we need a lower quality GPU approximation, though it might be nice to see how it looks in practice for a comparison. I was wondering if we couldn't do the actual raytracing algorithm on the GPU since they are highly parallel by nature.

Link to comment
Share on other sites

regarding murkiness: Yay! i guessed right!

@historic_bruno Do you mean have blender use the gpu? or use the gpu for the lower alternative? I don't know blender, but if you can give it a script from the command line, this seems the type of thing that would easily be added to the build system. Even a straight up makefile would probably work.

Link to comment
Share on other sites

Several minutes is probably too long to generate a high quality AO texture on the fly and we have to consider slower computers (mine can handle about 8 threads at a time) :( I don't see that we need a lower quality GPU approximation, though it might be nice to see how it looks in practice for a comparison. I was wondering if we couldn't do the actual raytracing algorithm on the GPU since they are highly parallel by nature.

I know proper GPU raytracing can be done with OpenCL... though it's tricky to do with GLSL shaders.

For raytracing you need access to your entire model, so for each point you can cast a bunch of rays and check if they collide with any other parts of the model. Shaders only have local info about the triangle they are currently rendering, so obviously that's a problem.

Assuming we don't want to use the shadowmapping method and we want to try real GPU raytracing, I've been thinking about what kind of algorithms we can try. The good thing about AO calculation is that we don't care about the colour of each ray, just whether it shoots into the sky.

One possible solution is to first render the model into a 3d texture (on either CPU or GPU) and then do the actual tracing of rays by "walking" through the texture on the GPU. This alone may be enough for our purposes, but this paper goes a step further and passes in a data structure (stored in a texture) with the triangle data that occurs in each voxel, and thus calculates exactly what the ray hits.

A 2563 3d texture is 16MB. 5123 is 128MB. Seems totally feasible, I think... but we'll have to try it to be sure.

Edited by myconid
Link to comment
Share on other sites

What this project ( I mean 0 AD in general) really needs is a weekly report 'the week in review' (or sth alike)

Our new website (when it's finished) will have team member blogs and such. I'm sure trusted folks such as yourself would be able contribute in one way or another.

Link to comment
Share on other sites

Its kind of tedious, you basically remake the entire texture with lots of gradient work. Lets see how this works out. Next up will be a specular and light map for it.

I'll give this a try! Btw, have you considered using this heightmap with the "displace" modifier in Blender? Maybe we could bake more detailed AO maps that way, and you could use the sculpting tools to improve your results.

Link to comment
Share on other sites

Fastest way to me would be:

Create a heightmap using CrazyBump (from the texture). Start up Gimp/photoshop/whatever and quickly fix the most obvious problems (color inversion…). Load the model in blender, tesselate/subsurf, displace using said heightmap, paint the texture to fix the problems (live in Blender, I mean), save texture, apply the modifier and bake the normals in Blender (using one of many tutorials). Then merge these two files in Gimp/Photoshop/whatever.

Edited by wraitii
Link to comment
Share on other sites

Its kind of tedious, you basically remake the entire texture with lots of gradient work. Lets see how this works out. Next up will be a specular and light map for it.

Alright, here are two big screenshots:

9wPh7.jpg

There are some tiling artifacts on the stone part of the roof, but otherwise this looks gorgeous.

gD9V1.jpg

Download the attachments for the massive versions, if they'll be more helpful.

post-14564-0-89529200-1342267889_thumb.j

post-14564-0-21650000-1342267968_thumb.j

Edited by myconid
Link to comment
Share on other sites

Cool, that did turn out pretty good. I see some fixes I need to make to the texture and the artifacts you mention (I'll need to modify the UV mapping on the model to fix that). I think there would be a big benefit to do some mapping to some of the things I avoided like the pediment, eagle, and statue too.

Q, does the AO generator take into account the normal maps?

Link to comment
Share on other sites

Alright, I've now implemented effects that can disable themselves with distance. It's done through the materials files and controlled from the config without hardcoding anything. :)

Instead of using "define" to set up effects in the materials, we can use "conditional_define" that looks like this:


<conditional_define name="USE_PARALLAX_MAP" value="1" type="draw_range" conf="parallaxdist"/>

This tells it that we want the shaders to see a define of that name/value only when the "draw_range" condition type is true with the values it gets from the "parallaxdist" set of values in the config file. In the config, this will appear like this


materialmgr.parallaxdist.max = 120

i.e. parallax is enabled only when the distance to the model is up to 120 units away.

If we set this to a value less than 0 (e.g. -1) the effect is always on. If the value is 0 then the effect is always off.

Code: https://github.com/myconid/0ad/tree/effectdistance2

Link to comment
Share on other sites

Cool, that did turn out pretty good. I see some fixes I need to make to the texture and the artifacts you mention (I'll need to modify the UV mapping on the model to fix that). I think there would be a big benefit to do some mapping to some of the things I avoided like the pediment, eagle, and statue too.

You could look at how the automatically-generated normalmap worked around that issue. Afaik, this wasn't a problem with that.

Q, does the AO generator take into account the normal maps?

In Blender, no. We'd need to explicitly turn the heightmap into geometry for it to affect the AO.

Link to comment
Share on other sites

Seems like it would be working great, Myconid. Basically, you switch shaders on the fly?

Yeah, something like that.

What's left to do is to somehow pass the config values into the shaders, so they know when to fade themselves out. This can probably be done using defines.

Link to comment
Share on other sites

Ok, done with the effects distance. Unrolled GLSL loop and using the new system with it, with 2 different quality levels.

I haven't checked the stats, but it definitely feels like it's faster now!

wraitii, when you get a chance see if this works with your ARB shader. :)

fabio, if you're still looking at this thread, can you check if the updated parallax effect works on your X1600?

Link to comment
Share on other sites

I'll try to finish the water stuffs (notably waves) first, and then port everything else to ARB, I'll check at that time, but there's no reason to imagine it wouldn't work.

I can test in the following days. It's on git at https://github.com/m...id/0ad/branches ? Which branch?

There's no hurry, test whenever you have time. The branch is "effectdistance2".

Link to comment
Share on other sites

This grass effect. If it's too slow for terrain, what about applying it to a farm field decal and use the feature for nice-looking 3-D farms that conform to the terrain grid?

At the very least, that would give me an excuse to implement fancy materials for decals. ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...