Creating falloff

I have a refraction shader which so far works OK, but i’m still missing something. I want to add some falloff to it. Take a look at the following image to see what i mean:

This first image is how i have it right now. The 2nd and the 3rd is what i want to have.

Basically i want to be able to switch between the 2nd and the 3rd image. Something like, clamping the value between -1 and 1. If it’s larger than 0, the falloff comes from the inside out. And its smaller than 0, then it’s the other way around.

But i’m not sure how to create such a falloff. Can anyone help me out…??

This is what i have so far in my fragment shader (just the refraction)

void main (void)
    vec2 index;   

   // calc refraction
   vec3 refractionDir = normalize(EyeDir) - normalize(Normal);

   // Scale the refraction so the z element is equal to depth
   float depthVal = Depth / -refractionDir.z;
   // perform the div by w
   float recipW = 1.0 / EyePos.w;
   vec2 eye = EyePos.xy * vec2(recipW);

   // calc the refraction lookup
   index.s = (eye.x + refractionDir.x * depthVal);
   index.t = (eye.y + refractionDir.y * depthVal);
   // scale and shift so we're in the range 0-1
   index.s = index.s / 2.0 + 0.5;
   index.t = index.t / 2.0 + 0.5;
   // as we're looking at the framebuffer, we want it clamping at the edge of the rendered scene, not the edge of the texture,
   // so we clamp before scaling to fit
   float recip1k = 1.0 / 2048.0;
   index.s = clamp(index.s, 0.0, 1.0 - recip1k);
   index.t = clamp(index.t, 0.0, 1.0 - recip1k);
   // scale the texture so we just see the rendered framebuffer
   index.s = index.s * FrameWidth * recip1k;
   index.t = index.t * FrameHeight * recip1k;
    vec3 RefractionColor = vec3 (texture2D(RefractionMap, index));

    gl_FragColor = vec4 (RefractionColor, 1.0);

Hopefully someone can help me out.

Sounds like you’ve already got a way to generate the attenuation factors for each. Generate both, and just lerp between them:

mix( atten1, atten2, blend_factor )

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.