Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

An update to Anim8or, v1.00b, is available with a few bug fixes. Get your copy HERE. See the "ReadMe" file for details.

Author Topic: AOBake  (Read 4385 times)

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
AOBake
« on: February 25, 2014, 07:35:10 am »

AOBake v0.2
Ok, so I lied. My next script ended up being impractical again. Welcome to AOBake, a raytraced Ambient Occlusion texture baking script for Anim8or.

Description
To use this, select mesh shapes or faces in a mesh shape that you want to bake the AO for. Alternatively you can select nothing and it'll bake AO for all shapes in the object. This script writes all of the selection onto one   texture, so be wary of overlapping UVs from different objects.
   
Go to Build->Export, and select the "Bake AO to PPM Image" (.ppm) file format and save to the file name of your choice. Anim8or will then generate the AO. You can track the progress in the console.

The .ppm format can be opened in image editors such as GIMP and Photoshop

Attribute Options:
AO_Width: (int [Default 128]) Sets the width of the texture in pixels (Default 128). Increasing this value slows render time greatly.

AO_Height: (int [Default 128]) Sets the height of the texture in pixels (Default 128). Increasing this value slows render time greatly.

AO_Samples: (int [Default 3]) Number of rays cast per pixel on a triangle (Default 8) . Increasing this value slows render time.

AO_Blending: (int [Default 0]) "Blurs" the results so that it's less pixellated (Default 0). The number represents the number of blur iterations. 0 means no blur. If you have very low samples, you'll want high (10-20+) blur. You can achieve this effect in an image editor, though the blending here automatically crops it to the uv cluster space.

AO_Padding: (int [Default 3]) Number of pixels that will be padded around each UV cluster (Default 3)

AO_Contrast: (float [Default 0]) Adds contrast so that lights are lighter (Default 0). 0 is no contrast, 0.5 is moderate, 1.0 is high, 1.5 is extreme, etc. Can also be done in an image editor.

AO_RayLength: (float [Default Variable]) Anything past this distance (in Anim8or Units) will not be detected as occluding the light. Useful if you want to have more or less geometry affecting the shadowing. If not set, the ray length is automatically set to 0.15*(diameter of bounding sphere)

AO_BGColor: (point3 [Default 255 255 255]) Background color of the image. Useful if you want to do your own blur or image editing.

AO_RayConeBounds: (float [Default 0.15]) Determines how close to the plane of the triangle a ray can go (example in image below). Clamped between 0 and 0.999


Ray Cone Bounds Effect

To-Do
  • Optimize...where's my octrees?

Sample Images
Not much yet (yeah, it's that slow).







Warning: Best to treat this script as experimental. This script is very slow and practically primeval (hah...ahah...). If you want fast, high resolution AO, turn to something like xNormal. Otherwise tinker as you will :P
« Last Edit: February 28, 2014, 03:17:18 pm by Raxx »
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
AOBake v0.2 Released
« Reply #1 on: February 27, 2014, 04:56:23 pm »

Alright, update posted!

The first release was absolutely horrid. This one is much more accurate and for the most part delivers the expected results.

Changes:
  • Various bugfixes and improvements
  • Added AO_BGColor option
  • Added AO_RayConeBounds option

No speed optimizations yet. I'm trying to eliminate the brute force methods, but getting weird results. Once recursive functions are implemented in ASL, I'll be able to do more with this. Until then, this is likely the last release.

I did discover that for the most part, only 3 samples are sufficient for the task if the texture is 512x512 or higher. You can take the results, toss it in an image editor, add gaussian blur and increase the dark color levels. The images in the first post follow this line.
Logged

CrashDrive

  • Full Member
  • ***
  • Posts: 102
    • View Profile
Re: AOBake
« Reply #2 on: March 14, 2014, 09:41:53 pm »

Tried this out and it's definitely a long wait during render, but it works.   
Amazing you've been able to implement these things with the limited scripting resources available.

I've never tried baking Ambient Occlusion before, so thanks for making me more aware of this.
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: AOBake
« Reply #3 on: March 19, 2014, 04:04:52 pm »

Thanks CrashDrive, glad it helped you out in some way ;) I'm thinking I'll probably rewrite this script later. I already did some performance optimizations (about 30% speed improvement for large meshes) but it still takes too long to be truly useful.
Logged

Trevor

  • Full Member
  • ***
  • Posts: 167
  • Goldfinger64 Dev OS:10.0.17017 Gfx:RX480 Loc:UK
    • View Profile
    • LS Tech Services
Re: AOBake
« Reply #4 on: July 25, 2014, 04:15:48 pm »

wow, I just noticed this and would love to include a suggestion.
Instead of making a texture with AO, can you shade the object?

The environment I model for does not support textures bigger than 64x64x4 (2048 bytes) and so I use small textures with repeating UV's and vertex shading (or in an8, mtl shading) for flat shadows.

If you were to do this may I also add that each mtl crerated will require the following settings (to allow flat shading unless steve adds a special option for it)

LockAmbientDiffuse()
AmbiantFactor = 1.2
Diffusefactor = 0.01  <-- This is rerquired to keep texture otherwise the texture is un-assosiated
SpecularFactor = 0

Texture Mode = Darken.

Trev
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1448
    • View Profile
Re: AOBake
« Reply #5 on: July 25, 2014, 07:41:03 pm »

Hm, hard to visualize what exactly you want. Do you mean that you want unique materials on a per-triangle basis, with darker materials where there are shadows? Do you have an example you can share?
Logged