Ticket #2111: fix-hqdof-error.patch

File fix-hqdof-error.patch, 5.1 KB (added by historic_bruno, 10 years ago)
  • binaries/data/mods/public/shaders/effects/postproc/HQDOF.xml

     
    55        <pass shader="glsl/hqdof">
    66            <define name="manualdof" value="true"/>
    77
    8             <define name="focalLength" value="1000"/>
    9             <define name="fstop" value="200"/>
     8            <define name="focalLength" value="1000.0"/>
     9            <define name="fstop" value="200.0"/>
     10            <define name="showFocus" value="false"/>
    1011
    1112            <define name="samples" value="3"/>
    1213            <define name="rings" value="3"/>
     
    1617            <define name="fdofstart" value="30.0"/>
    1718            <define name="fdofdist" value="40.0"/>
    1819
    19             <define name="maxblur" value="2"/>
     20            <define name="maxblur" value="2.0"/>
    2021
    2122            <define name="threshold" value="0.9"/>
    2223            <define name="gain" value="2.0"/>
  • binaries/data/mods/public/shaders/glsl/hqdof.fs

     
    6666uniform float focalDepth;  //focal distance value in meters, but you may use autofocus option below
    6767//uniform float focalLength = 1000; //focal length in mm
    6868//uniform float fstop = 200; //f-stop value
    69 uniform bool showFocus = false; //show debug focus point and focal range (red = focal point, green = focal range)
     69//uniform bool showFocus = false; //show debug focus point and focal range (red = focal point, green = focal range)
    7070
    7171/*
    7272make sure that these two values are the same for your camera, otherwise distances will be wrong.
     
    119119float bdepth(vec2 coords, float blursize) //blurring depth
    120120{
    121121    float d = 0.0;
    122     float div = 0;
     122    float div = 0.0;
    123123    float kernel[9];
    124124    vec2 offset[9];
    125125
     
    218218        float b = (a-fdofstart)/fdofdist; //far DoF
    219219        float c = (-a-ndofstart)/ndofdist; //near Dof
    220220        blur = (a>0.0)?b:c;
    221         blur /= max((fDepth / 15) - 7, 1);
     221        blur /= max((fDepth / 15.0) - 7.0, 1.0);
    222222    }
    223223    else
    224224    {
     
    233233        blur = abs(a-b)*c;
    234234    }
    235235
    236     return clamp(blur, 0, 1);
     236    return clamp(blur, 0.0, 1.0);
    237237}
    238238
    239239varying vec2 v_tex;
     
    279279    float h2 = texel.y*maxblur+noise.y;
    280280
    281281    // calculation of final color
    282     vec3 color = texture2D(renderedTex, v_tex).rgb;
    283     vec3 samplecolor = color;
     282    vec3 samplecolor = texture2D(renderedTex, v_tex).rgb;
    284283    float samplediv = 1.0;
    285284
    286285    int ringsamples;
     
    288287    for (int i = 1; i <= rings; i += 1)
    289288    {
    290289        ringsamples = i * samples;
    291         float step = PI*2.0 / ringsamples;
     290        float step = PI*2.0 / float(ringsamples);
    292291
    293292        for (int j = 0; j < ringsamples; j += 1)
    294293        {
    295294            // find sample coordinates
    296             float pw = (cos(j*step)*i);
    297             float ph = (sin(j*step)*i);
     295            float pw = (cos(float(j)*step)*float(i));
     296            float ph = (sin(float(j)*step)*float(i));
    298297
    299298            vec2 samplecoord = v_tex + vec2(pw*w,ph*h);
    300299
    301300            // set this sample's color and count
    302             vec3 samplecoloradd = color(samplecoord,blur)*mix(1.0,i/rings,bias);
    303             float sampledivadd = mix(1.0,i/rings,bias);
     301            vec3 samplecoloradd = color(samplecoord,blur)*mix(1.0,float(i)/float(rings),bias);
     302            float sampledivadd = mix(1.0,float(i)/float(rings),bias);
    304303
    305304            // begin performance-unfriendly (but nice-looking) removal of fully-focused foreground samples
    306305            if (foregroundcleanup)
    307306            {
    308307                float sampledepth = linearize(texture2D(depthTex, samplecoord).x);
    309                 int depthweight = (sampledepth > depth) ? 1 : 0;
     308                float depthweight = (sampledepth > depth) ? 1.0 : 0.0;
    310309                float sampleblur = bluramount(sampledepth, fDepth);
    311310
    312                 float weight = clamp(depthweight + sampleblur, 0, 1);
     311                float weight = clamp(depthweight + sampleblur, 0.0, 1.0);
    313312                samplecoloradd *= weight;
    314313                sampledivadd *= weight;
    315314            }
     
    323322        #ifdef BLURONSHARPCHECK
    324323        for (int k = j; k < ringsamples * 2; k += 1)
    325324        {
    326             float pw = (cos(k*step)*i);
    327             float ph = (sin(k*step)*i);
     325            float pw = (cos(float(k)*step)*float(i));
     326            float ph = (sin(float(k)*step)*float(i));
    328327
    329328            vec2 samplecoord = v_tex + vec2(pw*w2,ph*h2);
    330329
    331330            float sampledepth = linearize(texture2D(depthTex, samplecoord).x);
    332             int depthweight = (sampledepth > depth) ? 0 : 1;
     331            float depthweight = (sampledepth > depth) ? 0.0 : 1.0;
    333332            float sampleblur = bluramount(sampledepth, fDepth);
    334333
    335             vec3 coladd = color(samplecoord,sampleblur)*mix(1.0,i/rings,bias);
    336             float sadd = mix(1.0,i/rings,bias);
     334            vec3 coladd = color(samplecoord,sampleblur)*mix(1.0,float(i)/float(rings),bias);
     335            float sadd = mix(1.0,float(i)/float(rings),bias);
    337336
    338             float weight = (sampleblur > blur) ? clamp(depthweight * (0.2 - blur) * (float(k) / ringsamples / 2) * sampleblur, 0, 1) : 0.0;
     337            float weight = (sampleblur > blur) ? clamp(depthweight * (0.2 - blur) * (float(k) / float(ringsamples) / 2.0) * sampleblur, 0.0, 1.0) : 0.0;
    339338            coladd *= weight;
    340339            sadd *= weight;
    341340