Ticket #2111: fix-hqdof-error.patch
File fix-hqdof-error.patch, 5.1 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/shaders/effects/postproc/HQDOF.xml
5 5 <pass shader="glsl/hqdof"> 6 6 <define name="manualdof" value="true"/> 7 7 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"/> 10 11 11 12 <define name="samples" value="3"/> 12 13 <define name="rings" value="3"/> … … 16 17 <define name="fdofstart" value="30.0"/> 17 18 <define name="fdofdist" value="40.0"/> 18 19 19 <define name="maxblur" value="2 "/>20 <define name="maxblur" value="2.0"/> 20 21 21 22 <define name="threshold" value="0.9"/> 22 23 <define name="gain" value="2.0"/> -
binaries/data/mods/public/shaders/glsl/hqdof.fs
66 66 uniform float focalDepth; //focal distance value in meters, but you may use autofocus option below 67 67 //uniform float focalLength = 1000; //focal length in mm 68 68 //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) 70 70 71 71 /* 72 72 make sure that these two values are the same for your camera, otherwise distances will be wrong. … … 119 119 float bdepth(vec2 coords, float blursize) //blurring depth 120 120 { 121 121 float d = 0.0; 122 float div = 0 ;122 float div = 0.0; 123 123 float kernel[9]; 124 124 vec2 offset[9]; 125 125 … … 218 218 float b = (a-fdofstart)/fdofdist; //far DoF 219 219 float c = (-a-ndofstart)/ndofdist; //near Dof 220 220 blur = (a>0.0)?b:c; 221 blur /= max((fDepth / 15 ) - 7, 1);221 blur /= max((fDepth / 15.0) - 7.0, 1.0); 222 222 } 223 223 else 224 224 { … … 233 233 blur = abs(a-b)*c; 234 234 } 235 235 236 return clamp(blur, 0 , 1);236 return clamp(blur, 0.0, 1.0); 237 237 } 238 238 239 239 varying vec2 v_tex; … … 279 279 float h2 = texel.y*maxblur+noise.y; 280 280 281 281 // calculation of final color 282 vec3 color = texture2D(renderedTex, v_tex).rgb; 283 vec3 samplecolor = color; 282 vec3 samplecolor = texture2D(renderedTex, v_tex).rgb; 284 283 float samplediv = 1.0; 285 284 286 285 int ringsamples; … … 288 287 for (int i = 1; i <= rings; i += 1) 289 288 { 290 289 ringsamples = i * samples; 291 float step = PI*2.0 / ringsamples;290 float step = PI*2.0 / float(ringsamples); 292 291 293 292 for (int j = 0; j < ringsamples; j += 1) 294 293 { 295 294 // 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)); 298 297 299 298 vec2 samplecoord = v_tex + vec2(pw*w,ph*h); 300 299 301 300 // 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); 304 303 305 304 // begin performance-unfriendly (but nice-looking) removal of fully-focused foreground samples 306 305 if (foregroundcleanup) 307 306 { 308 307 float sampledepth = linearize(texture2D(depthTex, samplecoord).x); 309 int depthweight = (sampledepth > depth) ? 1 :0;308 float depthweight = (sampledepth > depth) ? 1.0 : 0.0; 310 309 float sampleblur = bluramount(sampledepth, fDepth); 311 310 312 float weight = clamp(depthweight + sampleblur, 0 , 1);311 float weight = clamp(depthweight + sampleblur, 0.0, 1.0); 313 312 samplecoloradd *= weight; 314 313 sampledivadd *= weight; 315 314 } … … 323 322 #ifdef BLURONSHARPCHECK 324 323 for (int k = j; k < ringsamples * 2; k += 1) 325 324 { 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)); 328 327 329 328 vec2 samplecoord = v_tex + vec2(pw*w2,ph*h2); 330 329 331 330 float sampledepth = linearize(texture2D(depthTex, samplecoord).x); 332 int depthweight = (sampledepth > depth) ? 0 : 1;331 float depthweight = (sampledepth > depth) ? 0.0 : 1.0; 333 332 float sampleblur = bluramount(sampledepth, fDepth); 334 333 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); 337 336 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; 339 338 coladd *= weight; 340 339 sadd *= weight; 341 340