From 4a406e2a803190cea1bedd78253bcc448ece68d4 Mon Sep 17 00:00:00 2001 From: Peter Thoman Date: Fri, 26 Oct 2012 16:01:15 +0200 Subject: [PATCH] Version 1.9 - Added 2 new ambient occlusion algorithms: HBAO and SCAO - Added scale option for ambient occlusion on lower-end systems - Disabled hotkeys when Dark Souls is not active - Reinstated the texture filtering option with slightly better implementation - Rework WindowManager::resize to center the window along with resizing, and call on startup (wT) - Fix prevExStyle in WindowManager::toggleBorderlessFullscreen (wT) --- Actions.def | 4 +- DATA/VERSIONS.txt | 10 ++ DATA/dsfix/HBAO.fx | 269 ++++++++++++++++++++++++++++++++ DATA/dsfix/SCAO.fx | 340 +++++++++++++++++++++++++++++++++++++++++ DATA/dsfix/VSSAO.fx | 24 +-- DSfix.v11.suo | Bin 94720 -> 94720 bytes DSfix.vcxproj | 4 +- FPS.cpp | 4 +- KeyActions.cpp | 10 +- RenderstateManager.cpp | 66 +++++--- RenderstateManager.h | 14 +- VSSAO.cpp => SSAO.cpp | 43 ++++-- VSSAO.h => SSAO.h | 8 +- Settings.cpp | 1 + Settings.def | 4 +- WindowManager.cpp | 32 ++-- d3d9dev.cpp | 17 +-- main.cpp | 1 - main.h | 2 +- 19 files changed, 764 insertions(+), 89 deletions(-) create mode 100644 DATA/dsfix/HBAO.fx create mode 100644 DATA/dsfix/SCAO.fx rename VSSAO.cpp => SSAO.cpp (65%) rename VSSAO.h => SSAO.h (79%) diff --git a/Actions.def b/Actions.def index 2c7e764..46365ba 100644 --- a/Actions.def +++ b/Actions.def @@ -25,7 +25,9 @@ ACTION(toggle30FPSLimit, Settings::get().toggle30FPSLimit()) // Development Actions -ACTION(reloadSSAOEffect, RSManager::get().reloadVssao()) +ACTION(reloadVSSAOEffect, RSManager::get().reloadVssao()) +ACTION(reloadHBAOEffect, RSManager::get().reloadHbao()) +ACTION(reloadSCAOEffect, RSManager::get().reloadScao()) ACTION(reloadGAUSSEffect, RSManager::get().reloadGauss()) ACTION(reloadAAEffect, RSManager::get().reloadAA()) diff --git a/DATA/VERSIONS.txt b/DATA/VERSIONS.txt index 84ad798..a6a8576 100644 --- a/DATA/VERSIONS.txt +++ b/DATA/VERSIONS.txt @@ -1,3 +1,13 @@ +25-10-1012 -- version 1.9 beta +============================== +- Added 2 new ambient occlusion algorithms: HBAO and SCAO +- Added scale option for ambient occlusion on lower-end systems +- Disabled hotkeys when Dark Souls is not active +- Reinstated the texture filtering option with slightly better implementation +- Rework WindowManager::resize to center the window along with resizing, and call on startup (wT) +- Fix prevExStyle in WindowManager::toggleBorderlessFullscreen (wT) + + 21-10-1012 -- version 1.8 beta ============================== - Added FXAA option for AA diff --git a/DATA/dsfix/HBAO.fx b/DATA/dsfix/HBAO.fx new file mode 100644 index 0000000..701d74e --- /dev/null +++ b/DATA/dsfix/HBAO.fx @@ -0,0 +1,269 @@ +// Cosine Weighted HBAO +// Originally based off of NVIDIA's HBAO, implemented and heavily modified by Tomerk +// Adapted and tweaked for Dark Souls by Durante + +/***User-controlled variables***/ +#define N_DIRECTIONS 8 //number of directions to sample in, currently do not change. +#define N_STEPS 6 //number of steps to raymarch, you may change The higher this is the higher the quality and the lower the performance. + +extern float aoRadiusMultiplier = 5.0; //Linearly multiplies the radius of the AO Sampling +extern float Attenuation_Factor = 0.1; //Affects units in space the AO will extend to + +extern float FOV = 85; //Field of View in Degrees + +extern float luminosity_threshold = 0.3; + +#ifndef SCALE +#define SCALE 1.0 +#endif + +#ifndef SSAO_STRENGTH_LOW +#ifndef SSAO_STRENGTH_MEDIUM +#ifndef SSAO_STRENGTH_HIGH +#define SSAO_STRENGTH_MEDIUM 1 +#endif +#endif +#endif + +#ifdef SSAO_STRENGTH_LOW +extern float aoClamp = 0.75; +extern float aoStrengthMultiplier = 2.0; +#endif + +#ifdef SSAO_STRENGTH_MEDIUM +extern float aoClamp = 0.4; +extern float aoStrengthMultiplier = 4.5; +#endif + +#ifdef SSAO_STRENGTH_HIGH +extern float aoClamp = 0.15; +extern float aoStrengthMultiplier = 6.0; +#endif + + +#define LUMINANCE_CONSIDERATION //comment this line to not take pixel brightness into account +//#define RAW_SSAO //uncomment this line to show the raw ssao + +/***End Of User-controlled Variables***/ +static float2 rcpres = PIXEL_SIZE; +static float aspect = rcpres.y/rcpres.x; +static const float nearZ = 1.0; +static const float farZ = 5000.0; +static const float2 g_InvFocalLen = { tan(0.5f*radians(FOV)) / rcpres.y * rcpres.x, tan(0.5f*radians(FOV)) }; +static const float depthRange = nearZ-farZ; + +texture2D depthTex2D; +texture2D frameTex2D; +texture2D prevPassTex2D; + +sampler depthSampler = sampler_state +{ + texture = ; + AddressU = CLAMP; + AddressV = CLAMP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; +}; + +sampler frameSampler = sampler_state +{ + texture = ; + AddressU = CLAMP; + AddressV = CLAMP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; +}; + +sampler passSampler = sampler_state +{ + texture = ; + AddressU = CLAMP; + AddressV = CLAMP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; +}; + +struct VSOUT +{ + float4 vertPos : POSITION; + float2 UVCoord : TEXCOORD0; +}; + +struct VSIN +{ + float4 vertPos : POSITION0; + float2 UVCoord : TEXCOORD0; +}; + +VSOUT FrameVS(VSIN IN) +{ + VSOUT OUT = (VSOUT)0.0f; // initialize to zero, avoid complaints. + OUT.vertPos = IN.vertPos; + OUT.UVCoord = IN.UVCoord; + return OUT; +} + +static float2 sample_offset[N_DIRECTIONS] = +{ +//#if N_DIRECTIONS >= 9 + float2(1, 0), + float2(0.7071f, 0.7071f), + float2(0, 1), + float2(-0.7071f, 0.7071f), + float2(-1, 0), + float2(-0.7071f, -0.7071f), + float2(0, -1), + float2(0.7071f, -0.7071f) +//#endif +}; + +float2 rand(in float2 uv) { + float noiseX = (frac(sin(dot(uv, float2(12.9898,78.233)*2.0)) * 43758.5453)); + float noiseY = sqrt(1-noiseX*noiseX); + return float2(noiseX,noiseY); +} + +float readDepth(in float2 coord : TEXCOORD0) { + float4 col = tex2D(depthSampler, coord); + float posZ = ((1.0-col.z) + (1.0-col.y)*256.0 + (1.0-col.x)*(257.0*256.0)); + return 1 - (posZ-nearZ)/farZ; +} + +float3 getPosition(in float2 uv, in float eye_z) { + uv = (uv * float2(2.0, -2.0) - float2(1.0, -1.0)); + float3 pos = float3(uv * g_InvFocalLen * eye_z, eye_z ); + return pos; +} + +float4 ssao_Main( VSOUT IN ) : COLOR0 { + clip(1/SCALE-IN.UVCoord.x); + clip(1/SCALE-IN.UVCoord.y); + IN.UVCoord.xy *= SCALE; + + float depth = readDepth(IN.UVCoord); + float3 pos = getPosition(IN.UVCoord, depth); + float3 dx = ddx(pos); + float3 dy = ddy(pos); + float3 norm = normalize(cross(dx,dy)); + + float sample_depth; + float3 sample_pos; + + float ao = 0.0; + float s = 0.0; + + float2 rand_vec = rand(IN.UVCoord); + float2 sample_vec_divisor = g_InvFocalLen*depth*depthRange/(aoRadiusMultiplier*5000*rcpres); + float2 sample_center = IN.UVCoord; + + for(int i = 0; i < N_DIRECTIONS; i++) + { + float theta = 0; + float temp_theta = 0; + + float temp_ao = 0; + float curr_ao = 0; + + float3 occlusion_vector = float3(0,0,0); + + float2 sample_vec = reflect(sample_offset[i], rand_vec); + sample_vec /= sample_vec_divisor; + float2 sample_coords = (sample_vec*float2(1,aspect))/N_STEPS; + + for(int k = 1; k <= N_STEPS; k++) + { + sample_depth = readDepth(sample_center + sample_coords*(k-0.5*(i%2)) ); + sample_pos = getPosition(sample_center + sample_coords*(k-0.5*(i%2)), sample_depth); + occlusion_vector = sample_pos - pos; + temp_theta = dot(norm, normalize(occlusion_vector)); + + if(temp_theta > theta) + { + theta = temp_theta; + temp_ao = 1-sqrt(1 - theta*theta ); + float dfactor = clamp(depth-0.8, 0.0, 1.0)*2; + ao += (1/ (1 + (Attenuation_Factor+dfactor) * pow(length(occlusion_vector)/aoRadiusMultiplier*depthRange,2)) )*(temp_ao-curr_ao); + curr_ao = temp_ao; + } + } + s += 1; + } + + ao /= s; + + // adjust for close and far away + if(depth>0.98) ao = lerp(ao, 0.0, (depth-0.98)*100.0); + + ao = 1.0-ao*aoStrengthMultiplier; + + return float4(clamp(ao,aoClamp,1),1,1,1); +} + +float4 HBlur( VSOUT IN ) : COLOR0 { + float color = tex2D(passSampler, IN.UVCoord).r; + + float blurred = color*0.2270270270; + blurred += tex2D(passSampler, IN.UVCoord + float2(rcpres.x*1.3846153846, 0)).r * 0.3162162162; + blurred += tex2D(passSampler, IN.UVCoord - float2(rcpres.x*1.3846153846, 0)).r * 0.3162162162; + blurred += tex2D(passSampler, IN.UVCoord + float2(rcpres.x*3.2307692308, 0)).r * 0.0702702703; + blurred += tex2D(passSampler, IN.UVCoord - float2(rcpres.x*3.2307692308, 0)).r * 0.0702702703; + + return blurred; +} + +float4 VBlur( VSOUT IN ) : COLOR0 { + float color = tex2D(passSampler, IN.UVCoord).r; + + float blurred = color*0.2270270270; + blurred += tex2D(passSampler, IN.UVCoord + float2(0, rcpres.y*1.3846153846)).r * 0.3162162162; + blurred += tex2D(passSampler, IN.UVCoord - float2(0, rcpres.y*1.3846153846)).r * 0.3162162162; + blurred += tex2D(passSampler, IN.UVCoord + float2(0, rcpres.y*3.2307692308)).r * 0.0702702703; + blurred += tex2D(passSampler, IN.UVCoord - float2(0, rcpres.y*3.2307692308)).r * 0.0702702703; + + return blurred; +} + +float4 Combine( VSOUT IN ) : COLOR0 { + float3 color = tex2D(frameSampler, IN.UVCoord).rgb; + float ao = tex2D(passSampler, IN.UVCoord/SCALE).r; + ao = clamp(ao, aoClamp, 1.0); + + #ifdef LUMINANCE_CONSIDERATION + float luminance = color.r*0.3+color.g*0.59+color.b*0.11; + float white = 1.0; + float black = 0; + + luminance = clamp(max(black,luminance-luminosity_threshold)+max(black,luminance-luminosity_threshold)+max(black,luminance-luminosity_threshold),0.0,1.0); + ao = lerp(ao,white,luminance); + #endif + + color *= 1.05; + color *= ao; + + //return float4(ao, ao, ao,1); + return float4(color,1); +} + +technique t0 +{ + pass p0 + { + VertexShader = compile vs_3_0 FrameVS(); + PixelShader = compile ps_3_0 ssao_Main(); + } + pass p1 + { + VertexShader = compile vs_3_0 FrameVS(); + PixelShader = compile ps_3_0 HBlur(); + } + pass p2 + { + VertexShader = compile vs_3_0 FrameVS(); + PixelShader = compile ps_3_0 VBlur(); + } + pass p3 + { + VertexShader = compile vs_1_1 FrameVS(); + PixelShader = compile ps_2_0 Combine(); + } +} diff --git a/DATA/dsfix/SCAO.fx b/DATA/dsfix/SCAO.fx new file mode 100644 index 0000000..e33040c --- /dev/null +++ b/DATA/dsfix/SCAO.fx @@ -0,0 +1,340 @@ +// Stupidly Combined AO +// Stupidly combines VSSAO and HBAO, by Durante + +/***User-controlled variables***/ +#define N_SAMPLES 9 //number of samples, currently do not change. +#define N_DIRECTIONS 8 //number of directions to sample in, currently do not change. +#define N_STEPS 5 //number of steps to raymarch, you may change The higher this is the higher the quality and the lower the performance. + +extern float vaoRadiusMultiplier = 1.0; //Linearly multiplies the radius of the AO Sampling +extern float haoRadiusMultiplier = 5.0; //Linearly multiplies the radius of the AO Sampling +extern float ThicknessModel = 25.0; //units in space the AO assumes objects' thicknesses are +extern float Attenuation_Factor = 0.1; //Affects units in space the AO will extend to +extern float FOV = 85; //Field of View in Degrees +extern float luminosity_threshold = 0.3; + +#ifndef SCALE +#define SCALE 1.0 +#endif + +#ifndef SSAO_STRENGTH_LOW +#ifndef SSAO_STRENGTH_MEDIUM +#ifndef SSAO_STRENGTH_HIGH +#define SSAO_STRENGTH_MEDIUM 1 +#endif +#endif +#endif + +#ifdef SSAO_STRENGTH_LOW +extern float aoClamp = 0.75; +extern float aoStrengthMultiplier = 0.6; +#endif + +#ifdef SSAO_STRENGTH_MEDIUM +extern float aoClamp = 0.5; +extern float aoStrengthMultiplier = 0.8; +#endif + +#ifdef SSAO_STRENGTH_HIGH +extern float aoClamp = 0.2; +extern float aoStrengthMultiplier = 1.2; +#endif + + +#define LUMINANCE_CONSIDERATION //comment this line to not take pixel brightness into account + +/***End Of User-controlled Variables***/ +static float2 rcpres = PIXEL_SIZE; +static float aspect = rcpres.y/rcpres.x; +static const float nearZ = 1.0; +static const float farZ = 5000.0; +static const float2 g_InvFocalLen = { tan(0.5f*radians(FOV)) / rcpres.y * rcpres.x, tan(0.5f*radians(FOV)) }; +static const float depthRange = nearZ-farZ; + +texture2D depthTex2D; +texture2D frameTex2D; +texture2D prevPassTex2D; + +sampler depthSampler = sampler_state +{ + texture = ; + AddressU = CLAMP; + AddressV = CLAMP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; +}; + +sampler frameSampler = sampler_state +{ + texture = ; + AddressU = CLAMP; + AddressV = CLAMP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; +}; + +sampler passSampler = sampler_state +{ + texture = ; + AddressU = CLAMP; + AddressV = CLAMP; + MINFILTER = LINEAR; + MAGFILTER = LINEAR; +}; + +struct VSOUT +{ + float4 vertPos : POSITION; + float2 UVCoord : TEXCOORD0; +}; + +struct VSIN +{ + float4 vertPos : POSITION0; + float2 UVCoord : TEXCOORD0; +}; + +VSOUT FrameVS(VSIN IN) +{ + VSOUT OUT; + OUT.vertPos = IN.vertPos; + OUT.UVCoord = IN.UVCoord; + return OUT; +} + +static float2 sample_offset_hb[N_DIRECTIONS] = +{ +//#if N_DIRECTIONS >= 9 + float2(1, 0), + float2(0.7071f, 0.7071f), + float2(0, 1), + float2(-0.7071f, 0.7071f), + float2(-1, 0), + float2(-0.7071f, -0.7071f), + float2(0, -1), + float2(0.7071f, -0.7071f) +//#endif +}; + +static float2 sample_offset[N_SAMPLES] = +{ +//#if N_SAMPLES >= 9 + float2(-0.1376476f, 0.2842022f), + float2(-0.626618f, 0.4594115f), + float2(-0.8903138f, -0.05865424f), + float2(0.2871419f, 0.8511679f), + float2(-0.1525251f, -0.3870117f), + float2(0.6978705f, -0.2176773f), + float2(0.7343006f, 0.3774331f), + float2(0.1408805f, -0.88915f), + float2(-0.6642616f, -0.543601f) +//#endif +}; + +static float sample_radius[N_SAMPLES] = +{ +//#if N_SAMPLES >= 9 + 0.948832, + 0.629516, + 0.451554, + 0.439389, + 0.909372, + 0.682344, + 0.5642, + 0.4353, + 0.5130 +//#endif +}; + +float2 rand(in float2 uv) { + float noiseX = (frac(sin(dot(uv, float2(12.9898,78.233)*2.0)) * 43758.5453)); + float noiseY = sqrt(1-noiseX*noiseX); + return float2(noiseX, noiseY); +} + +float readDepth(in float2 coord : TEXCOORD0) { + float4 col = tex2D(depthSampler, coord); + float posZ = ((1.0-col.z) + (1.0-col.y)*256.0 + (1.0-col.x)*(257.0*256.0)); + return (posZ-nearZ)/farZ; +} +float readDepthHb(in float2 coord : TEXCOORD0) { + float4 col = tex2D(depthSampler, coord); + float posZ = ((1.0-col.z) + (1.0-col.y)*256.0 + (1.0-col.x)*(257.0*256.0)); + return 1 - (posZ-nearZ)/farZ; +} + +float3 getPosition(in float2 uv, in float eye_z) { + uv = (uv * float2(2.0, -2.0) - float2(1.0, -1.0)); + float3 pos = float3(uv * g_InvFocalLen * eye_z, eye_z ); + return pos; +} + +float4 ssao_Main( VSOUT IN ) : COLOR0 { + clip(1/SCALE-IN.UVCoord.x); + clip(1/SCALE-IN.UVCoord.y); + IN.UVCoord.xy *= SCALE; + + float vao=0, hao=0; + + // VSSAO + { + float depth = readDepth(IN.UVCoord); + float3 pos = getPosition(IN.UVCoord, depth); + float3 dx = ddx(pos); + float3 dy = ddy(pos); + float3 norm = normalize(cross(dx,dy)); + norm.y *= -1; + + float sample_depth; + + float s=0.0; + + float2 rand_vec = rand(IN.UVCoord); + float2 sample_vec_divisor = g_InvFocalLen*depth*depthRange/(vaoRadiusMultiplier*5000*rcpres); + float2 sample_center = IN.UVCoord + norm.xy/sample_vec_divisor*float2(1,aspect); + float sample_center_depth = depth*depthRange + norm.z*vaoRadiusMultiplier*10; + + for(int i = 0; i < N_SAMPLES; i++) { + float2 sample_vec = reflect(sample_offset[i], rand_vec); + sample_vec /= sample_vec_divisor; + float2 sample_coords = sample_center + sample_vec*float2(1,aspect); + + float curr_sample_radius = sample_radius[i]*vaoRadiusMultiplier*10; + float curr_sample_depth = depthRange*readDepth(sample_coords); + + vao += clamp(0,curr_sample_radius+sample_center_depth-curr_sample_depth,2*curr_sample_radius); + vao -= clamp(0,curr_sample_radius+sample_center_depth-curr_sample_depth-ThicknessModel,2*curr_sample_radius); + s += 2*curr_sample_radius; + } + + vao /= s; + if(depth<0.1) vao = lerp(vao, 0.0, (0.1-depth)*10.0); + } + + // HBAO + { + float depth = readDepthHb(IN.UVCoord); + float3 pos = getPosition(IN.UVCoord, depth); + float3 dx = ddx(pos); + float3 dy = ddy(pos); + float3 norm = normalize(cross(dx,dy)); + + float sample_depth; + float3 sample_pos; + + float s = 0.0; + + float2 rand_vec = rand(IN.UVCoord); + float2 sample_vec_divisor = g_InvFocalLen*depth*depthRange/(haoRadiusMultiplier*5000*rcpres); + float2 sample_center = IN.UVCoord; + + for(int i = 0; i < N_DIRECTIONS; i++) + { + float theta = 0; + float temp_theta = 0; + + float temp_ao = 0; + float curr_ao = 0; + + float3 occlusion_vector = float3(0,0,0); + + float2 sample_vec = reflect(sample_offset_hb[i], rand_vec); + sample_vec /= sample_vec_divisor; + float2 sample_coords = (sample_vec*float2(1,aspect))/N_STEPS; + + for(int k = 1; k <= N_STEPS; k++) + { + sample_depth = readDepthHb(sample_center + sample_coords*(k-0.5*(i%2)) ); + sample_pos = getPosition(sample_center + sample_coords*(k-0.5*(i%2)), sample_depth); + occlusion_vector = sample_pos - pos; + temp_theta = dot(norm, normalize(occlusion_vector)); + + if(temp_theta > theta) + { + theta = temp_theta; + temp_ao = 1-sqrt(1 - theta*theta ); + float dfactor = clamp(depth-0.8, 0.0, 1.0)*2; + hao += (1/ (1 + (Attenuation_Factor+dfactor) * pow(length(occlusion_vector)/haoRadiusMultiplier*depthRange,2)) )*(temp_ao-curr_ao); + curr_ao = temp_ao; + } + } + s += 1; + } + + hao /= s; + if(depth>0.98) hao = lerp(hao, 0.0, (depth-0.98)*100.0); + } + + float ao = 1.0-max(vao*aoStrengthMultiplier, hao*aoStrengthMultiplier*4); + + return float4(ao,ao,ao,1); +} + +float4 HBlur( VSOUT IN ) : COLOR0 { + float color = tex2D(passSampler, IN.UVCoord).r; + + float blurred = color*0.2270270270; + blurred += tex2D(passSampler, IN.UVCoord + float2(rcpres.x*1.3846153846, 0)).r * 0.3162162162; + blurred += tex2D(passSampler, IN.UVCoord - float2(rcpres.x*1.3846153846, 0)).r * 0.3162162162; + blurred += tex2D(passSampler, IN.UVCoord + float2(rcpres.x*3.2307692308, 0)).r * 0.0702702703; + blurred += tex2D(passSampler, IN.UVCoord - float2(rcpres.x*3.2307692308, 0)).r * 0.0702702703; + + return blurred; +} + +float4 VBlur( VSOUT IN ) : COLOR0 { + float color = tex2D(passSampler, IN.UVCoord).r; + + float blurred = color*0.2270270270; + blurred += tex2D(passSampler, IN.UVCoord + float2(0, rcpres.y*1.3846153846)).r * 0.3162162162; + blurred += tex2D(passSampler, IN.UVCoord - float2(0, rcpres.y*1.3846153846)).r * 0.3162162162; + blurred += tex2D(passSampler, IN.UVCoord + float2(0, rcpres.y*3.2307692308)).r * 0.0702702703; + blurred += tex2D(passSampler, IN.UVCoord - float2(0, rcpres.y*3.2307692308)).r * 0.0702702703; + + return blurred; +} + +float4 Combine( VSOUT IN ) : COLOR0 { + float3 color = tex2D(frameSampler, IN.UVCoord).rgb; + float ao = tex2D(passSampler, IN.UVCoord/SCALE).r; + ao = clamp(ao, aoClamp, 1.0); + + #ifdef LUMINANCE_CONSIDERATION + float luminance = color.r*0.3+color.g*0.59+color.b*0.11; + float white = 1.0; + float black = 0; + + luminance = clamp(max(black,luminance-luminosity_threshold)+max(black,luminance-luminosity_threshold)+max(black,luminance-luminosity_threshold),0.0,1.0); + ao = lerp(ao,white,luminance); + #endif + + color *= 1.05; + color *= ao; + + //return float4(ao, ao, ao,1); + return float4(color,1); +} + +technique t0 +{ + pass p0 + { + VertexShader = compile vs_3_0 FrameVS(); + PixelShader = compile ps_3_0 ssao_Main(); + } + pass p1 + { + VertexShader = compile vs_3_0 FrameVS(); + PixelShader = compile ps_3_0 HBlur(); + } + pass p2 + { + VertexShader = compile vs_3_0 FrameVS(); + PixelShader = compile ps_3_0 VBlur(); + } + pass p3 + { + VertexShader = compile vs_1_1 FrameVS(); + PixelShader = compile ps_2_0 Combine(); + } +} diff --git a/DATA/dsfix/VSSAO.fx b/DATA/dsfix/VSSAO.fx index 8bf215a..6ab7d3f 100644 --- a/DATA/dsfix/VSSAO.fx +++ b/DATA/dsfix/VSSAO.fx @@ -5,12 +5,15 @@ /***User-controlled variables***/ #define N_SAMPLES 9 //number of samples, currently do not change. -extern float scale = 1; //downsampling scale, 1 is highest quality but slowest extern float aoRadiusMultiplier = 1.0; //Linearly multiplies the radius of the AO Sampling extern float ThicknessModel = 25.0; //units in space the AO assumes objects' thicknesses are extern float FOV = 85; //Field of View in Degrees extern float luminosity_threshold = 0.3; +#ifndef SCALE +#define SCALE 1.0 +#endif + #ifndef SSAO_STRENGTH_LOW #ifndef SSAO_STRENGTH_MEDIUM #ifndef SSAO_STRENGTH_HIGH @@ -26,12 +29,12 @@ extern float aoStrengthMultiplier = 0.6; #ifdef SSAO_STRENGTH_MEDIUM extern float aoClamp = 0.5; -extern float aoStrengthMultiplier = 0.8; +extern float aoStrengthMultiplier = 0.9; #endif #ifdef SSAO_STRENGTH_HIGH extern float aoClamp = 0.2; -extern float aoStrengthMultiplier = 1.2; +extern float aoStrengthMultiplier = 1.3; #endif @@ -48,7 +51,6 @@ static const float depthRange = nearZ-farZ; texture2D depthTex2D; texture2D frameTex2D; texture2D prevPassTex2D; -texture1D thicknessTex1D; sampler depthSampler = sampler_state { @@ -97,6 +99,7 @@ VSOUT FrameVS(VSIN IN) return OUT; } + static float2 sample_offset[N_SAMPLES] = { //#if N_SAMPLES >= 9 @@ -127,11 +130,9 @@ static float sample_radius[N_SAMPLES] = //#endif }; - float2 rand(in float2 uv) { float noiseX = (frac(sin(dot(uv, float2(12.9898,78.233)*2.0)) * 43758.5453)); float noiseY = sqrt(1-noiseX*noiseX); - //float noiseY = (frac(sin(dot(uv, float2(12.9898,78.233))) * 43758.5453)); return float2(noiseX, noiseY); } @@ -153,9 +154,9 @@ float3 getPosition(in float2 uv, in float eye_z) { } float4 ssao_Main( VSOUT IN ) : COLOR0 { - clip(1/scale-IN.UVCoord.x); - clip(1/scale-IN.UVCoord.y); - IN.UVCoord.xy *= scale; + clip(1/SCALE-IN.UVCoord.x); + clip(1/SCALE-IN.UVCoord.y); + IN.UVCoord.xy *= SCALE; float depth = readDepth(IN.UVCoord); float3 pos = getPosition(IN.UVCoord, depth); @@ -190,7 +191,7 @@ float4 ssao_Main( VSOUT IN ) : COLOR0 { ao /= s; // adjust for close and far away - if(depth<0.1) ao = lerp(ao, 0.0, (0.1-depth)*10.0); + if(depth<0.075) ao = lerp(ao, 0.0, (0.075-depth)*13.3); //if(depth>0.1) ao = lerp(ao, 0.0, 1.0); ao = 1.0-ao*aoStrengthMultiplier; @@ -225,7 +226,7 @@ float4 VBlur( VSOUT IN ) : COLOR0 { float4 Combine( VSOUT IN ) : COLOR0 { float3 color = tex2D(frameSampler, IN.UVCoord).rgb; - float ao = tex2D(passSampler, IN.UVCoord/scale).r; + float ao = tex2D(passSampler, IN.UVCoord/SCALE).r; ao = clamp(ao, aoClamp, 1.0); #ifdef LUMINANCE_CONSIDERATION @@ -237,6 +238,7 @@ float4 Combine( VSOUT IN ) : COLOR0 { ao = lerp(ao,white,luminance); #endif + color *= 1.05; color *= ao; //return float4(ao, ao, ao,1); diff --git a/DSfix.v11.suo b/DSfix.v11.suo index af20ca45df2a1eb4cc3f67b9d64b88ce5c4f4a3f..b5da038a05e46bbc6c8e369255cc4ec3859b4f40 100644 GIT binary patch delta 1176 zcmb`GUr1AN6vuzR+r4+2Zn@Nzv77FXi$QCy6iG|moDnWfM}Lg6a9U=XrZvK><}95h z5^kqVdeYlNK`*jfZ$(BUDCnhx-aMfK|#C5KkSUBjRhY#o8^ZWkJ`JUgszu*)X zoZ`k>7)@~Z!{^a=^bjE=cpN&JPTC^PFv*nKfU>#UjhL@QSj2?vMfM?j#DOT0g?K!^ z17jR~Y!2NBVOFox;JXtkMzn|v$%dC~meGSx9DoF!FC5R>LO_QoPfv$H>_;i=0awyG<9VbF)$XX)pq32BCMg6nO_C||6BVyAP-0D&(oJeL7=+r0kPRlC08Sx~Yrt*a zU{=2kOnS^1S!E9zlMf5LRx>ylj%z{*+zWf@{z!;}H(RP77#s}NF>|y})@`uZXg$p6 za}pI55*1zSE2b?uX~8zHrP)yh6U{GGKuqJ1{6zz52&Uo`hOLzCU1bXV#!40G!i@Z% z{k96zxi-mAKB*Dw7_o+rUV24UG=PHZt3>=^Y;=oAbM<^GFMr{99C%M5jEC~T@2OJC zv!|}oOVfjDDt53DPfQtFb1k48s-uNM3I5}i#7-JW2kGs(t@s-F_-uajkr$tTJpKSK zs}Aa(>S!x;XP1NZivYE6dAJs^X#B)S{NyxVtPWBDqiI>P6UpBZy>|2Dc-Z}nERj~$H-U9sGFRMgxg4TjpNc%O|92Put#%iJZ7 Gy#EF1bxsrj delta 933 zcmZvZ-%FEG7{}jpdf&CTZ8|kGa^&mgVi(hG6#TI@Y?0psA znTRy;A;m`OMpmYdW-2POWffz5+t5uqi>MLvTfpx5Lx|PRzr&(N&w}Wp;lu-M;1FNUWx>OBYhY~{R3l32Z}I>YcypsKzewovk~ zdeu+aD^q`B!j&AzTa*(b8S@=x1iWtBwPzQ2+L7l`G$MQ6#A++ zu&uD0YsWiO`M!uYINdxJST^f(d8267_*d%mkX-7HEEbzt*4xmc|FcDZqjAkvAn9R4 z`YP2=!Mjmt$c*NQD$V19#hObDmoV{?#DC5hDS>p7p|~-%7Rm Av;Y7A diff --git a/DSfix.vcxproj b/DSfix.vcxproj index 51dd9c5..75cefdc 100644 --- a/DSfix.vcxproj +++ b/DSfix.vcxproj @@ -305,7 +305,7 @@ - + @@ -331,7 +331,7 @@ - + diff --git a/FPS.cpp b/FPS.cpp index 9e07251..863d152 100644 --- a/FPS.cpp +++ b/FPS.cpp @@ -57,8 +57,8 @@ void updateAnimationStepTime(float stepTime, float minFPS, float maxFPS) { float FPS = 1.0f/(stepTime/1000); if (FPS < minFPS) - stepTime = minFPS; - else if (stepTime > maxFPS) + FPS = minFPS; + else if (FPS > maxFPS) FPS = maxFPS; float cappedStep = 1/(float)FPS; diff --git a/KeyActions.cpp b/KeyActions.cpp index 4bf5378..e177513 100644 --- a/KeyActions.cpp +++ b/KeyActions.cpp @@ -68,10 +68,12 @@ void KeyActions::performAction(const char* name) { } void KeyActions::processIO() { - for(IntStrMap::const_iterator i = keyBindingMap.begin(); i != keyBindingMap.end(); ++i) { - if(GetAsyncKeyState(i->first)&1) { - SDLOG(0, "Action triggered: %s\n", i->second.c_str()); - performAction(i->second.c_str()); + if(::GetForegroundWindow() != NULL && ::GetActiveWindow() != NULL) { + for(IntStrMap::const_iterator i = keyBindingMap.begin(); i != keyBindingMap.end(); ++i) { + if(GetAsyncKeyState(i->first)&1) { + SDLOG(0, "Action triggered: %s\n", i->second.c_str()); + performAction(i->second.c_str()); + } } } } diff --git a/RenderstateManager.cpp b/RenderstateManager.cpp index 5892384..f2ded4e 100644 --- a/RenderstateManager.cpp +++ b/RenderstateManager.cpp @@ -17,19 +17,22 @@ RSManager RSManager::instance; void RSManager::initResources() { SDLOG(0, "RenderstateManager resource initialization started\n"); + unsigned rw = Settings::get().getRenderWidth(), rh = Settings::get().getRenderHeight(); + unsigned dofRes = Settings::get().getDOFOverrideResolution(); if(Settings::get().getAAQuality()) { if(Settings::get().getAAType() == "SMAA") { - smaa = new SMAA(d3ddev, Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), (SMAA::Preset)(Settings::get().getAAQuality()-1)); + smaa = new SMAA(d3ddev, rw, rh, (SMAA::Preset)(Settings::get().getAAQuality()-1)); } else { - fxaa = new FXAA(d3ddev, Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), (FXAA::Quality)(Settings::get().getAAQuality()-1)); + fxaa = new FXAA(d3ddev, rw, rh, (FXAA::Quality)(Settings::get().getAAQuality()-1)); } } - if(Settings::get().getSsaoStrength()) vssao = new VSSAO(d3ddev, Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), Settings::get().getSsaoStrength()-1); - if(Settings::get().getDOFBlurAmount()) gauss = new GAUSS(d3ddev, Settings::get().getDOFOverrideResolution()*16/9, Settings::get().getDOFOverrideResolution()); - if(Settings::get().getEnableHudMod()) hud = new HUD(d3ddev, Settings::get().getRenderWidth(), Settings::get().getRenderHeight()); - d3ddev->CreateTexture(Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &rgbaBuffer1Tex, NULL); + if(Settings::get().getSsaoStrength()) ssao = new SSAO(d3ddev, rw, rh, Settings::get().getSsaoStrength()-1, + (Settings::get().getSsaoType() == "VSSAO") ? SSAO::VSSAO : ((Settings::get().getSsaoType() == "HBAO") ? SSAO::HBAO : SSAO::SCAO) ); + if(Settings::get().getDOFBlurAmount()) gauss = new GAUSS(d3ddev, dofRes*16/9, dofRes); + if(Settings::get().getEnableHudMod()) hud = new HUD(d3ddev, rw, rh); + d3ddev->CreateTexture(rw, rh, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &rgbaBuffer1Tex, NULL); rgbaBuffer1Tex->GetSurfaceLevel(0, &rgbaBuffer1Surf); - d3ddev->CreateDepthStencilSurface(Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, false, &depthStencilSurf, NULL); + d3ddev->CreateDepthStencilSurface(rw, rh, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, false, &depthStencilSurf, NULL); d3ddev->CreateStateBlock(D3DSBT_ALL, &prevStateBlock); SDLOG(0, "RenderstateManager resource initialization completed\n"); if(!inited) startDetour(); // on first init only @@ -44,7 +47,7 @@ void RSManager::releaseResources() { SAFERELEASE(prevStateBlock); SAFEDELETE(smaa); SAFEDELETE(fxaa); - SAFEDELETE(vssao); + SAFEDELETE(ssao); SAFEDELETE(gauss); SAFEDELETE(hud); SDLOG(0, "RenderstateManager resource release completed\n"); @@ -212,7 +215,7 @@ HRESULT RSManager::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSur ++mainRTuses; } - if(mainRTuses == 2 && mainRT && zSurf && (vssao && doVssao)) { // we are switching away from the initial 3D-rendered image, do SSAO + if(mainRTuses == 2 && mainRT && zSurf && (ssao && doSsao)) { // we are switching away from the initial 3D-rendered image, do SSAO IDirect3DSurface9 *oldRenderTarget; d3ddev->GetRenderTarget(0, &oldRenderTarget); if(oldRenderTarget == mainRT) { @@ -227,15 +230,11 @@ HRESULT RSManager::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSur //if(takeScreenshot) D3DXSaveTextureToFile("0effect_z.bmp", D3DXIFF_BMP, zTex, NULL); storeRenderState(); d3ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); - //d3ddev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); - //d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); - //d3ddev->SetRenderState(D3DRS_STENCILENABLE, FALSE); - //d3ddev->SetRenderState(D3DRS_CLIPPING, FALSE); d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); d3ddev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); // perform SSAO - if(vssao && doVssao) { - vssao->go(tex, zTex, rgbaBuffer1Surf); + if(ssao && doSsao) { + ssao->go(tex, zTex, rgbaBuffer1Surf); d3ddev->StretchRect(rgbaBuffer1Surf, NULL, oldRenderTarget, NULL, D3DTEXF_NONE); } restoreRenderState(); @@ -249,7 +248,7 @@ HRESULT RSManager::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSur oldRenderTarget->Release(); } - if(mainRTuses == 5 && !lowFPSmode && mainRT && zSurf && doAA && (smaa || fxaa)) { // time to do SMAA + if(mainRTuses == 5 && !lowFPSmode && mainRT && zSurf && doAA && (smaa || fxaa)) { // time to do AA IDirect3DSurface9 *oldRenderTarget; d3ddev->GetRenderTarget(0, &oldRenderTarget); if(oldRenderTarget == mainRT) { @@ -261,10 +260,6 @@ HRESULT RSManager::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSur if(desc.Width == Settings::get().getRenderWidth() && desc.Height == Settings::get().getRenderHeight()) { storeRenderState(); d3ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); - //d3ddev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); - //d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); - //d3ddev->SetRenderState(D3DRS_STENCILENABLE, FALSE); - //d3ddev->SetRenderState(D3DRS_CLIPPING, FALSE); d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); d3ddev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); // perform AA processing @@ -407,10 +402,11 @@ HRESULT RSManager::redirectStretchRect(IDirect3DSurface9* pSourceSurface, CONST // if(capturing) dumpSurface("redirectStretchRect", it->second); // return d3ddev->StretchRect(it->second, pSourceRect, pDestSurface, pDestRect, Filter); //} - return d3ddev->StretchRect(pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter); + return d3ddev->StretchRect(pSourceSurface, pSourceRect, pDestSurface, pDestRect, D3DTEXF_LINEAR); } HRESULT RSManager::redirectSetTexture(DWORD Stage, IDirect3DBaseTexture9 * pTexture) { + if(pTexture == NULL) return d3ddev->SetTexture(Stage, pTexture); //TexIntMap::iterator it = renderTexIndices.find((IDirect3DTexture9*)pTexture); //if(it != renderTexIndices.end() && it->second == 2) { // IDirect3DSurface9* surf0; @@ -440,6 +436,20 @@ HRESULT RSManager::redirectSetTexture(DWORD Stage, IDirect3DBaseTexture9 * pText SDLOG(1, "HUD started!\n"); hudStarted = true; } + //if(mainRT && mainRTuses > 3) { + // IDirect3DTexture9* tex; + // pTexture->QueryInterface(IID_IDirect3DTexture9, (void**)&tex); + // if(tex) { + // IDirect3DSurface9* surf; + // if(tex->GetSurfaceLevel(0, &surf) == D3D_OK) { + // bool main = surf == mainRT; + // surf->Release(); + // if(main) { + // d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + // } + // } + // } + //} if(pTexture && rddp == 0 && Stage == 0) { ++rddp; } else if(pTexture && rddp == 1 && Stage == 1) { ++rddp; } else if(pTexture && rddp == 2 && Stage == 2) { ++rddp; } @@ -528,8 +538,18 @@ void RSManager::enableTakeScreenshot() { } void RSManager::reloadVssao() { - SAFEDELETE(vssao); - vssao = new VSSAO(d3ddev, Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), Settings::get().getSsaoStrength()-1); + SAFEDELETE(ssao); + ssao = new SSAO(d3ddev, Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), Settings::get().getSsaoStrength()-1, SSAO::VSSAO); + SDLOG(0, "Reloaded SSAO\n"); +} +void RSManager::reloadHbao() { + SAFEDELETE(ssao); + ssao = new SSAO(d3ddev, Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), Settings::get().getSsaoStrength()-1, SSAO::HBAO); + SDLOG(0, "Reloaded SSAO\n"); +} +void RSManager::reloadScao() { + SAFEDELETE(ssao); + ssao = new SSAO(d3ddev, Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), Settings::get().getSsaoStrength()-1, SSAO::SCAO); SDLOG(0, "Reloaded SSAO\n"); } diff --git a/RenderstateManager.h b/RenderstateManager.h index 855d6ba..00ab47d 100644 --- a/RenderstateManager.h +++ b/RenderstateManager.h @@ -7,7 +7,7 @@ #include "d3d9.h" #include "SMAA.h" #include "FXAA.h" -#include "VSSAO.h" +#include "SSAO.h" #include "GAUSS.h" #include "HUD.h" @@ -25,8 +25,8 @@ class RSManager { SMAA* smaa; FXAA* fxaa; - bool doVssao; - VSSAO* vssao; + bool doSsao; + SSAO* ssao; bool doDofGauss; GAUSS* gauss; @@ -108,8 +108,8 @@ class RSManager { return instance; } - RSManager() : smaa(NULL), fxaa(NULL), vssao(NULL), gauss(NULL), rgbaBuffer1Surf(NULL), rgbaBuffer1Tex(NULL), - inited(false), doAA(true), doVssao(true), doDofGauss(true), doHud(true), captureNextFrame(false), capturing(false), hudStarted(false), takeScreenshot(false), hideHud(false), + RSManager() : smaa(NULL), fxaa(NULL), ssao(NULL), gauss(NULL), rgbaBuffer1Surf(NULL), rgbaBuffer1Tex(NULL), + inited(false), doAA(true), doSsao(true), doDofGauss(true), doHud(true), captureNextFrame(false), capturing(false), hudStarted(false), takeScreenshot(false), hideHud(false), mainRenderTexIndex(0), mainRenderSurfIndex(0), dumpCaptureIndex(0), numKnownTextures(0), foundKnownTextures(0), skippedPresents(0) { #define TEXTURE(_name, _hash) ++numKnownTextures; #include "Textures.def" @@ -134,11 +134,13 @@ class RSManager { void enableTakeScreenshot(); bool takingScreenshot() { return takeScreenshot; } void toggleAA() { doAA = !doAA; } - void toggleVssao() { doVssao = !doVssao; } + void toggleVssao() { doSsao = !doSsao; } void toggleHideHud() { hideHud = !hideHud; } void toggleChangeHud() { doHud = !doHud; } void toggleDofGauss() { doDofGauss = !doDofGauss; } void reloadVssao(); + void reloadHbao(); + void reloadScao(); void reloadGauss(); void reloadAA(); diff --git a/VSSAO.cpp b/SSAO.cpp similarity index 65% rename from VSSAO.cpp rename to SSAO.cpp index 92839c5..66f73c5 100644 --- a/VSSAO.cpp +++ b/SSAO.cpp @@ -1,4 +1,4 @@ -#include "VSSAO.h" +#include "SSAO.h" #include #include @@ -8,18 +8,25 @@ using namespace std; #include "Settings.h" #include "RenderstateManager.h" -VSSAO::VSSAO(IDirect3DDevice9 *device, int width, int height, unsigned strength) +SSAO::SSAO(IDirect3DDevice9 *device, int width, int height, unsigned strength, Type type) : Effect(device), width(width), height(height) { // Setup the defines for compiling the effect vector defines; - stringstream s; // Setup pixel size macro - s << "float2(1.0 / " << width << ", 1.0 / " << height << ")"; - string pixelSizeText = s.str(); - D3DXMACRO pixelSizeMacro = { "PIXEL_SIZE", pixelSizeText.c_str() }; - defines.push_back(pixelSizeMacro); + stringstream sp; + sp << "float2(1.0 / " << width << ", 1.0 / " << height << ")"; + string pixelSizeText = sp.str(); + D3DXMACRO pixelSizeMacro = { "PIXEL_SIZE", pixelSizeText.c_str() }; + defines.push_back(pixelSizeMacro); + + // Setup scale macro + stringstream ss; + ss << Settings::get().getSsaoScale() << ".0"; + string scaleText = ss.str(); + D3DXMACRO scaleMacro = { "SCALE", scaleText.c_str() }; + defines.push_back(scaleMacro); D3DXMACRO strengthMacros[] = { { "SSAO_STRENGTH_LOW", "1" }, @@ -34,9 +41,15 @@ VSSAO::VSSAO(IDirect3DDevice9 *device, int width, int height, unsigned strength) DWORD flags = D3DXFX_NOT_CLONEABLE | D3DXSHADER_OPTIMIZATION_LEVEL3; // Load effect from file - SDLOG(0, "VSSAO load\n"); + const char* shader; + switch(type) { + case VSSAO: shader = "dsfix\\VSSAO.fx"; break; + case HBAO: shader = "dsfix\\HBAO.fx"; break; + case SCAO: shader = "dsfix\\SCAO.fx"; break; + } + SDLOG(0, "%s load, scale %s, strength %s\n", shader, scaleText.c_str(), strengthMacros[strength].Name); ID3DXBuffer* errors; - HRESULT hr = D3DXCreateEffectFromFile(device, GetDirectoryFile("dsfix\\VSSAO.fx"), &defines.front(), NULL, flags, NULL, &effect, &errors); + HRESULT hr = D3DXCreateEffectFromFile(device, shader, &defines.front(), NULL, flags, NULL, &effect, &errors); if(hr != D3D_OK) SDLOG(0, "ERRORS:\n %s\n", errors->GetBufferPointer()); // Create buffers @@ -51,7 +64,7 @@ VSSAO::VSSAO(IDirect3DDevice9 *device, int width, int height, unsigned strength) prevPassTexHandle = effect->GetParameterByName(NULL, "prevPassTex2D"); } -VSSAO::~VSSAO() { +SSAO::~SSAO() { SAFERELEASE(effect); SAFERELEASE(buffer1Surf); SAFERELEASE(buffer1Tex); @@ -59,7 +72,7 @@ VSSAO::~VSSAO() { SAFERELEASE(buffer2Tex); } -void VSSAO::go(IDirect3DTexture9 *frame, IDirect3DTexture9 *depth, IDirect3DSurface9 *dst) { +void SSAO::go(IDirect3DTexture9 *frame, IDirect3DTexture9 *depth, IDirect3DSurface9 *dst) { device->SetVertexDeclaration(vertexDeclaration); mainSsaoPass(depth, buffer1Surf); @@ -72,7 +85,7 @@ void VSSAO::go(IDirect3DTexture9 *frame, IDirect3DTexture9 *depth, IDirect3DSurf combinePass(frame, buffer1Tex, dst); } -void VSSAO::mainSsaoPass(IDirect3DTexture9* depth, IDirect3DSurface9* dst) { +void SSAO::mainSsaoPass(IDirect3DTexture9* depth, IDirect3DSurface9* dst) { device->SetRenderTarget(0, dst); device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0); @@ -88,7 +101,7 @@ void VSSAO::mainSsaoPass(IDirect3DTexture9* depth, IDirect3DSurface9* dst) { effect->End(); } -void VSSAO::hBlurPass(IDirect3DTexture9 *depth, IDirect3DTexture9* src, IDirect3DSurface9* dst) { +void SSAO::hBlurPass(IDirect3DTexture9 *depth, IDirect3DTexture9* src, IDirect3DSurface9* dst) { device->SetRenderTarget(0, dst); // Setup variables. @@ -104,7 +117,7 @@ void VSSAO::hBlurPass(IDirect3DTexture9 *depth, IDirect3DTexture9* src, IDirect3 effect->End(); } -void VSSAO::vBlurPass(IDirect3DTexture9 *depth, IDirect3DTexture9* src, IDirect3DSurface9* dst) { +void SSAO::vBlurPass(IDirect3DTexture9 *depth, IDirect3DTexture9* src, IDirect3DSurface9* dst) { device->SetRenderTarget(0, dst); // Setup variables. @@ -120,7 +133,7 @@ void VSSAO::vBlurPass(IDirect3DTexture9 *depth, IDirect3DTexture9* src, IDirect3 effect->End(); } -void VSSAO::combinePass(IDirect3DTexture9* frame, IDirect3DTexture9* ao, IDirect3DSurface9* dst) { +void SSAO::combinePass(IDirect3DTexture9* frame, IDirect3DTexture9* ao, IDirect3DSurface9* dst) { device->SetRenderTarget(0, dst); //device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 255, 0, 255), 1.0f, 0); diff --git a/VSSAO.h b/SSAO.h similarity index 79% rename from VSSAO.h rename to SSAO.h index b824997..2ae308a 100644 --- a/VSSAO.h +++ b/SSAO.h @@ -7,10 +7,12 @@ #include "Effect.h" -class VSSAO : public Effect { +class SSAO : public Effect { public: - VSSAO(IDirect3DDevice9 *device, int width, int height, unsigned strength); - virtual ~VSSAO(); + enum Type { VSSAO, HBAO, SCAO }; + + SSAO(IDirect3DDevice9 *device, int width, int height, unsigned strength, Type type); + virtual ~SSAO(); void go(IDirect3DTexture9 *frame, IDirect3DTexture9 *depth, IDirect3DSurface9 *dst); diff --git a/Settings.cpp b/Settings.cpp index a51dbeb..71b332d 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -53,6 +53,7 @@ void Settings::init() { if(getCaptureCursor()) WindowManager::get().toggleCursorCapture(); if(getBorderlessFullscreen()) WindowManager::get().toggleBorderlessFullscreen(); + WindowManager::get().resize(NULL, NULL); inited = true; } } diff --git a/Settings.def b/Settings.def index 059987e..47d522f 100644 --- a/Settings.def +++ b/Settings.def @@ -14,10 +14,12 @@ SETTING(unsigned, AAQuality, "aaQuality", 0); SETTING(std::string, AAType, "aaType", "FXAA"); SETTING(unsigned, SsaoStrength, "ssaoStrength", 0); +SETTING(unsigned, SsaoScale, "ssaoScale", 0); +SETTING(std::string, SsaoType, "ssaoType", "VSSAO"); SETTING(bool, UnlockFPS, "unlockFPS", 0); SETTING(unsigned, FPSLimit, "FPSlimit", 30); -SETTING(unsigned, FPSThreshold, "FPSthreshold", 29); +SETTING(unsigned, FPSThreshold, "FPSthreshold", 28); SETTING(bool, EnableTripleBuffering, "enableTripleBuffering", 0); diff --git a/WindowManager.cpp b/WindowManager.cpp index 458a8bf..196cdc4 100644 --- a/WindowManager.cpp +++ b/WindowManager.cpp @@ -36,7 +36,7 @@ void WindowManager::toggleBorderlessFullscreen() { lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU); ::SetWindowLong(hwnd, GWL_STYLE, lStyle); LONG lExStyle = ::GetWindowLong(hwnd, GWL_EXSTYLE); - prevExStyle = prevExStyle; + prevExStyle = lExStyle; lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE); ::SetWindowLong(hwnd, GWL_EXSTYLE, lExStyle); // adjust size & position @@ -60,12 +60,26 @@ void WindowManager::toggleBorderlessFullscreen() { void WindowManager::resize(unsigned clientW, unsigned clientH) { HWND hwnd = ::GetActiveWindow(); - RECT desiredRect; - desiredRect.left = 0; - desiredRect.top = 0; - desiredRect.right = clientW; - desiredRect.bottom = clientH; - LONG lStyle = ::GetWindowLong(hwnd, GWL_STYLE); - ::AdjustWindowRect(&desiredRect, lStyle, false); - ::SetWindowPos(hwnd, NULL, 0, 0, desiredRect.right, desiredRect.bottom, SWP_NOZORDER); + // Store current window rect + ::GetClientRect(hwnd, &prevWindowRect); + // Get monitor size + HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); + MONITORINFO info; + info.cbSize = sizeof(MONITORINFO); + GetMonitorInfo(monitor, &info); + int monitorWidth = info.rcMonitor.right - info.rcMonitor.left; + int monitorHeight = info.rcMonitor.bottom - info.rcMonitor.top; + + // How much do we overlap or are smaller than the actual screen size + int widthDiff = monitorWidth - (clientW ? clientW : prevWindowRect.right); + int heightDiff = monitorHeight - (clientH ? clientH : prevWindowRect.bottom); + + RECT desiredRect; + desiredRect.left = widthDiff / 2; + desiredRect.top = heightDiff / 2; + desiredRect.right = monitorWidth - (widthDiff / 2); + desiredRect.bottom = monitorHeight - (heightDiff / 2); + LONG lStyle = ::GetWindowLong(hwnd, GWL_STYLE); + ::AdjustWindowRect(&desiredRect, lStyle, false); + ::SetWindowPos(hwnd, NULL, desiredRect.left, desiredRect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); } diff --git a/d3d9dev.cpp b/d3d9dev.cpp index e53550a..dc68308 100644 --- a/d3d9dev.cpp +++ b/d3d9dev.cpp @@ -560,21 +560,18 @@ HRESULT APIENTRY hkIDirect3DDevice9::SetRenderState(D3DRENDERSTATETYPE State, DW HRESULT APIENTRY hkIDirect3DDevice9::SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) { SDLOG(14, "SetSamplerState sampler %lu: state type: %s value: %lu\n", Sampler, D3DSamplerStateTypeToString(Type), Value); if(Settings::get().getFilteringOverride() == 2) { - m_pD3Ddev->SetSamplerState(Sampler, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); - m_pD3Ddev->SetSamplerState(Sampler, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC); - m_pD3Ddev->SetSamplerState(Sampler, D3DSAMP_MAXANISOTROPY, 16); SDLOG(10, " - aniso sampling activated!\n"); - if(Type != D3DSAMP_MINFILTER && Type != D3DSAMP_MAGFILTER && Type != D3DSAMP_MAXANISOTROPY) { + if(Type == D3DSAMP_MAXANISOTROPY) { + return m_pD3Ddev->SetSamplerState(Sampler, Type, 16); + } else if(Type != D3DSAMP_MINFILTER && Type != D3DSAMP_MAGFILTER) { return m_pD3Ddev->SetSamplerState(Sampler, Type, Value); } else { - return D3D_OK; + return m_pD3Ddev->SetSamplerState(Sampler, Type, D3DTEXF_ANISOTROPIC); } } else if(Settings::get().getFilteringOverride() == 1) { - if(Type == D3DSAMP_MINFILTER || Type == D3DSAMP_MAGFILTER) { - if(Value == D3DTEXF_POINT) { - SDLOG(10, " - linear override activated!\n"); - return m_pD3Ddev->SetSamplerState(Sampler, Type, D3DTEXF_LINEAR); - } + if((Type == D3DSAMP_MINFILTER || Type == D3DSAMP_MIPFILTER) && (Value == D3DTEXF_POINT || Value == D3DTEXF_NONE)) { + SDLOG(10, " - linear override activated!\n"); + return m_pD3Ddev->SetSamplerState(Sampler, Type, D3DTEXF_LINEAR); } } return m_pD3Ddev->SetSamplerState(Sampler, Type, Value); diff --git a/main.cpp b/main.cpp index e1b45de..67ea422 100644 --- a/main.cpp +++ b/main.cpp @@ -30,7 +30,6 @@ bool WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved) { TCHAR fileName[512]; GetModuleFileName(NULL, fileName, 512); - if(dwReason == DLL_PROCESS_ATTACH) { DisableThreadLibraryCalls(hDll); GetModuleFileName(hDll, dlldir, 512); diff --git a/main.h b/main.h index ab4ebab..732e8c4 100644 --- a/main.h +++ b/main.h @@ -18,7 +18,7 @@ #pragma once -#define VERSION "1.8" +#define VERSION "1.9" #define RELEASE_VER