Racer Shaders?

Hello.

I would like to have a list of Racer shaders for example HDR, DOF ect. ect.

It would also help people who want to make Racer videos/movies
 
HDR is already active as a shader in the current default Racer release.

The only way to change how things appear properly is to choose a different tone mapper from hdr.cg file, and then turn it on in your full-screen shader.

The motion blur shader unfortunately does not work well for screenshots because you can't pause Racer elegantly and get nice motion blur. So ideally you might want to capture those kinds of stills during actual play and see how it pans out, or capture from a movie still!

The DOF shader, hmmm, I can't seem to see it now. Not sure on that.



Basically, the visual result is dictated ideally in the fs_filter shader entry in racer.ini.

Those shaders then access other shaders which control things like the HDR tone mapping, or depth of field or other such effects. Sometimes some effects are done in the actual fs_filter file though.


Dig around and have a play would be my advice.


DOF certainly was in there though, but I've no idea where it was or where it's gone.

Iirc Camsinny had it working pretty well at one point with lovely soft bokeh and everything.


Ideally some of these effects should be able to be set per camera so different cameras can use different effects... even if just in a replay scenario.

Worst case we can just have a batch file swap things around so you load up specifically with the camera you want to use to take a photo with :D


Cheers

Dave
 
I think as something that wasn't put into the Racer distribution it fell by the wayside a couple versions ago.

renderer.depth_of_field=1 gets a depth map rendered,
renderer.motion_blur.velocity_map=0 should also be done on recent versions to save on performance (since the shader doesn't also do motion blur atm)
renderer.motion_blur.fs_filter1=bloom_shadows_dof_f.cg is the final ingredient, picking a fullscreen shader with the appropriate function.
(it's this kind of multiple-inputs to get 1 feature thing that I'm hoping to straighten out a bit with my config program)


Color grading seems broken again so I've commented it out.
bloom_shadows_dof_f.cg or similar.
Code:
// CSM Shadowmapping + Bloom + Colorgrade
// HDR version

#include "../common/constants.cg"
#include "../common/hdr.cg"
#include "../common/utils.cg"
#include "bloom.cg"
#include "common_fs.cg"

struct VertOut
{
  float4 pos : POSITION;
  float4 col : COLOR0;
  float2 tc0 : TEXCOORD0;
};

struct FragOut
{
  float4 col : COLOR;
};



float BlurTexture(sampler2D tex, float2 vin, float blur, sampler2D depthMap)
// With Z sampling
{
  return tex2D(tex,vin).a;

}


float ComputeDepthBlur (float depth, float k)
{
    float4 vDofVars = float4(0,0,1,1);
    // k is the target depth
    float f;
    depth = 1f/(1-depth)-1f;
    depth = 1/depth;
    // note that k is 1/target
    k = 1f/(1f/(1-k)-1f);
    // approximating a thin lens system here.
    // assuming an ideal image plane at v0
    float v0 = 1.0;
    // first, calculate the focal length of the lens
    // or rather, the inverse of it
    float foc = k + 1/v0;
    // now we can calculate the actual imaging plane for our depth
    float vx = foc - depth;
    // one more constant comes into play
    float d = 100.0; // d is aperture width.
    f = d*abs(1/foc * (v0-1/foc))*abs(1-v0*vx);
    // and as before vx is actually 1/length, to avoid doing a bunch of inverses.
    /*if (depth < k)
        {
            f = (depth-k)/(0.7-0.9);;//(depth - vDofVars.y)/(vDofVars.y - vDofVars.x);
        } else
        {
            //scale to 0...1
            f = (k-depth)/(0.7-0.9);//(depth - vDofVars.y)/(vDofVars.z - vDofVars.y);

            //clamp far to max blur
        }*/
    //f = abs((depth-k)/depth)*0.8;
    f = clamp (f, 0, max(2.0f,20f*depth));
    return f;// * 0.5f + 0.5f;
}



float4 DOFFilter (float2 tc0, sampler2D sceneMap, float depthVar)
{

    float2 pixelSizeLow = float2(0.0007, 0.0013);
    float2 pixelSizeHigh = float2(0.0005, 0.0009);

    float2 vMaxCoC = float2(0.0, 25.0);

    float4 cOut;
    float discRad;
    float discRadLow;
    float centerDepth;

    float lowScale = 1.84;

    cOut = tex2D(sceneMap, tc0);
    //float4 cDepth = tex2D(depthMap, tc0);

    //depthVar = 0;

    cOut.a = depthVar;//cDepth.a;
    centerDepth=cOut.a;

    //convert depth into blur radius
    discRad = abs(cOut.a);
    //discRad = abs(cOut.a*vMaxCoC.y - vMaxCoC.x);
    discRadLow = discRad * lowScale;
    cOut=0;

    for(int t=0; t<16; t++)
        {
            //compute tap coords
            float2 coordLow = tc0 + (pixelSizeLow * poissonDisk[t] * discRadLow);
            float2 coordHigh = tc0 + (pixelSizeHigh * poissonDisk[t] * discRad);

            //fetch high res tap
            float4 tapLow = tex2D (sceneMap, coordLow);
            float4 tapHigh = tex2D (sceneMap, coordHigh);

            //mix high and low taps
            float tapBlur = abs(tapHigh.a * 2.0 - 1.0); //put blur into 0...1
            float4 tap = lerp(tapHigh, tapLow, tapBlur);

            //SMARTblur
            tap.a = (tap.a >= centerDepth) ? 1.0 : abs(tap.a * 2.0 - 1.0);

            cOut.rgb += tap.rgb * tap.a;
            cOut.a += tap.a;
        }
    return (cOut / cOut.a);
}



FragOut main(
  VertOut vin,
  uniform sampler2D sceneMap    : TEXUNIT0,
  uniform sampler2D velocityMap : TEXUNIT1,
  /// Z in TEXUNIT5
  uniform sampler2D bloomMap1  : TEXUNIT2,
  uniform sampler2D bloomMap2  : TEXUNIT3,
  uniform sampler2D bloomMap3  : TEXUNIT4,
#ifdef CSM_MRT
  uniform sampler2D depthMap    : TEXUNIT5,
  uniform sampler2D shadowMap  : TEXUNIT6,
  uniform sampler3D gradeMap    : TEXUNIT7,
#else
  uniform sampler3D gradeMap    : TEXUNIT5,  // 3D texture for color grading
  uniform sampler2D depthMap    : TEXUNIT6,
#endif
  uniform float alpha,              // Amount of blur
  uniform float exposure
)
{
  FragOut fout;

  float4 ambientColor,
        sdColor;                // Specular+diffuse
  float4 color;

#ifdef CSM_MRT
  // Original color
  ambientColor=tex2D(sceneMap,vin.tc0);
  sdColor=tex2D(shadowMap,vin.tc0);

  float shadowAmount=BlurTexture(shadowMap, vin.tc0,smBlurAmount,depthMap);
  color=ambientColor+shadowAmount*sdColor;
#else
  // Single render-target (RT)
  color=tex2D(sceneMap,vin.tc0);
#endif

  float4 depthColor=tex2D(depthMap,vin.tc0);
  float4 bloomColor=BloomCombineMaps3(bloomMap1,bloomMap2,bloomMap3,vin.tc0);
  color=BloomMix(color,bloomColor);

// Show the 3 bloom stages and the end-result in 1 view
/*if(vin.tc0.y>0.5)
{
if(vin.tc0.x>0.666)color=tex2D(bloomMap3,vin.tc0);
else if(vin.tc0.x>0.333)color=tex2D(bloomMap2,vin.tc0);
else color=tex2D(bloomMap1,vin.tc0);
}*/

    float depthV = ComputeDepthBlur(depthColor,tex2D(depthMap,float2(0.5f,0.5f)));
    //float depthV = ComputeDepthBlur(depthColor,0.91f);

    float4 DOFtest = DOFFilter(vin.tc0, sceneMap, depthV);

  // HDR -> LDR tonemap
  //color.rgb=ToneMapHDR(color,exposure);
  DOFtest.rgb=ToneMapHDR(DOFtest,exposure);

  // Color grading
  //color.rgb=ColorGrade(color.rgb,gradeMap);
  //DOFtest.rgb = ColorGrade(DOFtest.rgb,gradeMap);


  //fout.col.rgb=color;
  // Motion blur blend
  //fout.col.a=alpha;
  fout.col.rgb = DOFtest.rgb;
  //fout.col.rgb = depthV;
  fout.col.a = alpha;
  //fout.col.rgb=depthColor;
  //fout.col.rgb=10f*(depthColor-0.9);
  return fout;
}


The main reason I'd call it a low priority to bother including is that the effect is subtle at anything like a normal driving camera, and to make it work perfectly, the camera's FOV would need to be available in the fs shader (when it's not, changing FOV causes strange effects to distance calculations). You'll only notice it on extremes, like a picture of the car from 30cm away. If I understand the cameras business correctly, it is primarily dependent on the distance to the focal plane - the farther that is, the less DOF there will be on objects a set distance from the plane. So if it's focused on a wall, and the car's nearby, the car won't blur much. If it's focused on the windscreen and the tail lights are closer, that can blur the lights a bit.
gSXqv.jpg


Exaggerating the effect is a pretty trivial tweak - d = 100.0 in the above script gives the aperture width, which I believe would not be physical units, but a change to it will give that 'scale model of a car' effect:
5wJoD.jpg

(this is with d=10,000, which makes the focal plane ridiculously narrow)

Anyone remember that track that was based on a 1:60 slot car track, in a giant room? Maybe that would be a good use for this shader...
 

Latest News

Shifting method

  • I use whatever the car has in real life*

  • I always use paddleshift

  • I always use sequential

  • I always use H-shifter

  • Something else, please explain


Results are only viewable after voting.
Back
Top