Lens shader

Discussion about everything. New games, 3d math, development tips...
Post Reply
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Lens shader

Post by JP »

I found a thread on gamedev.net 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 ... _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 ideas on this at all?
Image Image Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

No ideas right now but thanks for the link I was thinking of doing an effect like this sometime.

Addon:

Ok on second look the second code that you posted has a variable Zoom value based on the texcoords and some calculations while your one is fixed. (Unless I got the fact that the second bit of code is not the one you wrote but the GameDev poster's code and you are showing it for comparison wrong.)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Both those bits of code are from the original gamedev post (but with some slight alterations of my own).

I've actually got the code working now and only have one issue left and that's some nasty over distortion in the very centre of the lens but i reckon i'll be able to sort that out.

Unfortunately i can't really share my code with anyone as it's Sony's confidential property now due to being developed at work and for a Sony project but i'm sure i can at least put up a little guide on how i achieved the effect so i'll do that at some point!
Image Image Image
Post Reply