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

Commit

Permalink
Physics and shaders
Browse files Browse the repository at this point in the history
Resolves #13. Resolves #16. Resolves #23. Resolves #27.
  • Loading branch information
fonsp committed Dec 14, 2014
1 parent 3120ded commit b49bc63
Show file tree
Hide file tree
Showing 31 changed files with 772 additions and 406 deletions.
58 changes: 58 additions & 0 deletions GraphicsEngine/Content/shaders/blur.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#version 120
uniform float worldTime;
uniform sampler2D tex;
uniform sampler2D depthTex;

uniform float focalDist;

float asdf = 0.0;

void main()
{
float dx = 2.0 / 1280.0;
float dy = 2.0 / 0720.0;

float depth = texture2D(depthTex, gl_TexCoord[0].xy).x;
float n = 1.0; // camera z near
float f = 100000.0; // camera z far
depth = 2000.0 * (2.0 * n) / (f + n - depth * (f - n));


float focalDist2 = 2000.0 * (2.0 * n) / (f + n - focalDist * (f - n));

depth = abs(1.0 - sqrt(depth / focalDist2));
depth = clamp(depth, 0.0, 1.0);
vec4 sum = vec4(0.0);
if(depth >= 0.5)
{
float[] pascal = float[7](1.0, 6.0, 15.0, 20.0, 15.0, 6.0, 1.0);

for(int x = 0; x < 7; x++)
{
for(int y = 0; y < 7; y++)
{
sum = sum + texture2D(tex, gl_TexCoord[0].xy + vec2((x - 3) * dx, (y - 3) * dy)) * pascal[x] * pascal[y];
}
}
sum = sum / 4096.0;
//sum.r = 1.0;
depth = 1.0;
} else {
float[] pascal = float[5](1.0, 4.0, 6.0, 4.0, 1.0);

for(int x = 0; x < 5; x++)
{
for(int y = 0; y < 5; y++)
{
sum = sum + texture2D(tex, gl_TexCoord[0].xy + vec2((x - 2) * dx, (y - 2) * dy)) * pascal[x] * pascal[y];
}
}
sum = sum / 256.0;
//sum.g = 1.0;
depth = depth * 2;
}

vec4 diff = texture2D(tex, gl_TexCoord[0].xy);
//diff.b = 1.0;
gl_FragColor = sum * depth + diff * (1.0 - depth);
}
9 changes: 9 additions & 0 deletions GraphicsEngine/Content/shaders/blur.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 120
uniform float worldTime;

void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
13 changes: 13 additions & 0 deletions GraphicsEngine/Content/shaders/collision.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 120
uniform float worldTime;
uniform int effects;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
uniform sampler2D tex;

void main()
{
gl_FragColor = vec4(0.5, 0.0, 0.0, 0.05);
}
14 changes: 14 additions & 0 deletions GraphicsEngine/Content/shaders/collision.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#version 120
uniform float worldTime;
uniform int effects;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;

void main()
{
vec4 v = gl_Vertex;
v.xyz = v.xyz - cpos;
gl_Position = gl_ProjectionMatrix * (crot * (gl_ModelViewMatrix * v));
}
18 changes: 18 additions & 0 deletions GraphicsEngine/Content/shaders/crt.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#version 120
uniform float worldTime;
uniform sampler2D tex;

void main()
{
/*vec2 rCoord = (gl_TexCoord[0].xy - vec2(0.5, 0.5)) * 0.995 + vec2(0.5, 0.5);
float r = texture2D(tex, rCoord).r;
float g = texture2D(tex, gl_TexCoord[0].xy).g;
float b = texture2D(tex, gl_TexCoord[0].xy).b;
gl_FragColor = vec4(r, g, b, 1.0); chromatic aberration*/
/*gl_FragColor = vec4(texture2D(tex, gl_TexCoord[0].xy).xyz - texture2D(tex, gl_TexCoord[0].xy + vec2(1.0/1280.0, 1.0/720.0)).xyz, 1.0); diff*/
float r = texture2D(tex, (gl_TexCoord[0].xy - vec2(0.5, 0.5)) * 0.992 + vec2(0.5, 0.5)).r;
float g = texture2D(tex, gl_TexCoord[0].xy).g;
float b = texture2D(tex, (gl_TexCoord[0].xy - vec2(0.5, 0.5)) * 0.998 + vec2(0.5, 0.5)).b;
gl_FragColor = vec4(vec3(r, g, b) * (mod(int(gl_FragCoord.y), 2) + 1.0) * 0.5, 1.0);
}
9 changes: 9 additions & 0 deletions GraphicsEngine/Content/shaders/crt.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 120
uniform float worldTime;

void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
28 changes: 28 additions & 0 deletions GraphicsEngine/Content/shaders/depth.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
uniform float worldTime;
uniform int effects;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
uniform sampler2D tex;
varying float dopp;

void main()
{
vec4 output = texture2D(tex, gl_TexCoord[0].xy) * vec4(vec3(gl_Color.w), 1.0);
if((effects / 2) % 2 == 1)
{
output = output * vec4(vec3(0.5 + dopp / 2.0), 1.0);
}
if((effects / 4) % 2 == 1)
{
vec4 shift = vec4(1.0);
shift.r = 2 * max(0, 0.5 - abs(dopp + 0.0)) + 2 * max(0, 0.5 - abs(dopp + 0.5)) + 2 * max(0, 0.5 - abs(dopp + 1.0));
shift.g = 2 * max(0, 0.5 - abs(dopp - 0.5)) + 2 * max(0, 0.5 - abs(dopp + 0.0)) + 2 * max(0, 0.5 - abs(dopp + 0.5));
shift.b = 2 * max(0, 0.5 - abs(dopp - 1.0)) + 2 * max(0, 0.5 - abs(dopp - 0.5)) + 2 * max(0, 0.5 - abs(dopp + 0.0));
output = output * shift;
}
gl_FragColor = output;
}
31 changes: 31 additions & 0 deletions GraphicsEngine/Content/shaders/depth.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
uniform float worldTime;
uniform int effects;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
varying float dopp;

void main()
{
vec4 v = gl_Vertex;
v.xyz = v.xyz - cpos;
v = gl_ModelViewMatrix * v;
dopp = 0.0;
if(b > 0)
{
dopp = dot(v.xyz, vdir) * b / length(v.xyz);
if((effects / 1) % 2 == 1)
{
float oldlength = length(v.xyz);
v.xyz = v.xyz + vdir * b * length(v.xyz);
v.xyz = v.xyz * (oldlength / length(v.xyz));
}
}
v = crot * v;
gl_Position = gl_ProjectionMatrix * v;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_FrontColor = vec4(gl_Color.xyz, 1.0 / (gl_Position.w / 2000.0 + 1.0));
}
35 changes: 35 additions & 0 deletions GraphicsEngine/Content/shaders/diffuse.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable

uniform float worldTime;
uniform int effects;
uniform float bL;
uniform float bW;
uniform vec3 vdirL;
uniform vec3 vdirW;
uniform vec3 cpos;
uniform mat4 crot;
varying float dopp;
uniform sampler2D tex;

varying float intensity;

void main()
{
float a = sqrt(intensity);

vec4 output = texture2D(tex, gl_TexCoord[0].xy) * vec4(vec3(gl_Color.w), 1.0) * (vec4(a, a, a, 1.0) * gl_LightSource[0].diffuse + vec4(1.0-a, 1.0-a, 1.0-a, 1.0) * gl_LightSource[0].ambient);
if((effects / 2) % 2 == 1)
{
output = output * vec4(vec3(1.0 + dopp), 1.0);
}
if((effects / 4) % 2 == 1)
{
vec4 shift = vec4(1.0);
shift.r = 2 * max(0, 0.5 - abs(dopp + 0.0)) * output.r + 2 * max(0, 0.5 - abs(dopp + 0.5)) * output.g + 2 * max(0, 0.5 - abs(dopp + 1.0)) * output.b;
shift.g = 2 * max(0, 0.5 - abs(dopp - 0.5)) * output.r + 2 * max(0, 0.5 - abs(dopp + 0.0)) * output.g + 2 * max(0, 0.5 - abs(dopp + 0.5)) * output.b;
shift.b = 2 * max(0, 0.5 - abs(dopp - 1.0)) * output.r + 2 * max(0, 0.5 - abs(dopp - 0.5)) * output.g + 2 * max(0, 0.5 - abs(dopp + 0.0)) * output.b;
output = shift;
}
gl_FragColor = output;
}
38 changes: 38 additions & 0 deletions GraphicsEngine/Content/shaders/diffuse.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable

uniform float worldTime;
uniform int effects;
uniform float bL;
uniform float bW;
uniform vec3 vdirL;
uniform vec3 vdirW;
uniform vec3 cpos;
uniform mat4 crot;
varying float dopp;

varying float intensity;

void main()
{
intensity = (dot(gl_LightSource[0].position.xyz, gl_Normal)+1.0)/2.0;

vec4 v = gl_Vertex;
v.xyz = v.xyz - cpos;
v = gl_ModelViewMatrix * v;
dopp = dot(v.xyz, vdirL) * bL / length(v.xyz);;
if(bW > 0)
{
if((effects / 1) % 2 == 1)
{
float oldlength = length(v.xyz);
v.xyz = v.xyz + vdirW * bW * length(v.xyz);
v.xyz = v.xyz * (oldlength / length(v.xyz));
}
}
v = crot * v;
gl_Position = gl_ProjectionMatrix * v;

gl_FrontColor = vec4(gl_Color.xyz, 1.0 / (gl_Position.w / 2000.0 + 1.0));
gl_TexCoord[0] = gl_MultiTexCoord0;
}
13 changes: 13 additions & 0 deletions GraphicsEngine/Content/shaders/dither.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 120
uniform float worldTime;
uniform sampler2D tex;
uniform sampler2D ditherTex;

void main()
{
float r = int(texture2D(ditherTex, gl_FragCoord.xy / 4).r < texture2D(tex, gl_TexCoord[0].xy).r);
float g = int(texture2D(ditherTex, gl_FragCoord.xy / 4).r < texture2D(tex, gl_TexCoord[0].xy).g);
float b = int(texture2D(ditherTex, gl_FragCoord.xy / 4).r < texture2D(tex, gl_TexCoord[0].xy).b);

gl_FragColor = vec4(r, g, b, 1.0);
}
9 changes: 9 additions & 0 deletions GraphicsEngine/Content/shaders/dither.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 120
uniform float worldTime;

void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
8 changes: 8 additions & 0 deletions GraphicsEngine/Content/shaders/hud.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 120
uniform float worldTime;
uniform sampler2D tex;

void main()
{
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy) * gl_Color;
}
9 changes: 9 additions & 0 deletions GraphicsEngine/Content/shaders/hud.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 120
uniform float worldTime;

void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
58 changes: 58 additions & 0 deletions GraphicsEngine/Content/shaders/ssao.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#version 120
uniform float worldTime;
uniform sampler2D tex;
uniform sampler2D depthTex;

uniform float focalDist;

float asdf = 0.0;

void main()
{
float dx = 2.0 / 1280.0;
float dy = 2.0 / 0720.0;

float depth = texture2D(depthTex, gl_TexCoord[0].xy).x;
float n = 1.0; // camera z near
float f = 100000.0; // camera z far
depth = 2000.0 * (2.0 * n) / (f + n - depth * (f - n));


float focalDist2 = 2000.0 * (2.0 * n) / (f + n - focalDist * (f - n));

depth = abs(1.0 - sqrt(depth / focalDist2));
depth = clamp(depth, 0.0, 1.0);
vec4 sum = vec4(0.0);
if(depth >= 0.5)
{
float[] pascal = float[7](1.0, 6.0, 15.0, 20.0, 15.0, 6.0, 1.0);

for(int x = 0; x < 7; x++)
{
for(int y = 0; y < 7; y++)
{
sum = sum + texture2D(tex, gl_TexCoord[0].xy + vec2((x - 3) * dx, (y - 3) * dy)) * pascal[x] * pascal[y];
}
}
sum = sum / 4096.0;
//sum.r = 1.0;
depth = 1.0;
} else {
float[] pascal = float[5](1.0, 4.0, 6.0, 4.0, 1.0);

for(int x = 0; x < 5; x++)
{
for(int y = 0; y < 5; y++)
{
sum = sum + texture2D(tex, gl_TexCoord[0].xy + vec2((x - 2) * dx, (y - 2) * dy)) * pascal[x] * pascal[y];
}
}
sum = sum / 256.0;
//sum.g = 1.0;
depth = depth * 2;
}

vec4 diff = texture2D(tex, gl_TexCoord[0].xy);
//diff.b = 1.0;
gl_FragColor = sum * depth + diff * (1.0 - depth) + vec4(0.2, 0.0, 0.0, 0.0);
}
9 changes: 9 additions & 0 deletions GraphicsEngine/Content/shaders/ssao.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 120
uniform float worldTime;

void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
Loading

0 comments on commit b49bc63

Please sign in to comment.