Lens Flareany ideas on how to make this work with tiled render and work better with subframes
edit: fixed subframes?
add these lines to the
#group Post in 3Dkn-1.0.1.frag
uniform bool LensFlare; checkbox[false]
uniform float FlareIntensity; slider[0,0.25,1]
uniform int FlareSamples; slider[1,8,9]
uniform float FlareDispersal; slider[0.0,0.25,1.0]
uniform float FlareHaloWidth; slider[0.0,0.5,1.0]
uniform float FlareDistortion; slider[0.0,1.0,2.0]
add this to BufferShader-1.0.1.frag right before the line
vec4 bloom(vec2 pos, vec2 quality){//see: https://gist.github.com/BlackBulletIV/4218802/*----------------------------------------------------------------------------*/
// modified from...
// http://john-chapman-graphics.blogspot.ca/2013/02/pseudo-lens-flare.html
uniform bool LensFlare;
uniform float FlareIntensity;
uniform int FlareSamples;
uniform float FlareDispersal;
uniform float FlareHaloWidth;
uniform float FlareDistortion;
vec4 textureDistorted(
in sampler2D tex,
in vec2 texcoord,
in vec2 direction,
in vec4 distortion
) {
return vec4(
texture2D(tex, texcoord + direction * distortion.r).r,
texture2D(tex, texcoord + direction * distortion.g).g,
texture2D(tex, texcoord + direction * distortion.b).b,
texture2D(tex, texcoord + direction * distortion.a).a
);
}
vec4 lensflare(vec2 texcoord, vec2 texelSize) {
vec2 ghostVec = (vec2(0.5) - texcoord) * FlareDispersal;
vec2 ghostVecNorm = normalize(ghostVec);
vec2 haloVec = normalize(ghostVec) * FlareHaloWidth;
vec4 distortion = vec4(-texelSize.x * FlareDistortion, 0.0, texelSize.x * FlareDistortion, 0.0);
// sample ghosts:
vec4 result = vec4(0.0);
for (int i = 0; i < FlareSamples; ++i) {
vec2 offset = fract(texcoord + ghostVec * float(i));
float weight = pow(1.0 - (length(vec2(0.5) - offset) / length(vec2(0.5))), 10.0);
result += textureDistorted( frontbuffer,offset,ghostVecNorm,distortion ) * weight;
}
// sample halo:
float weight = pow(1.0 - (length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5))), 10.0);
result += textureDistorted( frontbuffer, fract(texcoord + haloVec), ghostVecNorm, distortion ) * weight;
return result;
}
/*----------------------------------------------------------------------------*/
and in the main() routine add this somewhere, right after the test and call to bloom seems to work
if(LensFlare) {
vec4 lf=lensflare(pos,pixelsiz);
lf=lf/lf.w;
c += FlareIntensity*lf.xyz;
}
and you get this...
edit: John Chapman informed me that this use of his code is fine
(yes I actually asked him)