Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application crosstalk feature #200

Closed
wants to merge 5 commits into from
Closed

Conversation

megai2
Copy link

@megai2 megai2 commented Jan 4, 2021

Hi. I want to add an ability to supply data to reshade from games/mods.

For example supplying depth buffer without heuristics or 3d scene without UI
by reshade independent code i.e. without specific forks.
(real story behind that is various requests from Guild Wars 2 community to make a modern
version of https://github.com/04348/Gw2Hook and also some other requests)

I did make some hacky implementation for dx12, that uses command list SetPrivateData
function to supply needed data using magic guid and data checks.
Supplied data is later used on effect reload to replace texture resources with specific names.

General idea works, but it will be nice to hear
some comments about that, before making more changes.

-centralize changes
-add all other resource indexes to replacement sequence
-general clean up
@crosire
Copy link
Owner

crosire commented Jan 4, 2021

I'm actually currently working on a add-on API for ReShade, which would allow other mods to communicate with ReShade and even change game's rendering behavior through ReShade. This has not been pushed to GitHub yet though, but can do so soon for feedback.

The "official" solution to provide custom textures to shaders is using semantics: texture fooBar : MY_SPECIAL_TEXTURE, so I'll work on making sure the API has means to set those, so that a GW2 mod could provide ReShade with the right resources and have shaders access them via e.g.

texture zprepass : ZPREPASS;
texture gbuf_0 : GBUF_0;
texture gbuf_1 : GBUF_1;
texture gbuf_2 : GBUF_2;
texture gbuf_3 : GBUF_3;
texture gbuf_4 : GBUF_4;
texture overlay_0 : OVERLAY_0;
texture overlay_1 : OVERLAY_1;
...

@megai2
Copy link
Author

megai2 commented Jan 5, 2021

Good to hear that.
So for now i can replace

		if (texture.unique_name == "V__crosstalk_color")
			resource = crosstalk::get_crosstalk_resource(crosstalk::ResNames::COLOR);

lines with

		if (texture.semantic == "CROSSTALK_COLOR")
			resource = crosstalk::get_crosstalk_resource(crosstalk::ResNames::COLOR);

And this will work with following up API, without changes in shaders?

@crosire
Copy link
Owner

crosire commented Jan 5, 2021

Probably, yes.

to make shaders somewhat forward compatible
megai2 added a commit to megai2/gw2enhanced that referenced this pull request Jan 5, 2021
-crosstalk patch diff & discussions here
crosire/reshade#200
-ui bypass will work with latest build of d912pxy and reshade_compat iframe mod (enabled in config)
when any form of postprocessing is disabled in game
@jiangyi0923
Copy link

Can you open your modified reshade source code so that I can do Chinese localization?

this avoids crash when supplied texture changes
@crosire
Copy link
Owner

crosire commented Oct 22, 2021

Closing this since it can be achieved with the add-on system now:

// Somewhere in Gw2Hook:
#include <reshade.hpp>
...
ID3D12Resource *gColorRes = ...;
ID3D12Resource *gGBuf0Res = ...;
reshade::api::resource_view g_color_srv = {};
reshade::api::resource_view g_gbuf0_srv = {};
...
if (reshade::register_addon(hModule)) {
    // ReShade is loaded and we successfully registered us as an add-on
    // Register callback that is executed every time ReShade reloads effects to update textures
    reshade::register_event<reshade::addon_event::reloaded_effects>(
        [](reshade::api::effect_runtime *runtime) {
            reshade::api::device *const device = runtime->get_device();

            // Create resource views for the D3D12 resources (the "reshade::api::resource" handle passed into the first argument is just a "D3D12Resource" pointer in D3D12, so can use it directly)
            // If you already have a view descriptor (D3D12_CPU_DESCRIPTOR_HANDLE) for these resources, can skip this and pass those into "update_texture_bindings" directly (the "reshade::api::resource_view" handle is a typedef for D3D12_CPU_DESCRIPTOR_HANDLE in D3D12).
            if (g_color_srv == 0 && !device->create_resource_view({ reinterpret_cast<uint64_t>(gColorRes) }, reshade::api::resource_usage::shader_resource, reshade::api::resource_view_desc(...), &g_color_srv))
                return;
            if (g_gbuf0_srv == 0 && !device->create_resource_view({ reinterpret_cast<uint64_t>(gGBuf0Res) }, reshade::api::resource_usage::shader_resource, reshade::api::resource_view_desc(...), &g_gbuf0_srv))
                return;

            // Pass resource views to ReShade effect runtime and bind it to all textures with the provided semantic name
            runtime->update_texture_bindings("CROSSTALK_COLOR", g_color_srv);
            runtime->update_texture_bindings("CROSSTALK_GBUF_0", g_gbuf0_srv);
            ...
        });
}

@crosire crosire closed this Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants