Page 1 of 2

Lens Distortion Injector

Posted: Sat Sep 15, 2012 3:01 am
by MaterialDefender
This injector doubles the screen and applies a lens distortion shader based on a simplified version of the widely used Brown lens distortion model. Nothing more, nothing less. No real 3D, no FOV-correction, no sensor input and it's DX9-11 only.

Update:

Version Alpha002

- added DX10+11 support
- removed all other shaders (weren't working anyway in conjunction with the warping shader)
- simplified file structure
- on/off toggle key changed to INSERT (configurable via injector.ini)
- added uninstall batch

Some installation notes: If you can't get a game to run you might want to experiment a little bit. There are games where the DLLs (d3d9.dll, dxgi.dll) and the injector.ini have to be copied to one directory and the other files have to be copied to another directory. One example for this is Crysis. Once you have the DLLs in the right place a file called log.log is created when you start the game. Search for this file in the games sub directories. It will tell you where to put the other files.

Also you might want to disable antialising in the games settings, some AA modes are not compatible with the injector

If you use Steam, you might want to disable the Steam overlay. Guides how to do that can be found on the internet.

*** DISCLAIMER ***
I was quite reluctant to release this at all, it was originally done for personal use. But since there will be a commercial product doing something similar, I honestly feel it is better to discuss the implications of trying to bring old games to the Rift this way before the Rift is released, and - considering that there are most likely many non developers among the kickstarter backers - even before the dev kit is released. Most likely I'm a bit older than many others here, and I've seen a bunch of great ideas go down the drain because of not so great things that where done in the wake of them.

So here is a configurable distortion injector for everyone with a DIY-Rift. I'd like to see some healthy discussion of the whole topic of bringing old games to the Rift here based on the experience that DIY-Rift owners will make with this injector. Personally I'm not so sure whether this a really good idea at all, but I think a thread like lhis will give valuable input for anyone who wants to do something similar, being it commercial or non-commercial.

This injector is not meant to compete against any commercial solution, I intentionally stripped out the DX10 and DX11 part and a basic chromatic aberration correction, and I have absolutely no intention to develop this into a solution I would call good enough for everyone. There is plenty of room left for improvements in all directions.

What I might add in the future is a small graphical configuration utility, mouse emulation, and smarter aspect ratio handling, depending on the outcome of the discussion. Nothing more. So please no feature requests. Thanks for your understanding.

Anybody may use this as he/she wants, but for non commercial purposes only.

The injector is based on a Skyrim-FXAA-injector, but should work on most DX9 titles. All I did was exchanging one single shader for a doubling/warping shader. These injectors are used in Skyrim and many other titles by tens of thousands of people, so apart from the actual distortion shader this might be one of the best tested gaming 'hacks' ever created. No guarantees are given though. If this thing kills your cat or burns down your house you're on your own. You know the drill. Be aware that some anti-cheat software might see this as cheating. I haven't heard of such a case, but be warned, if you want to use this online.
*** DISCLAIMER END ***

That out of the way, here's the interesting part:

What does it do? The injector doubles the screen and applies a lens distortion shader based on a simplified version of the widely used Brown lens distortion model. Nothing more, nothing less. No real 3D, no FOV-correction, no sensor input and it's DX9-11 only.

How do I use it? Simply copy the contents of the ZIP-archive to the directory that holds the main executable of the game/application you want to try with the injector. There might be games where this will not work, but it will work with many of them.

How do I make it work as good as possible with my DIY-Rift? You most likely want to configure a few things for your DIY-Rift. To do this, first open LensDistort_Settings.ini in any text editor. In this file you will find a section called "Lens Distortion Settings" with four parameters you can adjust. Short explanations for each parameter are given in this file.

That should be about it. Sorry for the lengthy text. It would make me happy, if anyone who tries this on his DIY-Rift, would indeed come back here to post his experiences. That's the reason for this thing.

And if I might add another wish: it would be great to see discussion about actual gaming experinces here only.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 3:25 am
by Dycus
Can you list some games that you've tested and know work?

I don't have much installed on my computer. Half-Life 2 Episode 1 did not work; I didn't test anything else, though.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 3:36 am
by MaterialDefender
I tried Skyrim, Oblivion, Mass Effect 3, Bioshock and Anna, which worked fine.

Be awrare that in some cases the folder with the .exe that launches the game might not be the same as the folder with the main game executable. It is important to use the latter one.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 3:41 am
by Dycus
Hmm, all right. I've bought BioShock, I'll have to download it again and try it out.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 3:48 am
by MaterialDefender
For Bioshock you most likely will have to create a custom shortcut and add "-dx9" as parameter after the .exe name. That is important!

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 4:37 am
by MaterialDefender
@Dycus: You might want to download the file again. The first version unintentionally had some (fake) chromatic aberration effect, that was not supposed to be there and will look not too great when real ca is added on top of it.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 6:58 am
by marbas
Comment removed as it is not relevant to the topic..anymore.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 7:26 am
by MaterialDefender
>> Is stereoscopy supported?

NO. And that is one of the reasons why I'm not too fond of such a simple warping shader at all. And one of the reasons why I released this. For people to see, if this (or a possible commercial solution that may do the same) is good enough or not.

You may want to read the original post again in this regard ;)

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 7:33 am
by marbas
Yeah, sorry about asking about stereoscopy, when it was clearly stated in the original post that it doesn't support it.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 7:37 am
by space123321
hmmmm - everything that I try crashes the game while trying to load - shyrim, hard reset demo, etc... I remove the files and everything starts up fine again?

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 7:44 am
by marbas
Have you copied ALL the files into the game exe folder?
First time I tried this I just copied the .dll and .fx file (like with Emerson system)
But with this you need to copy over all the files.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 7:53 am
by space123321
marbas wrote:Have you copied ALL the files into the game exe folder?
First time I tried this I just copied the .dll and .fx file (like with Emerson system)
But with this you need to copy over all the files.

Yes, I have copied the following 4 itmes into the game folder:

The injFX_Shaders folder (kept everything in folder)
The d3d9.dll file
injFX-Settings.h file
shader.fx file

I was able to start Emerson's injector with no issues, therefore not sure why these are causing issues?

EDIT - I was able to get SLender to run - looks good on my DIY Rift! Running a steroview through tridef yields much more immersion, however it is amazing how good a 2d view in the rift looks! Will keep playing!

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 8:31 am
by BHawthorne
Just a note, this only works on one version of the DirectX api. No DX 7, 8, 10, 11 or OpenGL compatibility. Also requires manual injection in the game directory. I wouldn't suggest using this with a Punkbuster or any multiplayer DRM game. This should marginally work on single player games that use a DirectX 9 pipeline though.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 8:48 am
by MrGreen
This is gonna end well...

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 9:18 am
by BHawthorne
MrGreen wrote:This is gonna end well...
Na, I think it's cool people are putting out more stuff for the Rift.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 9:25 am
by MaterialDefender
BHawthorne wrote:Just a note, this only works on one version of the DirectX api. No DX 7, 8, 10, 11 or OpenGL compatibility. Also requires manual injection in the game directory. I wouldn't suggest using this with a Punkbuster or any multiplayer DRM game. This should marginally work on single player games that use a DirectX 9 pipeline though.
You read the original post, did you? All of that is stated there in the most unmistakably way possible. But thanks for repeating it, can never hurt.

Besides that I won't discuss anything with you anymore. Considering our private talk yesterday you may know why.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 9:27 am
by marbas
BHawthorne wrote:Just a note, this only works on one version of the DirectX api. No DX 7, 8, 10, 11 or OpenGL compatibility. Also requires manual injection in the game directory. I wouldn't suggest using this with a Punkbuster or any multiplayer DRM game. This should marginally work on single player games that use a DirectX 9 pipeline though.
MaterialDefender did explain all that in the original post already.

Edit
Oops! MaterialDefender beat me to it

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 9:33 am
by BHawthorne
I'm giving you suggestions on how to improve your work. Out of curiosity, how will you be handling updates and customer service? Since your injector is derivative work, where is the original software license and acknowledgement of author? Definitely not in the README you supplied. It's common courtesy to do such things.

OT: You insinuate a lot by stating we had a "private talk yesterday". You're welcome to post the PMs unedited if you like. Not sure why you brought that up though. It's petty and grossly OT.

Re: Lens Distortion Injector

Posted: Sat Sep 15, 2012 10:41 am
by MaterialDefender
>> Where is the original software license and acknowledgement of author?

Thanks for considering this. Rest assured, if there had been such a thing like an original software license it would have been included.

Regarding your other concerns, please read the original post again.

Thanks for your help.

Re: Lens Distortion Injector

Posted: Mon Sep 17, 2012 2:09 am
by alexs
That's pretty neat! A small suggestion: I'd make ldMode a define - that way it is checked only once at effect load time instead of at every pixel every frame.

I haven't tested it since I didn't have skyrim installed and couldn't get it to work on the other things I had, but that might just be my setup.

Re: Lens Distortion Injector

Posted: Mon Sep 17, 2012 2:58 am
by MaterialDefender
Making the fixed values defines (all four of them, not only ldMode) would certainly make sense to some degree, but this way it's a little bit easier to read for people not accustomed to reading source code. And since it doesn't have any measurable performance impact, I think this aspect is more important. But thanks anyway.

Regarding any general problems to get it work, it my be a good idea to release another version with the DX10-11 DLL I left out in this release. It was left out intentionally, but I'll think about that.

Re: Lens Distortion Injector

Posted: Tue Oct 02, 2012 5:21 pm
by MaterialDefender
Update: Please download the updated file from the first post.

A little note: if you can get a game (or two) to run with your DIY-Rift, please tell everyone your experience. It's nice when you can have some fun before anyone else, but collecting some gaming impressions for everyone here is the reason for this injector, and it's all I ask for. Thanks.

Version Alpha002

- added DX10+11 support
- removed all other shaders (weren't working anyway in conjunction with the warping shader)
- simplified file structure
- on/off toggle key changed to INSERT (configurable via injector.ini)
- added uninstall batch

Some installation notes: If you can't get a game to run you might want to experiment a little bit. There are games where the DLLs (d3d9.dll, dxgi.dll) and the injector.ini have to be copied to one directory and the other files have to be copied to another directory. One example for this is Crysis. Once you have the DLLs in the right place a file called log.log is created when you start the game. Search for this file in the games sub directories. It will tell you where to put the other files.

Also you might want to disable antialising in the games settings, some AA modes are not compatible with the injector

If you use Steam, you might want to disable the Steam overlay. Guides how to do that can be found on the internet.

Re: Lens Distortion Injector

Posted: Wed Oct 03, 2012 5:11 am
by 2EyeGuy
That's truly awesome.

Having to put the ini file in a different directory sounds like a bug. I'm sure there's an API for getting the current module's path, or something like that, so you can use that as the path for the ini file.

By the way, has anyone tried looking at the config files for the Vuzix or iz3d drivers to see what settings work best for each game? That could give you a head-start.

Oh, and people who are adding native support to games might like a way to indicate native support to any Rift driver (including nthusim) so their game doesn't get warped twice and quadrupled. If everyone making a driver could agree on some standard easy way for games to opt out, that would be good.

Re: Lens Distortion Injector

Posted: Wed Oct 03, 2012 7:45 am
by sambeckett
Could this work with mirroring you computer desktop? Thus view netflix or a bluray disk?

Re: Lens Distortion Injector

Posted: Wed Oct 03, 2012 1:58 pm
by Dycus
If your desktop ran off DX9, yes. :P

In other words, no.

Re: Lens Distortion Injector

Posted: Wed Oct 03, 2012 3:29 pm
by MaterialDefender
I'm not much of a 3d movie fan, but the warping shader could be added as a post process shader to MediaPlayer Classic Homecinema to play side by side 3d-video. MPC-HC already supports pixel shaders, so this should be pretty straight forward. I'm not sure whether it can play back blu ray though.

Edit: It's even easier, no changes to MPC-HC required. Dropping the injector files into MPC-HCs (32bit version only!) directory works fine. For correct display of 3D-movies a shader without screen doubling will be needed though. Maybe I will do this later. In its current form with doubling it only makes sense for 2D movies. Might work with other video players that use DX9-DX11 too.

Re: Lens Distortion Injector

Posted: Wed Oct 03, 2012 10:20 pm
by 2EyeGuy
Dycus wrote:If your desktop ran off DX9, yes. :P

In other words, no.
Actually the desktop does run off DX9, or to be more precise, DX9Ex (aka DX9L). Or at least it did on Vista. But no, it still won't work. nthusim managed to do something similar though, so it must be theoretically possible.

Re: Lens Distortion Injector

Posted: Thu Oct 04, 2012 8:26 pm
by cybereality
FRAPS also hooks into the desktop, its 100% possible. Looked into it a bit and couldn't figure out how they were doing it, though.

Re: Lens Distortion Injector

Posted: Fri Oct 05, 2012 2:21 am
by Dycus
I was playing HL2 earlier with this, and FOV set to 90 for my Rift, and a Novint Falcon. It was pretty awesome! If only it had head tracking, it would be perfect.

Re: Lens Distortion Injector

Posted: Fri Oct 05, 2012 4:32 am
by MaterialDefender
cybereality wrote:FRAPS also hooks into the desktop, its 100% possible. Looked into it a bit and couldn't figure out how they were doing it, though.
There is an older open source Fraps like app called Taksi that might be of some use, IIRC it captures DX8, DX9, OpenGL and GDI. It's BSD licensed, so you might even use portions of the code commercially without opening your own code, if you include a copyright notice acknowledging the authors.

I'm not sure though whether I would spend much time for desktop handling. For die hard VR enthusiasts that might sound great, but my personal guess is that the vast majority of people won't be really interested in this. Games and to a (far) lesser degree watching movies are the interesting things. Just my two cents.

@Dycus: That's good to hear. Many married people might get some problems with something like that Novint Falcon you used, doesn't look exactly wife compatible ;) . But I'm sure it's quite immersive. Most likely I will add tracking support through an small external app once the SDK is out. As it happens I already have a high precision mouse emulation proggy lying around, that I wrote some years ago because I was unhappy with the jerky Logitech stuff I got with a gamepad I bought back then.

Re: Lens Distortion Injector

Posted: Fri Oct 05, 2012 4:34 am
by mahler
Dycus wrote:I was playing HL2 earlier with this, and FOV set to 90 for my Rift, and a Novint Falcon. It was pretty awesome! If only it had head tracking, it would be perfect.
Perhaps you could use the FreePIE application to translate the movements of your iPhone or Android phone (taped to your head) into mouse or freetrack movements?

Re: Lens Distortion Injector

Posted: Fri Oct 05, 2012 4:04 pm
by Parity
MaterialDefender wrote: ... if you can get a game (or two) to run with your DIY-Rift, please tell everyone your experience. ...

I have ArmA2 running with the Injector on my setup. Working fine so far. Navigating throgh the menues is a bit tricky though, because you will only have one mouse pointer, not two. So you have to Click kinda blind.

But wow, great experience.

Re: Lens Distortion Injector

Posted: Fri Oct 05, 2012 9:42 pm
by 2EyeGuy
I didn't think of that. A software cursor rendered on both screens (pre-warping) based on the real cursor's screen position, would be great. And maybe turning off the real cursor?

Re: Lens Distortion Injector

Posted: Sat Oct 06, 2012 2:29 am
by MaterialDefender
The cursor issue is game dependent. With many games it works fine, with others it does not. Also many games support navigating menus with the keyboard, which might be worth trying. But this is definitely an issue.

Re: Lens Distortion Injector

Posted: Fri Nov 16, 2012 11:54 pm
by Mel
I can't find a download link for this injector. Has it been removed?

Re: Lens Distortion Injector

Posted: Sat Nov 17, 2012 1:33 am
by Dycus
Here's the (to the best of my knowledge) most recent version.

Re: Lens Distortion Injector

Posted: Sat Nov 17, 2012 10:13 am
by Mel
Dycus wrote:Here's the (to the best of my knowledge) most recent version.
Thanks for this, Dycus.

Initial tests, running on Windows 7.

1. Half Life 2 (Steam): fail. Installed injector files into 'C:\Program Files (x86)\Steam\steamapps\[username]\half-life 2', nothing happened. Then installed into 'C:\Program Files (x86)\Steam\steamapps\imacmillan\half-life 2\bin', game crashes bacl to desktop on startup. Log.log contains a single line with bin directory path.

2. MS Flight Sim X: fail. Installed injector in game's root directory. Game start-up presentation looks different (loading of textures screen is black (blank) right up to about the 80%, then pops into view), then switches to cockpit mode, but no dual screen. Log.log contains several lines, all of which just state some sort of initialization completion.

3. Mirror's Edge: Success. Installed injector files in game's root folder. Injector works without issues. I've been using DDD up until now, which has no lens distortion correction, so this injector was a nice treat. The image is beautifully undistorted and makes a big difference in over-all game feel. And while 3D is absent, I think that with solid head-tracking in place, this rendering technique would be quite compelling, as Johnny Woo's WII hack makes apparent: http://www.youtube.com/watch?v=Jd3-eiid-Uw. I think I would almost like this better than true 3D, as true 3D makes my head feel weird after a couple of minutes...there's something 'not right' about it.

4. Media Player Classic, set to D3D full-screen mode: Fail. I wasn't expecting this to work, but was sure hoping it would.

That's all for now.

Re: Lens Distortion Injector

Posted: Sat Nov 17, 2012 11:14 am
by jf031
Mel wrote:1. Half Life 2 (Steam): fail. Installed injector files into 'C:\Program Files (x86)\Steam\steamapps\[username]\half-life 2', nothing happened. Then installed into 'C:\Program Files (x86)\Steam\steamapps\imacmillan\half-life 2\bin', game crashes bacl to desktop on startup. Log.log contains a single line with bin directory path.
The file placement I thought would work (it works for Garry's Mod) doesn't function with Half-Life 2 Episode 1. I do not currently have Half-Life 2 installed.

Anyway, the following works with Garry's Mod, at least. As stated in the Injector's included .txt file, the injector.ini, dxgi.dll, and d3d9.dll files might need to go in a separate folder. In this case, put those files in the "bin" folder, with the rest of the files in the "garrysmod" folder (or "half-life 2" folder, if you want to try this).
Mel wrote:3. Mirror's Edge: Success. Installed injector files in game's root folder. Injector works without issues. I've been using DDD up until now, which has no lens distortion correction, so this injector was a nice treat. The image is beautifully undistorted and makes a big difference in over-all game feel. And while 3D is absent, I think that with solid head-tracking in place, this rendering technique would be quite compelling, as Johnny Woo's WII hack makes apparent: http://www.youtube.com/watch?v=Jd3-eiid-Uw. I think I would almost like this better than true 3D, as true 3D makes my head feel weird after a couple of minutes...there's something 'not right' about it.
Stereoscopic 3D is far from true 3D. There is no real depth information since all of it is projected from a flat surface, so when your eyes converge on various objects, there is no change is accommodation (http://en.wikipedia.org/wiki/Accommodation_%28eye%29), thus everything is still in focus. That is probably the part you notice as "not right." As stated elsewhere on these forums, there is a feasible way of faking the effects of accommodation via additional hardware and software, though.
Mel wrote: 4. Media Player Classic, set to D3D full-screen mode: Fail. I wasn't expecting this to work, but was sure hoping it would.
I was also unable to get it to work with Media Player Classic. However, it works well in VLC media player (http://www.videolan.org/vlc/index.html) with Direct3D output mode. Also, while you have the Injector installed, VLC might open and immediately close if you open a file directly through Windows 7 (the "open with..." option when right-clicking on a file, or just opening a file after setting VLC as the default program). Running VLC first, then opening a movie through it works fine.

edit: my description of stereoscopic 3D is poor. True holograms (with original light field information) are also stored on a flat surface. It is just that stereoscopy is merely two completely flat images with no real-world depth information, unlike real holograms (I hate that things like the mirror projections of Tupac and that anime pop-star thing in Japan are called holograms; they aren't at all).

Re: Lens Distortion Injector

Posted: Sat Nov 17, 2012 11:28 am
by Dycus
I've gotten Half-Life 2 on Steam to work. Put all the files in the "half-life 2" directory in Steam's files, where hl2.exe is. Then move d3d9.dll and dxgi.dll to the bin folder.

Re: Lens Distortion Injector

Posted: Sat Nov 17, 2012 11:41 am
by Mel
jf031 wrote:
Mel wrote:1. Half Life 2 (Steam): fail. Installed injector files into 'C:\Program Files (x86)\Steam\steamapps\[username]\half-life 2', nothing happened. Then installed into 'C:\Program Files (x86)\Steam\steamapps\imacmillan\half-life 2\bin', game crashes bacl to desktop on startup. Log.log contains a single line with bin directory path.
The file placement I thought would work (it works for Garry's Mod) doesn't function with Half-Life 2 Episode 1. I do not currently have Half-Life 2 installed.

Anyway, the following works with Garry's Mod, at least. As stated in the Injector's included .txt file, the injector.ini, dxgi.dll, and d3d9.dll files might need to go in a separate folder. In this case, put those files in the "bin" folder, with the rest of the files in the "garrysmod" folder (or "half-life 2" folder, if you want to try this).
Mel wrote:3. Mirror's Edge: Success. Installed injector files in game's root folder. Injector works without issues. I've been using DDD up until now, which has no lens distortion correction, so this injector was a nice treat. The image is beautifully undistorted and makes a big difference in over-all game feel. And while 3D is absent, I think that with solid head-tracking in place, this rendering technique would be quite compelling, as Johnny Woo's WII hack makes apparent: http://www.youtube.com/watch?v=Jd3-eiid-Uw. I think I would almost like this better than true 3D, as true 3D makes my head feel weird after a couple of minutes...there's something 'not right' about it.
Stereoscopic 3D is far from true 3D. There is no real depth information since all of it is projected from a flat surface, so when your eyes converge on various objects, there is no change is accommodation (http://en.wikipedia.org/wiki/Accommodation_%28eye%29), thus everything is still in focus. That is probably the part you notice as "not right." As stated elsewhere on these forums, there is a feasible way of faking the effects of accommodation via additional hardware and software, though.
Mel wrote: 4. Media Player Classic, set to D3D full-screen mode: Fail. I wasn't expecting this to work, but was sure hoping it would.
I was also unable to get it to work with Media Player Classic. However, it works well in VLC media player (http://www.videolan.org/vlc/index.html) with Direct3D output mode. Also, while you have the Injector installed, VLC might open and immediately close if you open a file directly through Windows 7 (the "open with..." option when right-clicking on a file, or just opening a file after setting VLC as the default program). Running VLC first, then opening a movie through it works fine.
I am looking forward to the day where the 'effects of accomodation' fixes are worked out. Until then, 3D will remain a novelty I will use for only short periods of time. Thee weirdness takes the joy out of it for me.

I will give VLC a try sometime this weekend. Thanks.