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

Commit

Permalink
Aberration and partial Doppler effect
Browse files Browse the repository at this point in the history
Updated the Depth shader to include these effects.
  • Loading branch information
fonsp committed Oct 27, 2014
1 parent 095a79e commit 5ecdb59
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 21 deletions.
3 changes: 2 additions & 1 deletion GraphicsEngine/Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void Reload()

string file = File.ReadAllText(fileName);

string[] fileSplit0 = file.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] fileSplit0 = file.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

foreach(string line in fileSplit0)
{
Expand All @@ -80,6 +80,7 @@ public void Reload()
//Comment
break;
case "":
case null:
//Empty line
break;
case "bool":
Expand Down
1 change: 0 additions & 1 deletion GraphicsEngine/Core/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public override void Render(int pass)

if(mesh.useVBO && mesh.hasVBO)
{
//Console.WriteLine("Rendering {0} using VBO", this.name);
GL.EnableClientState(ArrayCap.TextureCoordArray);
GL.EnableClientState(ArrayCap.NormalArray);
GL.EnableClientState(ArrayCap.VertexArray);
Expand Down
98 changes: 90 additions & 8 deletions GraphicsEngine/Core/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,39 @@ public static Shader diffuseShader
vertexShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
varying float intensity;
void main()
{
intensity = (dot(gl_LightSource[0].position.xyz, gl_Normal)+1.0)/2.0;
/*vec4 v = gl_ModelViewMatrix * gl_Vertex;
v.z = sin(0.02 * v.x + time) * 20.0 + v.z;
gl_Position = gl_ProjectionMatrix * v;*/
gl_Position = ftransform();
vec4 v = gl_Vertex;
v.xyz = v.xyz - cpos;
v = gl_ModelViewMatrix * v;
if(b > 0)
{
v.xyz = v.xyz + vdir * b * 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;
}",
fragmentShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
uniform sampler2D tex;
varying float intensity;
void main()
Expand Down Expand Up @@ -178,6 +193,10 @@ public static Shader unlitShader
vertexShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
void main()
{
Expand All @@ -188,6 +207,10 @@ void main()
fragmentShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
uniform sampler2D tex;
void main()
Expand Down Expand Up @@ -224,21 +247,46 @@ public static Shader depthShader
vertexShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
varying float dopp;
void main()
{
gl_Position = ftransform();
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);
v.xyz = v.xyz + vdir * b * 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));
}",
fragmentShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
uniform sampler2D tex;
varying float dopp;
void main()
{
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy) * vec4(gl_Color.xyz, 1.0) * vec4(vec3(gl_Color.w), 1.0);
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));
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy) * vec4(vec3(0.5 + dopp / 2.0), 1.0) * vec4(vec3(gl_Color.w), 1.0) * shift;
}"
};
}
Expand Down Expand Up @@ -270,16 +318,26 @@ public static Shader wireframeShader
vertexShader = @"
#version 120
uniform float time;
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));
gl_FrontColor = gl_Color;
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}",
fragmentShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
uniform sampler2D tex;
void main()
Expand Down Expand Up @@ -316,14 +374,24 @@ public static Shader collisionShader
vertexShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
void main()
{
gl_Position = ftransform();
vec4 v = gl_Vertex;
v.xyz = v.xyz - cpos;
gl_Position = gl_ProjectionMatrix * (crot * (gl_ModelViewMatrix * v));
}",
fragmentShader = @"
#version 120
uniform float time;
uniform float b;
uniform vec3 vdir;
uniform vec3 cpos;
uniform mat4 crot;
uniform sampler2D tex;
void main()
Expand Down Expand Up @@ -496,6 +564,20 @@ public void SetUniform(string name, Vector4 value)
}
GL.Uniform4(uniforms[name], value);
}

public void SetUniform(string name, Matrix4 value)
{
if(!compiled)
{
return;
}
GL.UseProgram(sp);
if(!uniforms.ContainsKey(name))
{
uniforms.Add(name, GL.GetUniformLocation(sp, name));
}
GL.UniformMatrix4(uniforms[name], false, ref value);
}
#endregion
}
}
23 changes: 17 additions & 6 deletions GraphicsEngine/GraphicsProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,35 @@ public GraphicsProgram(string[] arguments, bool enableLogging, string logFilenam
}
}
Debug.WriteLine("---------------");
Debug.WriteLine("A game by Fons van der Plas");
Debug.WriteLine("ReSim - Relativity Simulator");
Debug.WriteLine("---------------");
Debug.WriteLine("Copyright 2013 Fons van der Plas");
Debug.WriteLine("Fons van der Plas, fonsvdplas@gmail.com");
Debug.WriteLine("Created by:");
Debug.WriteLine("Fons van der Plas (fons-), fonsvdplas@gmail.com");
Debug.WriteLine("Just Verlinden (Mhilez), justverlinden@gmail.com");
Debug.WriteLine("---------------");
Debug.WriteLine("https://github.com/fons-/resim");
Debug.WriteLine("---------------");
Debug.WriteLine("Program launched at " + DateTime.Now);
Debug.Write("Received arguments: ");
foreach(string s in programArguments)
int i;
for(i = 0; i < programArguments.Length - 1; i++)
{
Debug.Write(programArguments[i] + ", ");
}
if(programArguments.Length == 0)
{
Debug.Write(s + ", ");
Debug.Write("none");
}
else
{
Debug.Write(programArguments[0]);
}
Debug.WriteLine("");
}

public virtual void LoadResources()
{


}

public virtual void InitGame()
Expand Down
2 changes: 1 addition & 1 deletion GraphicsEngine/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("GraphicsLibrary")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
47 changes: 44 additions & 3 deletions GraphicsEngine/RenderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public static RenderWindow Instance
public bool escapeOnEscape = true;
private readonly GameTimer updateSw = new GameTimer();
private float _time = 0f;
public float c = 2000f;
public float v = 0f;
public float b = 0f;
public float lf = 1f;
public float time { get { return _time; } }
public bool enableVelocity = true;
protected double timeSinceLastUpdate = 0;
Expand Down Expand Up @@ -227,7 +231,7 @@ protected override void OnUpdateFrame(FrameEventArgs e)
}
#endif
timeSinceLastUpdate = e.Time * timeMultiplier;
_time += (float) timeSinceLastUpdate;
_time += (float)timeSinceLastUpdate;

program.Update((float)timeSinceLastUpdate);
if(enableVelocity)
Expand Down Expand Up @@ -258,14 +262,51 @@ protected override void OnRenderFrame(FrameEventArgs e)
UpdateViewport();


Matrix4 modelview = Matrix4.LookAt(Camera.Instance.position, Camera.Instance.position - Vector3.UnitZ, Vector3.UnitY) * Matrix4.Rotate(Camera.Instance.derivedOrientation);
Matrix4 modelview = /*Matrix4.LookAt(Vector3.Zero, Vector3.Zero-Vector3.UnitZ, Vector3.UnitY) * */Matrix4.CreateFromQuaternion(Camera.Instance.derivedOrientation);

GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelview);

//GL.LoadMatrix(ref modelview);
GL.LoadIdentity();

//Update shaders
Shader.diffuseShaderCompiled.SetUniform("time", _time);
Shader.unlitShaderCompiled.SetUniform("time", _time);
Shader.depthShaderCompiled.SetUniform("time", _time);
Shader.wireframeShaderCompiled.SetUniform("time", _time);
Shader.collisionShaderCompiled.SetUniform("time", _time);

v = Camera.Instance.velocity.Length;
b = v / c;
lf = 1f / (float)Math.Sqrt(1.0 - b);

Shader.diffuseShaderCompiled.SetUniform("b", b);
Shader.unlitShaderCompiled.SetUniform("b", b);
Shader.depthShaderCompiled.SetUniform("b", b);
Shader.wireframeShaderCompiled.SetUniform("b", b);
Shader.collisionShaderCompiled.SetUniform("b", b);

Vector3 vDir = Camera.Instance.velocity.Normalized();

Shader.diffuseShaderCompiled.SetUniform("vdir", vDir);
Shader.unlitShaderCompiled.SetUniform("vdir", vDir);
Shader.depthShaderCompiled.SetUniform("vdir", vDir);
Shader.wireframeShaderCompiled.SetUniform("vdir", vDir);
Shader.collisionShaderCompiled.SetUniform("vdir", vDir);

Shader.diffuseShaderCompiled.SetUniform("cpos", Camera.Instance.position);
Shader.unlitShaderCompiled.SetUniform("cpos", Camera.Instance.position);
Shader.depthShaderCompiled.SetUniform("cpos", Camera.Instance.position);
Shader.wireframeShaderCompiled.SetUniform("cpos", Camera.Instance.position);
Shader.collisionShaderCompiled.SetUniform("cpos", Camera.Instance.position);

Matrix4 cRot = Matrix4.CreateFromQuaternion(Camera.Instance.derivedOrientation);

Shader.diffuseShaderCompiled.SetUniform("crot", cRot);
Shader.unlitShaderCompiled.SetUniform("crot", cRot);
Shader.depthShaderCompiled.SetUniform("crot", cRot);
Shader.wireframeShaderCompiled.SetUniform("crot", cRot);
Shader.collisionShaderCompiled.SetUniform("crot", cRot);

for(int i = 0; i < amountOfRenderPasses; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion Resim/Game.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

; Player
int walkingSpeed 3500
int runningSpeed 7500
int runningSpeed 10000
int jumpForce 0600
int walkHeight 170
int crouchHeight 90
Expand Down
7 changes: 7 additions & 0 deletions Resim/Program/InitGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public partial class Game

public override void InitGame()
{
#region Program arguments

//TODO: Program arguments

#endregion
#region Entities

skybox.mesh.material.textureName = "skybox";
skybox.isLit = false;
float size = Camera.Instance.ZFar / 1.8f;//Sqrt(3)
Expand Down Expand Up @@ -117,6 +123,7 @@ public override void InitGame()
map.Add(map0d);
map.Add(map0e);*/
map.Add(map1);

#endregion

Camera.Instance.position = new Vector3(2700, 300, -6075);
Expand Down
Loading

0 comments on commit 5ecdb59

Please sign in to comment.