Dark Souls internal rendering resolution fix (DSfix)

Yes. I still want to fix the issue some people experience with SMAA, but I still couldn't reproduce it :(


It will be in the next version, but if you can't wait you should be able to just replace the contents of VSSAO.fx with this:
Code:
// Volumetric SSAO
// Implemented by Tomerk for OBGE
// Adapted and tweaked for Dark Souls by Durante

/***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.2; //Linearly multiplies the radius of the AO Sampling
extern float aoStrengthMultiplier = 2.0; //Linearly multiplies the strength of the AO
extern float aoClamp = 0.0; //The maximum strength of the AO, 0 is max strength, 1 is weakest
extern float ThicknessModel = 30000.0; //units in space the AO assumes objects' thicknesses are
extern float FOV = 68; //Field of View in Degrees
extern float luminosity_threshold = 0.3;

#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 = 10.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 = <depthTex2D>;
	AddressU = CLAMP;
	AddressV = CLAMP;
	MINFILTER = LINEAR;
	MAGFILTER = LINEAR;
};

sampler frameSampler = sampler_state
{
	texture = <frameTex2D>;
	AddressU = CLAMP;
	AddressV = CLAMP;
	MINFILTER = LINEAR;
	MAGFILTER = LINEAR;
};

sampler passSampler = sampler_state
{
	texture = <prevPassTex2D>;
	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_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);
	float noiseY = (frac(sin(dot(uv, float2(12.9898,78.233))) * 43758.5453));
	return float2(noiseX, noiseY);
}

float readDepth(in float2 coord : TEXCOORD0) {
	float4 col = tex2D(depthSampler, coord);
	float posZ = clamp(((1.0-col.z)/256.0 + (1.0-col.y) + 256.0*(1.0-col.x))/(5.0), 0.0, 1.0);
	//float posZ = ((1.0-col.y) + 256.0*(1.0-col.x))/(5.0);
	return ((2.0f * nearZ) / (nearZ + farZ - posZ * (farZ - nearZ)))*10.0;
	//return posZ / (depthRange - (depthRange - 1.0)*posZ);
	//float posZ = ((1.0-col.y) + 256.0*(1.0-col.x));
	//return posZ;
}

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));
	norm.y *= -1;

	float sample_depth;

	float ao=0;
	float s=0.0;

	float2 rand_vec = rand(IN.UVCoord);
	float2 sample_vec_divisor = g_InvFocalLen*depth*depthRange/(aoRadiusMultiplier*4000*rcpres);
	float2 sample_center = IN.UVCoord + norm.xy/sample_vec_divisor*float2(1,aspect);
	float sample_center_depth = depth*depthRange + norm.z*aoRadiusMultiplier*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]*aoRadiusMultiplier*10;
		float curr_sample_depth = depthRange*readDepth(sample_coords);
		
		ao += clamp(0,curr_sample_radius+sample_center_depth-curr_sample_depth,2*curr_sample_radius);
		ao -= clamp(0,curr_sample_radius+sample_center_depth-curr_sample_depth-ThicknessModel*depth*depth*depth,2*curr_sample_radius);
		s += 2*curr_sample_radius;
	}

	ao /= s;
	
	// adjust for close and far away
	if(depth<0.08) ao = lerp(ao, 0.0, (0.08-depth)*25);
	//if(depth>0.5) ao = lerp(ao, 0.0, (depth-0.5)*10);

	ao = 1.0-ao*aoStrengthMultiplier;
	
	//return float4(depth,depth,depth,1);
	return float4(ao,ao,ao,1);
}


float4 Blur( VSOUT IN ) : COLOR0 {
	float color = tex2D(passSampler, IN.UVCoord).r*4;

	color += tex2D(passSampler, IN.UVCoord + float2(rcpres.x,0)).r*2;
	color += tex2D(passSampler, IN.UVCoord + float2(-rcpres.x,0)).r*2;
	color += tex2D(passSampler, IN.UVCoord + float2(0,rcpres.y)).r*2;
	color += tex2D(passSampler, IN.UVCoord + float2(0,-rcpres.y)).r*2;

	color += tex2D(passSampler, IN.UVCoord + rcpres).r;
	color += tex2D(passSampler, IN.UVCoord - rcpres).r;
	color += tex2D(passSampler, IN.UVCoord + rcpres * float2(1,-1)).r;
	color += tex2D(passSampler, IN.UVCoord - rcpres * float2(1,-1)).r;

	color /= 16;

	return float4(color,1,1,1);
	//return tex2D(passSampler, IN.UVCoord).r;
}


float4 Combine( VSOUT IN ) : COLOR0 {
	float3 color = tex2D(frameSampler, IN.UVCoord).rgb;
	float ao = clamp(tex2D(passSampler, IN.UVCoord/scale).r, 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 *= 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 Blur();
	}
	pass p2
	{
		VertexShader = compile vs_1_1 FrameVS();
		PixelShader = compile ps_2_0 Combine();
	}
}

No support for this!


Works ! No performance hit, no glitches. I love how character get shadow from shield on arm holding that shield. Without your fix now arm looks weird :D

edit: AMD gpu here.

edit2: I noticed that SSAO is visible when you rest by bonfire. When whole screen fills this fog shadows are still there. Very minor problem to me.
 
Same as this question, I never thought I'd miss realtek.
I managed to get it working with VIA audio :D. I did a lot of messing around, so I'm not sure exactly how I fixed it, but this is what I think I did:

- In Vdeck I set my output to 6 channels, with side speakers instead of back ones (not sure if this step actually did anything).
- Uninstalled Vdeck and the VIA audio drivers, then restarted PC.
- Then I just followed the steps here http://www.neogaf.com/forum/showpost.php?p=41642354&postcount=3568. Before it wouldn't work, but after installing and removing the VIA audio drivers it works.
 
Why do i get this? :\

5ZCpa.jpg
 
Fix worked like a charm, put in 1600 x 900 and that's what I got.

Don't know about the rest, but the most important thing is fixed and framerates are steady.

Thanks.
 
If I don't have a sound card and just use headphones for sound, is there a way for me to downsample 5.1 sound to my 2.0 headphones?
 
Ok now i'm having another problem. Everything was fine until i died for the first time, in Undead Berg.

Now the frame rate is unplayable, literally, as it kicks me back to the main menu saying it isn't good enough. Everytime i load the game it is shocking. Tried closing and everything of course.
 
I managed to get it working with VIA audio :D. I did a lot of messing around, so I'm not sure exactly how I fixed it, but this is what I think I did:

- In Vdeck I set my output to 6 channels, with side speakers instead of back ones (not sure if this step actually did anything).
- Uninstalled Vdeck and the VIA audio drivers, then restarted PC.
- Then I just followed the steps here http://www.neogaf.com/forum/showpost.php?p=41642354&postcount=3568. Before it wouldn't work, but after installing and removing the VIA audio drivers it works.

Confirmed that this works!
 
Fuck yeah!

I fixed the SSAO issue! (and without impacting performance)

1.0 (actually, it was even worse than this, but this is the closest I cared to reconstruct):

So is it possible to use your AO & the forced AO in Nv Inspector? I ask because it seems like your AO is applying more to background objects than the forced Inspector AO. I'd like to use them in conjunction. Just asking if you would recommend it ;)
 
I don't have a screenshot right now but this new unrelased SSAO looks really fucking retarded on my character.

I'll take one when I get home.
 
can't believe I am reading you guys not having any slowdown with the new SSAO effect. My 460 2GB GTX chugs to hell if I turn it on.


umm extra features? I have a couple of requests!


1. HUDless video recording! MSI Afterburner is really great but videos with a hud are kinda lame.

2. Disappearing HUD! Without any item switching button input or taking damage/changing status effects, the HUD will fade!
 
So is it possible to use your AO & the forced AO in Nv Inspector? I ask because it seems like your AO is applying more to background objects than the forced Inspector AO. I'd like to use them in conjunction. Just asking if you would recommend it ;)
I really wouldn't suggest it, your whole scene will be too dark. Also, I really think my fixed SSAO is better in every way than the forced one :P

I'm extremely happy with the way the SSAO looks now, both in motion and in stills. I'm pretty hard to please when it comes to graphics, but save for the small bonfire issue I think it's almost perfect. I probably won't change a thing about it.

screenshot_2012-09-086dfmp.jpg


screenshot_2012-09-08o1f8g.jpg


When you play with the effect on for a while and then turn it off everything looks really flat. I particularly love the self-shadowing-like effect on my character (the inside of the boots, behind the arm and arrows or even behind the ear). It's great.
(Note that the difference in colors in the above shots is due to a difference in fog, not the SSAO)
 
can't believe I am reading you guys not having any slowdown with the new SSAO effect. My 460 2GB GTX chugs to hell if I turn it on.


umm extra features? I have a couple of requests!


1. HUDless video recording! MSI Afterburner is really great but videos with a hud are kinda lame.

2. Disappearing HUD! Without any item switching button input or taking damage/changing status effects, the HUD will fade!

Yeah SSAO thru this mod is also pretty slow for me on my GTX 460 OC. Forcing it through Nvidia Inspector gives me a smooth 30 fps at all times with the performance setting.
 
Awesome work.

Did you ever figure out what happened with that sun issue?
Not yet. I know now though that it only happens when the vertical resolution is larger than 720.

I want to add one more tiny graphical feature, then it's just the HUD and that issue left on my personal priority list.

Yeah SSAO thru this mod is also pretty slow for me on my GTX 460 OC. Forcing it through Nvidia Inspector gives me a smooth 30 fps at all times with the performance setting.
To be honest I really only looked at quality and not performance when I tweaked it today. As long as it doesn't dip on my 660 at 2560x1440 I have no way of really noticing performance changes.

But it will most likely always be slower than "performance" driver SSAO, but that's because it also looks better.

And of course I meant "no performance hit" as compared to the previous, buggy and ugly SSAO in 1.0, not overall. If I had invented a way to do SSAO without any performance hit I'd write a paper about it, not a forum post ;)
 
Not yet. I know now though that it only happens when the vertical resolution is larger than 720.

I want to add one more tiny graphical feature, then it's just the HUD and that issue left on my personal priority list.

Thumbs up. Truly some stellar work.
 
Not yet. I know now though that it only happens when the vertical resolution is larger than 720.

I want to add one more tiny graphical feature, then it's just the HUD and that issue left on my personal priority list.

To be honest I really only looked at quality and not performance when I tweaked it today. As long as it doesn't dip on my 660 at 2560x1440 I have no way of really noticing performance changes.

But it will most likely always be slower than "performance" driver SSAO, but that's because it also looks better.

And of course I meant "no performance hit" as compared to the previous, buggy and ugly SSAO in 1.0, not overall. If I had invented a way to do SSAO without any performance hit I'd write a paper about it, not a forum post ;)

God amongmen durante. here to save the day
 
I really wouldn't suggest it, your whole scene will be too dark. Also, I really think my fixed SSAO is better in every way than the forced one :P

I'm extremely happy with the way the SSAO looks now, both in motion and in stills. I'm pretty hard to please when it comes to graphics, but save for the small bonfire issue I think it's almost perfect. I probably won't change a thing about it.

screenshot_2012-09-086dfmp.jpg


screenshot_2012-09-08o1f8g.jpg


When you play with the effect on for a while and then turn it off everything looks really flat. I particularly love the self-shadowing-like effect on my character (the inside of the boots, behind the arm and arrows or even behind the ear). It's great.
(Note that the difference in colors in the above shots is due to a difference in fog, not the SSAO)

The corners look a bit too dark, look like someone just used a soft edged paint brush in photoshop. The grass and all that looks great though.
 
Yeah, it looks fantastic but the corners near the wall could do with a more natural fade or opacity - Seems a bit too black, like a line drawn with a brush. Not sure if it's possible to change it like that or any change would have to be on the entire image.
 
The corners look a bit too dark, look like someone just used a soft edged paint brush in photoshop. The grass and all that looks great though.
Yeah, I realize that some would consider it too dark, but that's an easily tweaked variable that everyone can set to whatever feels right for them.
 
Great work on the SSAO implementation, it really looks amazing (tried it out with the code you posted). One question though, is there any way of extending the area of effect? As someone else posted earlier it seems limited really close to your character and objects at medium+ range have the effect applied to them in an incredibly subtle manner, if it all? Was that a compromise to reduce artifacts in the distance?
 
Great work Durante.

Was anyone able to get SLI to work? I imagine the brute power would help with enabling some of these extra graphic settings and keeping a steady 30 FPS.
 
Great work on the SSAO implementation, it really looks amazing (tried it out with the code you posted). One question though, is there any way of extending the area of effect? As someone else posted earlier it seems limited really close to your character and objects at medium+ range have the effect applied to them in an incredibly subtle manner, if it all? Was that a compromise to reduce artifacts in the distance?
It's something I did because I personally think SSAO in general isn't an effect that looks good on distant objects. It would be relatively easy to change.
 
It's a great enhancement to the overall image, especially with the character and foilage.

But one curious bug I noticed was when using manual targeting with arrows, AO will darken dramatically on those distant objects.

I guess it's due to the comment from Durante above - about him implementing it in a reduced manner on distant objects - and the algorithm doesn't account for the camera switch.

Durante, are you going to let us play with the SSAO variables via the .ini file?
 
Durante, are you going to let us play with the SSAO variables via the .ini file?
I don't really see a reason to implement that, you can just play with them in the VSSAO.fx file. You can even reload the effect without restarting Dark Souls (look into the keybindings file), which is a huge help when tweaking variables!

How would one go about doing that? Is it a parameter that you already have in the code?
It's not as straightforward as that (unlike the strength of the effect, for which there already is a parameter at the top of the file).
 
It's something I did because I personally think SSAO in general isn't an effect that looks good on distant objects. It would be relatively easy to change.

Mmm, well, the option would be cool, but this is fine too! Plus, I feel bad asking for more after everything you've already done, hah.
 
I don't really see a reason to implement that, you can just play with them in the VSSAO.fx file. You can even reload the effect without restarting Dark Souls (look into the keybindings file), which is a huge help when tweaking variables!

It's not as straightforward as that (unlike the strength of the effect, for which there already is a parameter at the top of the file).

Didn't realize you could do that, so that's probably even better! :D
 
It's just a matter of setting these 3 to whatever you fancy in VSSAO.fx:
Code:
extern float aoRadiusMultiplier = 1.2; //Linearly multiplies the radius of the AO Sampling
extern float aoStrengthMultiplier = 2.0; //Linearly multiplies the strength of the AO
extern float aoClamp = 0.0; //The maximum strength of the AO, 0 is max strength, 1 is weakest

E.g. if you think it's too strong try going with aoStrengthMultiplier = 1.0 and aoClamp = 0.3 for a start.


(if you find something you like then tell me the settings, I might include a "weak", "medium" and "strong" preset for the SSAO in the real release)
 
Does the autosave function create the screenshots in the game directory? If so, can you prevent it from doing that? Not too much room on my SSD.
 
Does the autosave function create the screenshots in the game directory? If so, can you prevent it from doing that? Not too much room on my SSD.
No, it doesn't. The default screenshot key is now page down, could it be that you pressed it accidentally?

(If so, I think I'll disable all the key bindings by default in the next version, if someone wants them they should enable them, it's causing too many issues)
 
No, it doesn't. The default screenshot key is now page down, could it be that you pressed it accidentally?

(If so, I think I'll disable all the key bindings by default in the next version, if someone wants them they should enable them, it's causing too many issues)

Was it something else before 1.0? I was using 0.9 up until just now. I don't think I've been hitting PgDn but had about 20 screenshots in my folder.
 
It's just a matter of setting these 3 to whatever you fancy in VSSAO.fx:
Code:
extern float aoRadiusMultiplier = 1.2; //Linearly multiplies the radius of the AO Sampling
extern float aoStrengthMultiplier = 2.0; //Linearly multiplies the strength of the AO
extern float aoClamp = 0.0; //The maximum strength of the AO, 0 is max strength, 1 is weakest

E.g. if you think it's too strong try going with aoStrengthMultiplier = 1.0 and aoClamp = 0.3 for a start.


(if you find something you like then tell me the settings, I might include a "weak", "medium" and "strong" preset for the SSAO in the real release)

I'm using these and the shadows look better now when I'm not wearing armor:
extern float aoStrengthMultiplier = 1.0;
extern float aoClamp = 0.5;

The effect is obviously diminished somewhat but still noticeable.
 
Top Bottom