Ambient occlusion, is it possible?

Hmmm, doesn't seem to work here :(

Should be named ssoa.cg in the fs_filter because the files are named oa not ao


Can't seem to make it work, but it's killing fps by about 95% :D

Dave
 
you need to play with some constants

be sure to adjust the random value and the "f" value.

anyway, i got it working here, so it's just a matter of finding the right values.
it runs fine on my laptop. but i will look into how to increase performance.

Consider this shader as a proof of concept
 
If an emissive map could be generated and passed like the depth map, it seems like this could be adapted to do some more general ambient lighting as well - might take some tweaking but it seems like it could be used to find lights in the same way it finds objects that cast shadows. Not as good as a full global illumination but potentially better than vertex lighting and baked lighting textures (I think some1's Supra uses these for the brake lights to cast light on the rear bumper).
 
The "random map" seems to have a lot of impact on quality, i implemented one and almost cried when i saw the end result. More soon !

edit: a normal map, emmisive map, ... and eventually we got deferred shading. i'm gonna discuss the possibilities with Ruud :)
 
  • Tiberius

Mitch, looks great. I tried myself and got it to do *something* but it definitely wasn't AO. I think the approach I was trying was more for shadow maps, basically just a map for anything which was in shadow, no gradients.

I'll try it when I'm awake, looks great from the screenshot :)
 
It's still not working for me...Mitch, could you post your settings that are working atm? Anything need to be checked/unchecked in the racer.ini?

Mine:
Code:
float g_RadiusMultiplier  = 1.0f;
float g_AngleBias         = 0.52f;
int   g_NumDir		      = 16;
int   g_NumSteps		  = 8;
float g_Contrast          = 25.0f;
float g_Attenuation       = 1000.0f;
int   g_QualityMode       = 1;
float2 g_Resolution 	  = float2(1024.0f,768.0f);
float2 g_InvResolution	  = float2(1.0/1024.0f,1.0/768.0f);
float g_R 				  = 1.0f;
float g_inv_R 			  = 1.0f;
float g_sqr_R 			  = 1.0f;
const float2 g_FocalLen   = float2( 1.0f / 0.849426f, 1.0f / 0.63707f);
float2 g_InvFocalLen 	  = float2(0.849426f, 0.63707f);
Code:
float f = 1500.0f;

And my renderer section of racer.ini:
Code:
renderer
{
  ; Gfx engine rendering options
  ; Desired framerate - will reduce detail dynamically to obtain the framerate (0 to disable)
  desired_fps=0
  ; Throttler detail limits (0=nothing drawn, 1=full detail, >1=increased visibility range)
  min_detail=1.0
  max_detail=1.0
  paint
  {
    ; Show wire frame?
    wireframe=0
    ; Show vertex normals?
    normals=0
    ; Show triangles? (default=1)
    triangles=1
  }
  ; Note that some fog parameters are defined in <track>/special.ini
  ; Enable fog? (shaders can still turn fog off)
  fog=1
  ; Use stencil shadowing? Costs a lot of performance and the track must support it, but can look nice.
  stencil_shadows=0
  {
    ; Use simple darkening (just 2 passes needed plus 1 dark fullscreen quad)?
    ; If 0, full lighting is done at more cost.
    ; Simple darkening does not require explicit 'Receive shadow' flags
    ; in the track objects; all objects are shadowed.
    simple=1
  }
  ; Use array elements instead of 1 drawelements?
  use_array_elements=0
  ; Use single pass rendering instead of multitexturing? Don't set at 1 if you use Cg shaders
  single_pass=0
  ; Support Vertex Buffer Objects? (for cars and/or tracks)
  use_vbo=1
  ; Support projected lights? (default=1)
  projected_lights=1
  hdr
  {
    ; HDR rendering (high-dynamic range)
    enable=1
  }
  bloom
  {
    ; Bloom on top of HDR - needs hdr.enable=1
    enable=1
  }
  auto_exposure
  {
    ; If enabled, calculates luminance of the scene and automatically adjusts the 'exposure'
    ; It then overrules any exposure setting from track special.ini files or the script 'exposure' command
    enable=0
    ; Decrease the amount of luminance calculations to improve framerate
    steps=20
    ; Linear response; exposure=offset-sceneLuminance*gradient
    offset=1.4
    gradient=0.7
    ; Minimal exposure
    min=0.4
    max=100.0
    ; Gradually change exposure with a Kalman filter
    filter_gain=0.05
  }
  motion_blur
  {
    ; Method: 0=disabled, 1=OpenGL accumulation buffers, 2=blur-texture, 3=bitmap (not functional), 4=FBO (fast texture based)
    ; Preferred is FBO (the future is going to do more & more with FBO's due to Cg shaders)
    method=4
    ; Direct setting of FBO size (if 0, the window size is used)
    fbo_width=0
    fbo_height=0
    ; (Method 1 only) Motion blur using accumulation buffers; 0=don't use, >1=number of passes (renders); can be slow!
    passes=4
    ; (Method 1 only) Mix scale; <1=darken, >1=brighten (sort of HDR)
    accum_factor=1.0
    ; (Method 2 & 4) Amount of blur; 0=nothing, 1=full.
    blur_alpha=0.5
    ; (Method 4 only)
    ;fs_filter1=ssao.cg
    fs_filter1=ssao.cg
    ; (Method 4 only) Number of samples for multisampled FBO (0=no multi-sampling, >1=samples); only works on nVidia cards 8xxx series and up
    samples=4
    ; Generate velocity map? (for use in fullscreen shader) Creates velocity values in R & G channels using motion_blur_v/f.cg shaders.
    velocity_map=1
    ; Distortion for projectors
    distorter
    {
      ; Enable distortion? (also set motion_blur.fs_filter1 to bloom_distort_edge_lr_f.cg for example if enabled)
      enable=0
      ; Enter edit mode at startup?
      auto_edit=0
      ; Enable a test pattern at start 
      init_testpattern=2
      ; Transparency of control points
      points_alpha=1.0
      ; Texture size (must be a power of 2)
      texture_size=1024
      ; Control points defining a net to fit the screen in. The points are normalized
      ; (so 1 means the right or lower side of the screen, 0,0 is the origin at the top-left)
      ; Number order is row-column, so control_point_10 means row 1, col 0.
      control_point_00=0.000000 0.000000
      control_point_01=0.250000 0.028320
      control_point_02=0.500977 0.066406
      control_point_03=0.750000 0.026367
      control_point_04=1.000000 0.000000
      control_point_10=0.009766 0.250000
      control_point_11=0.250000 0.250000
      control_point_12=0.500000 0.250000
      control_point_13=0.750000 0.250000
      control_point_14=0.987305 0.250000
      control_point_20=0.024414 0.500000
      control_point_21=0.250000 0.500000
      control_point_22=0.515625 0.483398
      control_point_23=0.750000 0.500000
      control_point_24=0.977539 0.500000
      control_point_30=0.000000 0.750000
      control_point_31=0.250000 0.750000
      control_point_32=0.500000 0.750000
      control_point_33=0.750000 0.750000
      control_point_34=0.985352 0.750000
      control_point_40=0.000000 1.000000
      control_point_41=0.250000 1.000000
      control_point_42=0.500000 0.971680
      control_point_43=0.750000 0.989258
      control_point_44=1.000000 1.000000
    }
  }
  ; Enable depth of field rendering? (experimental); needs motion_blur_passes>=2
  depth_of_field=0
  ; Force ATI card? A number of measurements may be taken, since ATI drivers have some problems.
  ; Note that v0.5.3 beta 8+ already automatically tries to detect ATI cards and overrules this value
  ; if an ATI card is indeed found (will force it to 1).
  ati=0
  ; Fader PID proportional setting; 0.002 is ok, 1 means superfast fades
  fgr_pid_p=0.002
  edge_blend
  {
    ; Software edge blending
    ; From v0.8.5, this needs to be done in Cg shaders, not a texture onscreen!
    ; Still, even with Cg, the p and gamma values are used.
    enable=0
    ; Curvature of edge fall-off (1=linear, 2=curvy, 3=more curved)
    p=2.000000
    ; Gamma of projector (around 1.8..2.2, 1.0=linear)
    gamma=1.93
    ; Size of edge ramp in pixels
    width=256
    ; Side (1=left, 2=right, 1+2=left&right)
    sides=0
    ; Testing the setup; draw a test image? (see also the script commands 'edgetest on' and 'edgetest off')
    test_pattern=0
    ; Transparency of test pattern (defaults to 128)
    test_pattern_alpha=128
  }
  gpu_shaders=1
}

and yes, I renamed the files, they're loading correctly...but when i try to view just the AO on it's own I just get a black screen.

Also, isn't it HBAO not SSAO? ;)
 
Code:
float g_RadiusMultiplier  = 1.0f;
float g_AngleBias         = 0.52;
int   g_NumDir                = 16;
int   g_NumSteps              = 8;
float g_Contrast          = 1.0f;
float g_Attenuation       = 1.0f;
int   g_QualityMode       = 1;
float2 g_Resolution = float2(1024.0f,786.0f);
float2 g_InvResolution=float2(1.0/1024.0,1.0/786.0);
float g_R = 1.0f;
float g_inv_R=1.0f/1.0f;
float g_sqr_R=1.0f;
const float2 g_FocalLen = float2( 1.0f / 0.849426, 1.0f / 0.63707f);
float2 g_InvFocalLen= float2(0.849426, 0.63707f );
it might help you if i told you that my resolution is 1024/768

Code:
float f=100.0f; // set fx.visibility to 100 in racer.ini
set the random value to 1.0f/1024.0f
you're gonna see some terrible ghosting when it works, but the random map should take care of that in the future.


it's very subtile with these settings.
After that you can raise R to these values to make it more noticable (gives it more spread)

Code:
float g_R = 9.0f;
float g_inv_R=1.0f/9.0f;
float g_sqr_R=3.0f;
yes, its HBAO and also SSAO, so maybe we can call it SSHBAO ... :)

this is how the AO map looks at this moment ... still ghosting

 
Is the screenie you posted with the (ferrari?) the raw ao...as in you uncommented line 78 in ssao.cg and commented out 83?

I just get pure (at least looks it) black with those settings. Even when bumping up the radius.

My GPU is an nVIDIA 250GTS so I doubt the GPU is insufficient...any ideas?
 
here is my current cg file

http://rapidshare.com/files/353741446/ssoa_final2.rar


GPU should only influence FPS. No new special extensions are used.

Might be that the Depth map is not available in the current released version of Racer, you can check that by putting these lines at the very beginning (in main obviously) of the AO file:

Code:
    color.rgb=tex2D(depthMap, IN.texUV);
    color.a=1.0f;
    return;

you should see the depth map (run into something to see some geometry).
 
  • Tiberius

Mitch, is there any chance you could upload somewhere else? Rapidshare just doesn't load here at all for some reason :(

The version I got from Whippy's site isn't working here either but my framerate goes from 100 to 20, so something is working even if I can't see it :)


EDIT: Thanks Dave :rolleyes:

EDIT2: Hmm, this time I get a white screen. I'm on a 9800GTX+ 1GB, I don't think there should be any problems with extensions even though it's an older card?
 
Might be that the Depth map is not available in the current released version of Racer, you can check that by putting these lines at the very beginning (in main obviously) of the AO file:

Code:
    color.rgb=tex2D(depthMap, IN.texUV);
    color.a=1.0f;
    return;
you should see the depth map (run into something to see some geometry).

if it doesn't work, you all will have to wait until the next release.
Posting a copy/paste shader is one thing, but obviously, i can't post the current WIP exe ...
 
Well everything is white now with the new stuff. Mirror is still rendering in colour though.


Can't wait to get this working and then optimise it for speed. The effect need only be subtle but it adds so much especially on detailed tracks :D

Dave
 
  • Tiberius

Might be that the Depth map is not available in the current released version of Racer, you can check that by putting these lines at the very beginning (in main obviously) of the AO file:

Code:
    color.rgb=tex2D(depthMap, IN.texUV);
    color.a=1.0f;
    return;
you should see the depth map (run into something to see some geometry).

Hmm, I'm getting only a black screen now, looks like there's no depth map then. Grrr :tongue: :rolleyes:
 

Latest News

Are you buying car setups?

  • Yes

  • No


Results are only viewable after voting.
Back
Top