[WIP] KeyMapper "Shader"

  • luluco250
  • Topic Author
More
7 years 6 months ago - 7 years 6 months ago #1 by luluco250 [WIP] KeyMapper "Shader" was created by luluco250
This is a shader/plugin that writes inputs to a texture, allowing other shaders to read from it.
Why did I make this? I wanted a way to be able to select keys from the uniforms menu, after tinkering a lot and some trial and error I was able to come up with this solution.

This is more of an idea/concept of how key inputs should be shown in the menu, so the user can easily select keys from there.
Otherwise, you'd need to have them manually edit some #define with the keycode and reload the shaders.

On the technical side, it writes to 92 pixels in a RG8 texture, the first one always being blank (for a 'null' key), and you can fetch a key using a function included.

KeyMapper.fx is the main file that contains the shader and uniforms for creating the texture.
KeyMapper.fxh is a header file that contains the GetKey() function, the texture and sampler, a list of key definitions and instructions on implementation.

I've marked [WIP] in the title because the GetKey() function isn't working properly yet, it can read a few keys but not others.
The KeyMapper technique also provides a debug shader that shows the texture on the screen, and it shows that even though the keys are working as intended, the function itself isn't.
Shouldn't be much of a problem, but I'm too tired to fix it right now, will update when I do.
Also mouse buttons don't seem to work, maybe an issue with ReShade itself?

The debug shader shows a black bar on the top of the screen with red squares representing active 'hold' inputs and green squares representing active 'toggle' inputs.
'Hold' is stored in the red channel, 'toggle' in the green channel.

Here's a prototype of it as well as a 'binoculars' shader to test it: keymapper.7z(Dropbox)

A demonstration of the debug feature (yes, I held a few keys for demonstration):


And a clip demonstrating the in-menu key selection and usage in the aforementioned 'binoculars' shader [HD] :


I do hope that this is implemented in some form in ReShade's code, so that key inputs can be made a bit more straightforward.

Please do give any feedback, and should you make any modifications feel free to share your changes!
Last edit: 7 years 6 months ago by luluco250.
The following user(s) said Thank You: crosire

Please Log in or Create an account to join the conversation.

  • crosire
More
7 years 6 months ago - 7 years 6 months ago #2 by crosire Replied by crosire on topic [WIP] KeyMapper "Shader"
Interesting concept!

The issue I see right now is that each shader files gets a unique set of textures, meaning the key map from KeyMapper.fx is not shared with Binoculars.fx and the latter cannot access it (it accesses a duplicate of the same texture). So in order for this to work the map creation technique would have to be part of the fxh as well.

I can see that adding the possibility to share textures between shader files could be useful though. Maybe through using the "extern" and "static" keywords (since this is what they are used for in languages like C++) that ReShade FX already recognizes but doesn't do anything with currently. The following is an idea of how this could work:

Declare a texture write in one shader files as usual:
texture MyTexture { ... };
And to reference that texture in another effect file use use the extern keyword:
extern texture MyTexture;
The static keyword would prevent referencing from anywhere else:
static texture MyTexture { ... };
The same could be applied to uniforms in theory as well, but it would be much more complicated to implement for them and likely not worth the trouble.

As for mouse buttons: They are not queried with the "key" source, but with "mousebutton":
uniform bool LMouse < source = "mousebutton"; keycode = 0; toggle = false; >;
uniform bool RMouse < source = "mousebutton"; keycode = 1; toggle = false; >;
uniform bool MMouse < source = "mousebutton"; keycode = 2; toggle = false; >;
...
Last edit: 7 years 6 months ago by crosire.
The following user(s) said Thank You: luluco250

Please Log in or Create an account to join the conversation.

  • luluco250
  • Topic Author
More
7 years 6 months ago #3 by luluco250 Replied by luluco250 on topic [WIP] KeyMapper "Shader"
Thanks for the advice!

I've managed to fix the shader almost completely, the ONLY problem is that the left mouse button won't work, maybe it's a problem with ReShade or maybe it's on a per-game basis?
Also when creating too many keys I got a "too many constants" error, but luckily that was avoided simply by the fact that not all keys are necessary/work, so the error doesn't occur with the now-implemented keys.

I tested using the entire shader on an .fxh, but it caused duplicate techniques for each shader that #included it, so I just left it as it was before, with KeyMapper.fx writing the texture from KeyMapper.fxh and the debug feature was moved to a separate KeyMapper_Debug.fx shader.

Also there are now macros for every key, "VK_X" ones as well as more friendly "Key_X" ones that point to the key positions in the key texture map.


I think it's become fairly easy to implement in any shader, any further opinions?

I have updated it in my dropbox, link just in case: KeyMapper.7z

I have also created a small C++ application to help with copy/pasting the keys, because there are so many I just cout'd them and copied it into the shader.
Here's the source code if you're interested: KeyMapper_Helper.7z
The following user(s) said Thank You: Gar Stazi

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.