Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
Depth of field and code cleanup
Browse files Browse the repository at this point in the history
Resolves #19. Added depth of field using render-to-texture shaders.
  • Loading branch information
fonsp committed Nov 10, 2014
1 parent 7e45657 commit 534fe50
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 1,762 deletions.
4 changes: 2 additions & 2 deletions GraphicsEngine/Content/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ static TextureManager()
try
{
mTexCache = new Dictionary<string, int>();
GL.Enable(EnableCap.Texture2D);
//GL.Enable(EnableCap.Texture2D);
}
catch(Exception exception)
{
Debug.WriteLine("WARNING: TextureManager could not be created: {0}", exception.Message);
Debug.WriteLine("WARNING: TextureManager could not be created: " + exception.Message + " @ " + exception.Source);
}
}

Expand Down
18 changes: 17 additions & 1 deletion GraphicsEngine/Core/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ void main()
#version 120
uniform float time;
uniform sampler2D tex;
uniform sampler2D depthTex;
uniform float focalDist;
float asdf = 0.0;
void main()
{
Expand All @@ -504,7 +508,7 @@ void main()
texture2D(tex, gl_TexCoord[0].xy + vec2(01.0 * dx, 0)) * 4.0 +
texture2D(tex, gl_TexCoord[0].xy + vec2(02.0 * dx, 0)) * 1.0
) / 16.0;*/
float[] pascal = float[](1.0, 6.0, 15.0, 20.0, 15.0, 6.0, 1.0);
float[] pascal = float[7](1.0, 6.0, 15.0, 20.0, 15.0, 6.0, 1.0);
vec4 sum = vec4(0.0);
for(int x = 0; x < 7; x++)
{
Expand All @@ -515,6 +519,18 @@ void main()
}
sum = sum / 4096.0;
gl_FragColor = sum;
float depth = texture2D(depthTex, gl_TexCoord[0].xy).x;
float n = 1.0; // camera z near
float f = 100000.0; // camera z far
depth = 60.0 * (2.0 * n) / (f + n - depth * (f - n));
float focalDist2 = texture2D(depthTex, vec2(0.5, 0.5)).x;
focalDist2 = 60.0 * (2.0 * n) / (f + n - focalDist2 * (f - n));
depth = abs(1.0 - depth / focalDist2);
depth = clamp(depth, 0.0, 1.0);
gl_FragColor = sum * depth + texture2D(tex, gl_TexCoord[0].xy) * (1.0 - depth);
//gl_FragColor = vec4(vec3(depth), 1.0);
}"
};
}
Expand Down
2 changes: 1 addition & 1 deletion GraphicsEngine/GraphicsProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public GraphicsProgram(string[] arguments, bool enableLogging, string logFilenam
}
catch(Exception exception)
{
Debug.WriteLine("Failed to create log file. Make sure you have admin rights and close all processes using this file: {0}", exception.Message);
Debug.WriteLine("WARNING: Failed to create log file. Make sure you have admin rights and close all processes using this file: " + exception.Message + " @ " + exception.Source);
}
}
Debug.WriteLine("---------------");
Expand Down
Loading

0 comments on commit 534fe50

Please sign in to comment.