bo3b / 3Dmigoto

Chiri's DX11 wrapper to enable fixing broken stereoscopic effects.
Other
688 stars 109 forks source link

does 3dmigoto have an equivelant of BUFFER_RCP_WIDTH or BUFFER_WIDTH to determine the screensize? #152

Closed thrive4 closed 2 years ago

thrive4 commented 2 years ago

I have been experimenting with some custom shaders lately, mostly trying to port some reshade shaders, and was wondering does 3dmigoto have an equivalent of BUFFER_WIDTH / HEIGHT or BUFFER_RCP_WIDTH / HEIGHT?

With reshade these (intrinsic(s)?) are used by example as: static const float2 PixelSize = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); static const float2 ScreenSize = float2(BUFFER_WIDTH, BUFFER_HEIGHT);

snippet from the reshade repo https://github.com/crosire/reshade/blob/9c9394fb18c8ec328bbb9e760f66291d3eab2a79/include/reshade_api.hpp line 66: ///

/// Gets the current buffer dimensions of the swap chain as used with effect rendering. /// The returned values are equivalent to BUFFER_WIDTH and BUFFER_HEIGHT in ReShade FX.

Or maybe there is an other way to attain the buffer dimensions and utilize them in a custom shader?

I am currently using:

define px 1.0f / 1920

define py 1.0f / 1080

define pixel float2(px,py)

define pxm 0.5 * px

define pym 0.5 * py

Which works but is rather inflexible.

Thanks in advance.

DarkStarSword commented 2 years ago

res_width and res_height return the swap chain size (get_resolution_from=depth_stencil can change this to use a heuristic to guess the internal render size for games that down/upscale). There's also rt_width / rt_height to get the dimensions of the currently bound render targets. window_width and window_height can get the window dimensions as that is occasionally more appropriate than the swap chain (but outside the software mouse this is rarely the correct thing to check).

DarkStarSword commented 2 years ago

Simple usage example: https://github.com/DarkStarSword/3d-fixes/blob/master/Far%20Cry%204/d3dx.ini#L571 https://github.com/DarkStarSword/3d-fixes/blob/master/Far%20Cry%204/ShaderFixes/efce02356807ae1b-vs_replace.txt#L31

A slightly more complex example from the same game: https://github.com/DarkStarSword/3d-fixes/blob/master/Far%20Cry%204/d3dx.ini#L819 https://github.com/DarkStarSword/3d-fixes/blob/master/Far%20Cry%204/ShaderFixes/50344260ea3c9a9c-vs_replace.txt#L102

A more modern "cleaner" approach to accessing the variables in a shader, but in a much more complex scenario: https://raw.githubusercontent.com/DarkStarSword/3d-fixes-DreamfallChapters/ce53ade795f19e29ebc5bad9295d0c93e9bfa75f/d3dx.ini https://github.com/DarkStarSword/3d-fixes-DreamfallChapters/blob/ce53ade795f19e29ebc5bad9295d0c93e9bfa75f/ShaderFixes/hud_analyse.hlsl#L101 https://github.com/DarkStarSword/3d-fixes-DreamfallChapters/blob/ce53ade795f19e29ebc5bad9295d0c93e9bfa75f/ShaderFixes/hud.hlsl#L12

In some scenarios it's useful to test this variable directly from the d3dx.ini without passing it to a shader at all, e.g.

if rt_width == res_width && rt_height == res_height
    ; Do something only when this shader is drawn to the screen, e.g.
    handling = skip
endif
thrive4 commented 2 years ago

Hello Ian (DarkStarSword),

First of I would like to extend the best wishes for 2022. Thank you for your snappy and illuminating response.

It took me a while to chew on your examples, in the end I opted for using window_width and window_height as you indicated which works rather nicely.

I'm still struggling with the more finite aspects so I've put together a little note in the ini I use if you have the time or inclination any feedback would be appreciated.

Lifting on upscale.ini:

; demo iniparam ; #define red IniParams[2].xyzw ;x2 = 1.0 ;y2 = 0.0 ;z2 = 0.0 ;w2 = 1.0 ; valid subscripts are xyzw or rgba and nothing else? ; implying var[number] has a max elements of 4 x[1..4]? ; does not recognize f (1.0f) or can not define variable type assume it defaults to a float? ; in d3dx.ini place under [Constants] ; in .ini place under [CustomShaderUpscale] or [shadername]? ; generic method of loading custom vars into shader is: ; Texture1D IniParams : register(t120); ; pre defined internals are: ;x1=rt_width ;y1=rt_height ;z1=res_width ;w1=res_height ;x1=window_width ;y1=window_height ; are there more maybe there is a list with a brief explanation of what they do?

Thank you for your time,

thrive4