The Game Creators
The Game Creators Home Click to Login
  Hot: April NewsletterAGK V108.2xAGK V2 Alpha 3AGK Google Nexus 10 Competition
The Game Creators
Code Snippets / [DBP] Fisheye Shader Demonstration

Go to the first page of this board Return to the Forum Menu Post Message
7 Messages - Page   of 1   
Bookmark and Share Search the Forum

Author Message
Dr Tank

User


Joined: Wed Apr 1st 2009
Location: Southampton, UK
Posted: 20th May 2010 04:02           | link | toggle



This is a demonstration of fisheye cameras using a dynamic cube mapping shader. Shader has many techniques for different fisheye variations: Stereographic, Area Preserving, Linear Angle, Cylindrical. Most have an exact and faster approximate version using series expansions instead of slow functions (sin, cos, sqrt) in pixel shader. Standard flat camera is also implemented for comparison.

Attached is project folder with .dba and .fx files in a .rar. Download is 7.19kB. I append the code for reference purposes. I have tried to clearly lay out and comment the code, but if you have questions, please ask.

.DBA code:
+ Code Snippet

.FX (FX/final.fx) code:
+ Code Snippet
Back to top
Download: fisheye shader demo.rar Size: 7366 bytesReport this message as abusive
Green Gandalf

Valued Member


Joined: Mon Jan 3rd 2005
Location: Cornwall UK
Posted: 20th May 2010 11:55           | link | toggle

Very nice demo.

Two comments:

1. I had to change rgba to rgbaAM (or anything really) as rgba is one of IanM's Matrix1 functions (which I have) which probably does the same thing.

2. I didn't understand your comment "don't think can send 2vectors to shader," in the dba file. You can only pass vector4's to shaders using DBPro but you can declare them as float2's in the shader, the extra components get ignored. If you want to play safe by making the types match then declare them as float4's in the shader as well but use swizzling to pick out the components you want, e.g.

+ Code Snippet

You could also pack two float2's into a single float4 and use swizzling to pick out the ones you want.

You can swizzle constants as well. For example if you want the vector {1.0, 1.0, 1.0, 1.0} you can write it as 1.0.xxxx in calculations, i.e. 4 copies of the first (and only) component of the constant 1.0.

PS2 and above support arbitrary swizzling, earlier PS1 versions have irritating limitations hidden away in the small print. But you're using SM2 so you're OK.

Hope this helps.
Back to top
Report this message as abusive
Dr Tank

User


Joined: Wed Apr 1st 2009
Location: Southampton, UK
Posted: 21st May 2010 16:30     Edited: 21st May 2010 16:39     | link | toggle

Thanks dude. I pondered doing the my4vector.xy thing but in the end went with easier solution. Perhaps i'll implement it when I update. Difference is that currently for 4:3, the sides of the object seen by cam 0 are off screen. But I figure the shader skips over drawing these parts anyway so with luck speed is unaffected.

I did wonder what might happen if a 4vector was sent to a 2 vector. Might it write to the pointer or something and overwrite other data? But as you say there's no need to do that.

I'm basically using shader model 2 for everything now. I get the impression that most users' computers support it. Is this a valid assumption? I find swizzling, casting etc kind of confusing. If you check out the pixel shaders here maybe you can see some speed improvements. I'm doing things like:

+ Code Snippet

when i would rather do something like
+ Code Snippet
but i couldn't figure out how to get that kind of thing working. Perhaps they result in the same compiled code. I've really got to check out FXComposer!

Played a little with this since. By sync masking out the back facing camera when it's not required, FPS gains about 10%. Possible improvements to this include squashing the cube map co-ordinates and camera frustrums along the z-axis to achieve more uniform texture scaling across the screen, and switching to a single extra camera with variable FOV when zoomed in.
Back to top
Report this message as abusive
Google Ad
Back to top
 
Green Gandalf

Valued Member


Joined: Mon Jan 3rd 2005
Location: Cornwall UK
Posted: 21st May 2010 22:34           | link | toggle

Quote: "when i would rather do something like"

+ Code Snippet

Quote: "but i couldn't figure out how to get that kind of thing working."

I do that a lot. Can you give an example where that snippet doesn't work for you?

Quote: "Perhaps they result in the same compiled code."

Quite possible. I've often tried fiddling with things like that to save an instruction or two and failed. The DX9 fx compiler has a built-in optimizer which is hard to beat.

Quote: "I've really got to check out FXComposer!"

Or Dark Shader - both will give you the compiled asm listing.

Quote: "I'm basically using shader model 2 for everything now. I get the impression that most users' computers support it. Is this a valid assumption?"

Yes. I use SM3 (or PS2a) when I run into instruction count limits, or just PS3 if I want texture reads in the vertex shader. Both are supported by DBPro. I haven't tried SM4 yet because it's not supported by DX9/DBPro.
Back to top
Report this message as abusive
Dr Tank

User


Joined: Wed Apr 1st 2009
Location: Southampton, UK
Posted: 22nd May 2010 12:56           | link | toggle

Quote: "I do that a lot. Can you give an example where that snippet doesn't work for you?"
It appears I may have been talking out of my bottom. What i said didn't work did work.

I'm will give shader model 3 a bash, because i want to use texture lookup in the vertex shader to scrolling, level of detail terrain. Any idea how commonly suppoerted it is?
Back to top
Report this message as abusive
Green Gandalf

Valued Member


Joined: Mon Jan 3rd 2005
Location: Cornwall UK
Posted: 23rd May 2010 00:17           | link | toggle

Quote: "What i said didn't work did work."



Quote: "Any idea how commonly suppoerted it is?"

It's quite widely supported on games machines with a reasonable spec - but I'd guess it is less common on machines you might find in a standard commercial, industrial or education environment. SM2 is more standard there.
Back to top
Report this message as abusive
Dr Tank

User


Joined: Wed Apr 1st 2009
Location: Southampton, UK
Posted: 15th Jul 2010 15:39     Edited: 15th Jul 2010 15:44     | link | toggle

Sorry for tardy reply. I guess I'll stick with SM2 for a bit.

Here's another demo. This only has the sterographic camera (angle, circle preserving), but has a clear zoom, using a single extra camera instead of the cube map for small FOV.

I attach the rar compressed project folder. Exe is included because future versions of DBP may complile the code differently. Download is 880 kB.

I also append the code for quick reference. Note that from the second shader, only one technique (Spherical) and pixel shader (PShader) is used by the program.

Here is the .dba: + Code Snippet

shader "fx/singlecam16by9zoom.fx": + Code Snippet

shader "fx/final2.fx": + Code Snippet
Back to top
Download: stereographic cam with zoom july 10.rar Size: 902099 bytesReport this message as abusive

Go to the first page of this board Return to the Forum Menu Post Message
7 Messages - Page   of 1   
Search the Forum

Sorry, but it has been so long since anyone replied to this Thread that it has been automatically locked.
You may read it but not reply.

Forum Search

Enter a word or phrase to search our Forum for:

Thread Subject Search
Search Phrase:
Search Scope: Entire forum
Just this board
 
Google Forum Search
Search Phrase:
 
Apollo v2.02


Privacy Policy AUP Top of Page