Skip to content

Commit

Permalink
Reached 1 mill spheres, implimented static ISpheres, fixed triangle b…
Browse files Browse the repository at this point in the history
…atching.
  • Loading branch information
fredrickbancan committed Oct 28, 2020
1 parent 2c98d6b commit 1252229
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 160 deletions.
Binary file added DevScreenshots/36.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion RabbetGameEngine/RabbetGameEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<None Include="Res\Shaders\VFX\LerpISpheres_FT.shader" />
<None Include="Res\Shaders\VFX\LerpISpheres_F.shader" />
<Compile Include="Src\Game\CustomColor.cs" />
<Compile Include="Src\Game\Debugging\HitboxRenderer.cs" />
<Compile Include="Src\Rendering\SubRendering\HitboxRenderer.cs" />
<Compile Include="Src\Game\GUIS\MainGUI.cs" />
<Compile Include="Src\Game\MathUtil.cs" />
<Compile Include="Src\Game\TickTimer.cs" />
Expand Down
4 changes: 3 additions & 1 deletion RabbetGameEngine/Res/Shaders/GUI/GuiText.shader
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void main()

#shader fragment
#version 330 core
#extension GL_ARB_conservative_depth : enable
layout(depth_less) out float gl_FragDepth;
out vec4 color;
in vec4 vColor;
in vec2 fTexCoord;
Expand All @@ -25,7 +27,7 @@ uniform sampler2D uTexture;

void main()
{
gl_FragDepth = -1;//render on top
gl_FragDepth = 0;//render on top
color = texture(uTexture, fTexCoord) * vColor;
if (color.a < 0.01)
{
Expand Down
4 changes: 3 additions & 1 deletion RabbetGameEngine/Res/Shaders/Planet/Skybox.shader
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void main()
//Out variables from vertex shader are passed into the fragment shaders in variables, part of glsl language.
#shader fragment
#version 330 core
#extension GL_ARB_conservative_depth : enable
layout(depth_greater) out float gl_FragDepth;
out vec4 color;
in vec4 worldSpacePos;

Expand All @@ -36,7 +38,7 @@ uniform vec3 skyHorizon;

void main()
{
gl_FragDepth = 0.9999F;//force fragdepth to be in background at all times
gl_FragDepth = 0.9999999F;//force fragdepth to be in background at all times
vec3 pointOnSphere = normalize(worldSpacePos.xyz);//normalizing the position of the frag to form a spherical depth from the camera, leaving out the w coordinate

color.rgb = mix(skyHorizon, skyTop, clamp(pointOnSphere.y, 0, 1));
Expand Down
7 changes: 5 additions & 2 deletions RabbetGameEngine/Res/Shaders/VFX/LerpISpheres_F.shader
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ void makeSphere()
////Set the depth based on the new cameraPos.
vec4 clipPos = projectionMatrix * viewMatrix * vec4(cameraPos, 1.0);
float ndcDepth = clipPos.z / clipPos.w;
gl_FragDepth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;

/*gl_FragDepth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;
if (gl_FragDepth < 0.0000001)
{
discard;
}*/
//calc ambient occlusion for circle
if (bool(fAoc))
ambientOcclusion = sqrt(1.0F - d / 2);
Expand Down
7 changes: 5 additions & 2 deletions RabbetGameEngine/Res/Shaders/VFX/LerpISpheres_FT.shader
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ void makeSphere()
////Set the depth based on the new cameraPos.
vec4 clipPos = projectionMatrix * viewMatrix * vec4(cameraPos, 1.0);
float ndcDepth = clipPos.z / clipPos.w;
gl_FragDepth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;

/*gl_FragDepth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;
if (gl_FragDepth < 0.0000001)
{
discard;
}*/
//calc ambient occlusion for circle
if (bool(fAoc))
ambientOcclusion = sqrt(1.0F - d / 2);
Expand Down
7 changes: 5 additions & 2 deletions RabbetGameEngine/Res/Shaders/VFX/StaticISpheres_F.shader
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ layout(location = 0) in vec4 position;
layout(location = 1) in vec4 pointColor;
layout(location = 2) in float radius;
layout(location = 3) in float aoc;
layout(location = 8) in vec2 corner;//instanced quad corner
layout(location = 4) in vec2 corner;//instanced quad corner

uniform float fogDensity = 0.0075;
const float fogGradient = 2.5;
Expand Down Expand Up @@ -115,7 +115,10 @@ void makeSphere()
vec4 clipPos = projectionMatrix * viewMatrix * vec4(cameraPos, 1.0);
float ndcDepth = clipPos.z / clipPos.w;
gl_FragDepth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;

if (gl_FragDepth < 0.0000001)
{
discard;
}
//calc ambient occlusion for circle
if (bool(fAoc))
ambientOcclusion = sqrt(1.0F - d / 2);
Expand Down
7 changes: 5 additions & 2 deletions RabbetGameEngine/Res/Shaders/VFX/StaticISpheres_FT.shader
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ layout(location = 0) in vec4 position;
layout(location = 1) in vec4 pointColor;
layout(location = 2) in float radius;
layout(location = 3) in float aoc;
layout(location = 8) in vec2 corner;//instanced quad corner
layout(location = 4) in vec2 corner;//instanced quad corner

uniform float fogDensity = 0.0075;
const float fogGradient = 2.5;
Expand Down Expand Up @@ -115,7 +115,10 @@ void makeSphere()
vec4 clipPos = projectionMatrix * viewMatrix * vec4(cameraPos, 1.0);
float ndcDepth = clipPos.z / clipPos.w;
gl_FragDepth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;

if (gl_FragDepth < 0.0000001)
{
discard;
}
//calc ambient occlusion for circle
if (bool(fAoc))
ambientOcclusion = sqrt(1.0F - d / 2);
Expand Down
7 changes: 3 additions & 4 deletions RabbetGameEngine/Src/Game/GameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void OnLoad(EventArgs e)
}
currentPlanet.spawnEntityInWorld(thePlayer);

VFXUtil.doDebugVoxels(currentPlanet);
VFXUtil.createDebugVoxels();
//center mouse in preperation for first person
Input.centerMouse();
Input.toggleHideMouse();
Expand Down Expand Up @@ -110,10 +110,9 @@ private void onTick()
Renderer.onTickStart();
GUIManager.onTick();
MainGUI.onTick();
// VFXUtil.doDebugSmokeEffect(currentPlanet);
//VFXUtil.doDebugSmokeEffect(currentPlanet);
VFXUtil.doDebugVoxels();
currentPlanet.onTick();
//testing point collider drawing
HitboxRenderer.addPointToBeRendered(new Physics.PointCollider(new Vector3(0,2,15)));
Profiler.updateAverages();
Renderer.onTickEnd();
Profiler.beginEndProfile("Loop");
Expand Down
30 changes: 10 additions & 20 deletions RabbetGameEngine/Src/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using RabbetGameEngine.SubRendering;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace RabbetGameEngine
{
Expand Down Expand Up @@ -74,17 +75,17 @@ public static void requestRender(BatchType type, Texture tex, Model mod)
Profiler.beginEndProfile("batching");
}

public static void requestRender(PointCloudModel mod, bool transparency)
public static void requestRender(PointCloudModel mod, bool transparency, bool lerp)
{
Profiler.beginEndProfile("batching");
BatchManager.requestRender(mod, transparency);
BatchManager.requestRender(mod, transparency, lerp);
Profiler.beginEndProfile("batching");
}

public static void requestRender(PointParticle point, bool transparency)
public static void requestRender(PointParticle point, bool transparency, bool lerp)
{
Profiler.beginEndProfile("batching");
BatchManager.requestRender(point, transparency);
BatchManager.requestRender(point, transparency, lerp);
Profiler.beginEndProfile("batching");
}

Expand Down Expand Up @@ -173,26 +174,15 @@ public static void addStaticDrawLines(string name, string textureName, Model dat
staticDraws.Add(name, StaticRenderObject.createSROLines(textureName, ShaderUtil.linesName, data));
}

public static void addStaticDrawPoints(string name, string shaderName, PointCloudModel data)
public static void addStaticDrawPoints(string name, PointParticle[] data, bool transparency)
{
if (staticDraws.TryGetValue(name, out StaticRenderObject s))
{
s.delete();
staticDraws.Remove(name);
}
staticDraws.Add(name, StaticRenderObject.createSROPoints(shaderName, data));
staticDraws.Add(name, StaticRenderObject.createSROPoints(data, transparency));
}

public static void addStaticDrawPoints(string name, PointCloudModel data)
{
if (staticDraws.TryGetValue(name, out StaticRenderObject s))
{
s.delete();
staticDraws.Remove(name);
}
staticDraws.Add(name, StaticRenderObject.createSROPoints(ShaderUtil.lerpISpheresName, data));
}

public static void removeStaticDraw(string name)
{
if (staticDraws.TryGetValue(name, out StaticRenderObject s))
Expand All @@ -204,9 +194,9 @@ public static void removeStaticDraw(string name)

private static void drawAllStaticRenderObjects()
{
foreach(StaticRenderObject s in staticDraws.Values)
{
s.draw(projectionMatrix, GameInstance.get.thePlayer.getViewMatrix(), GameInstance.get.currentPlanet.getFogColor());
for(int i = 0; i < staticDraws.Count; ++i)
{
staticDraws.ElementAt(i).Value.draw(GameInstance.get.thePlayer.getViewMatrix(), GameInstance.get.currentPlanet.getFogColor());
totalDraws++;
}
}
Expand Down
32 changes: 20 additions & 12 deletions RabbetGameEngine/Src/Rendering/StaticRenderObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class StaticRenderObject
private Texture tex = null;
private Shader shader = null;
private Model mod = null;
private PointCloudModel pointMod = null;
private PointParticle[] points = null;
private PrimitiveType type;
private bool pointBased = false;

Expand All @@ -32,13 +32,20 @@ private StaticRenderObject(string texture, string shader, Model data, PrimitiveT
break;
}
}
private StaticRenderObject(string shader, PointCloudModel data)
private StaticRenderObject(PointParticle[] data, bool transparency)
{
ShaderUtil.tryGetShader(shader, out this.shader);
this.pointMod = data;
type = PrimitiveType.Points;
if (transparency)
{
ShaderUtil.tryGetShader(ShaderUtil.iSpheresTransparentName, out this.shader);
}
else
{
ShaderUtil.tryGetShader(ShaderUtil.iSpheresName, out this.shader);
}
this.points = data;
type = PrimitiveType.TriangleStrip;
pointBased = true;
VAO = VertexArrayObject.createStaticPoints(pointMod.points);
VAO = VertexArrayObject.createStaticPoints(points);
}

public static StaticRenderObject createSROTriangles(string texture, string shader, Model data)
Expand All @@ -51,29 +58,30 @@ public static StaticRenderObject createSROLines(string texture, string shader, M
return new StaticRenderObject(texture, shader, data, PrimitiveType.Lines);
}

public static StaticRenderObject createSROPoints(string shader, PointCloudModel data)
public static StaticRenderObject createSROPoints(PointParticle[] data, bool transparency)
{
return new StaticRenderObject(shader, data);
return new StaticRenderObject(data, transparency);
}

public void draw(Matrix4 projectionMatrix, Matrix4 viewMatrix, Vector3 fogColor)
public void draw(Matrix4 viewMatrix, Vector3 fogColor)
{
VAO.bindVaoVboIbo();
shader.use();
if (tex != null)
{
tex.use();
}
shader.setUniformMat4F("projectionMatrix", projectionMatrix);
shader.setUniformMat4F("projectionMatrix", Renderer.projMatrix);
shader.setUniformMat4F("viewMatrix", viewMatrix);
shader.setUniformVec3F("fogColor", fogColor);
shader.setUniform1F("percentageToNextTick", TicksAndFrames.getPercentageToNextTick());
shader.setUniform1I("frame", Renderer.frame);
shader.setUniformVec2F("viewPortSize", Renderer.useOffScreenBuffer ? new Vector2(OffScreen.getWidth, OffScreen.getHeight) : new Vector2(GameInstance.get.Width, GameInstance.get.Height));

if(pointBased)
if (pointBased)
{
GL.DrawArrays(PrimitiveType.Points, 0, pointMod.points.Length);
VAO.bindInstVBO();
GL.DrawArraysInstanced(VAO.getPrimType(), 0, 4, points.Length);
return;
}
else
Expand Down
Loading

0 comments on commit 1252229

Please sign in to comment.