• Advertisement
Sign in to follow this  

Lens bulge shader

This topic is 3767 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi folks, I found a thread on here talking about a lens shader to create a bulge on the screen as if it's been distorted by a lens: http://www.gamedev.net/community/forums/topic.asp?topic_id=384166 In that thread there's two examples shown on how to create the effect but i can't get either to work properly and it's really doing my head in! With the technique that uses the offset 'normal map' when i put in a zoom value of 0 i get the original un-bulged image as you'd expect but any other value just results in a black screen... (i've tried 1.0 all the way down to 0.0000000000000001). I did change the code slightly though to get the image showing at all with a 0 zoom:
float zoom = 1.0;
   float3 normal = (tex2D(gOffsetTex, texCoord).rgb/256.0);// ranges from 0 to 1
   frag_colour = tex2D(gBulgeTexScene, texCoord + (normal.xy*normal.z*zoom) );
   frag_colour.a = 1.0;
For the original technique mentioned by the thread's poster i get the image swirled up really badly or with the centre blank depending on the strength i use, again the code differs slightly:
float strength = 0.5;
  float ZoomValue = strength-sqrt( ((texCoord.x-0.5)*(texCoord.x-0.5)) + ((texCoord.y-0.5)*(texCoord.y-0.5)) );
  float2 origin = float2(0.5,0.5);
  texCoord.x = texCoord.x * ZoomValue + origin.x;
  texCoord.y = texCoord.y * ZoomValue + origin.y;
  frag_colour = tex2D(gBulgeTexScene, texCoord);
Has anyone got any advice on this at all?

Share this post


Link to post
Share on other sites
Advertisement
You're expanding the normal incorrectly. tex2D gives you values in the [0,1] range, unless the texture is a floating point format (which I doubt this is!). Using the value as-is should be okay. If you want to convert it into the [-1, 1] range, multiply by two and subtract one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement