Skip to content

Commit

Permalink
Implimented looping sounds and 3d text
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrickbancan committed Nov 2, 2020
1 parent b704208 commit b4f1c0e
Show file tree
Hide file tree
Showing 38 changed files with 624 additions and 86 deletions.
Binary file added DevScreenshots/40(bug).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DevScreenshots/41.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions Res/Shaders/VFX/StaticText3D_F.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//shader for rendering point particles Dynamically opaque
#shader vertex
#version 330
layout(location = 0) in vec4 position;
layout(location = 1) in vec4 vertexColor;
layout(location = 2) in vec2 texCoord;
layout(location = 3) in float objectID;
layout(location = 4) in vec3 textPos;

uniform float fogDensity = 0.0075;
const float fogGradient = 2.5;

out vec4 vColor;
out float visibility;
out vec2 fTexCoord;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 cameraPos;
//vector of viewport dimensions
uniform vec2 viewPortSize;
uniform float percentageToNextTick;
uniform int frame;

void main()
{
//create translation
mat4 modelMatrix = mat4(1.0F);
modelMatrix[3][0] = textPos.x;
modelMatrix[3][1] = textPos.y;
modelMatrix[3][2] = textPos.z;

//remove rotation
mat4 modelViewBillboard = viewMatrix * modelMatrix;
modelViewBillboard[0][0] = 1;
modelViewBillboard[0][1] = 0;
modelViewBillboard[0][2] = 0;
modelViewBillboard[1][0] = 0;
modelViewBillboard[1][1] = 1;
modelViewBillboard[1][2] = 0;
modelViewBillboard[2][0] = 0;
modelViewBillboard[2][1] = 0;
modelViewBillboard[2][2] = 1;
vec4 positionRelativeToCam = modelViewBillboard * position;
gl_Position = projectionMatrix * positionRelativeToCam;

float distanceFromCam = length(positionRelativeToCam.xyz);
visibility = exp(-pow((distanceFromCam * fogDensity), fogGradient));
visibility = clamp(visibility, 0.0, 1.0);

vColor = vertexColor;
fTexCoord = texCoord;
}

/*#############################################################################################################################################################################################*/
#shader fragment
#version 330
layout(location = 0) out vec4 fragColor;
in float visibility;
in vec4 vColor;
in vec2 fTexCoord;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 fogColor;
uniform sampler2D uTexture;
void main()
{
vec4 textureColor = texture(uTexture, fTexCoord) * vColor;
if (textureColor.a < 0.01F)
{
discard;//cutout
}
fragColor.rgb = mix(fogColor, textureColor.rgb, visibility);
fragColor.a = 1;
}
Binary file added Res/Sounds/rain.ogg
Binary file not shown.
Binary file added Res/Sounds/waterroll.ogg
Binary file not shown.
Binary file added Res/Sounds/waterroll_large.ogg
Binary file not shown.
1 change: 0 additions & 1 deletion Src/Game/Debugging/DebugInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using RabbetGameEngine.GUI;
using RabbetGameEngine.GUI.Text;
using RabbetGameEngine.Sound;
using RabbetGameEngine.SubRendering;

Expand Down
2 changes: 1 addition & 1 deletion Src/Game/GUIS/MainGUI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using RabbetGameEngine.Debugging;
using RabbetGameEngine.GUI;
using RabbetGameEngine.GUI.Text;
using RabbetGameEngine.Text;

namespace RabbetGameEngine
{
Expand Down
10 changes: 9 additions & 1 deletion Src/Game/GameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using OpenTK.Windowing.Desktop;
using RabbetGameEngine.Debugging;
using RabbetGameEngine.GUI;
using RabbetGameEngine.GUI.Text;
using RabbetGameEngine.Sound;
using RabbetGameEngine.Src.Game;
using RabbetGameEngine.SubRendering;
using RabbetGameEngine.Text;
using RabbetGameEngine.VisualEffects;
using System;
using System.Drawing;

Expand Down Expand Up @@ -75,6 +77,10 @@ protected override void OnLoad()
currentPlanet.spawnEntityInWorld(new EntityCactus(currentPlanet, new Vector3(0, 10, 0)));
}
currentPlanet.spawnEntityInWorld(thePlayer);
SoundManager.playSoundLoopingAt("waterroll", new Vector3(16, 1, 16), 0.1F);
currentPlanet.spawnVFXInWorld(new VFXStaticText3D("waterroll", "Arial_Shadow", "waterroll.ogg, 10% volume", new Vector3(16,2.5F,16), 5.0F, CustomColor.white));
SoundManager.playSoundLoopingAt("waterroll_large", new Vector3(-16, 1, -16), 0.5F);
currentPlanet.spawnVFXInWorld(new VFXStaticText3D("waterroll_large", "Arial_Shadow", "waterroll_large.ogg, 50% volume", new Vector3(-16,2.5F,-16), 5.0F, CustomColor.white));
Input.setCursorHiddenAndGrabbed(true);
}
catch(Exception e)
Expand Down Expand Up @@ -146,6 +152,8 @@ private void onTick()
Renderer.onTickStart();
GUIManager.onTick();
MainGUI.onTick();
HitboxRenderer.addPointToBeRendered(new Vector3(16,1,16));
HitboxRenderer.addPointToBeRendered(new Vector3(-16,1,-16));
currentPlanet.onTick();
SoundManager.onTick();
Profiler.updateAverages();
Expand Down
5 changes: 5 additions & 0 deletions Src/Game/GameSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ static class GameSettings
{
public static float fov = 80; //fov of player camera
public static float mouseSensitivity = 0.08F;

/// <summary>
/// This setting MUST be between 0 and 1
/// </summary>
public static float masterVolume = 0.5F;

public static bool vsync = false;
public static bool displayFps = true;
public static bool debugScreen = true;
Expand Down
1 change: 0 additions & 1 deletion Src/Rendering/GUIComponents/GUICrosshair.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using OpenTK.Mathematics;
using RabbetGameEngine.Models;
using RabbetGameEngine.SubRendering;
using RabbetGameEngine.SubRendering.GUI;
namespace RabbetGameEngine.GUI
{
public enum CrosshairType//enum for all different types of crosshairs
Expand Down
4 changes: 1 addition & 3 deletions Src/Rendering/GUIManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using RabbetGameEngine.GUI.Text;
using RabbetGameEngine.SubRendering.GUI;
using System.Collections.Generic;
using System.Collections.Generic;

namespace RabbetGameEngine.GUI
{
Expand Down
15 changes: 14 additions & 1 deletion Src/Rendering/Models/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class Model
public uint[] indices = null;
public Matrix4 modelMatrix = Matrix4.Identity;
public Matrix4 prevModelMatrix = Matrix4.Identity;
public Vector3 worldPos;
public Vector3 prevWorldPos;
public Model(Vertex[] vertices, uint[] indices)
{
this.vertices = vertices;
Expand Down Expand Up @@ -112,7 +114,7 @@ public Model copyModel()
uint[] indicesCopy = new uint[indices.Length];
Array.Copy(indices, indicesCopy, indices.Length);
Array.Copy(vertices, verticesCopy, vertices.Length);
return new Model(verticesCopy, indicesCopy);
return new Model(verticesCopy, indicesCopy).setModelPos(worldPos).setModelPrevPos(prevWorldPos);
}

/// <summary>
Expand All @@ -131,6 +133,17 @@ public Model setObjectID(float f)
return this;
}

public Model setModelPos(Vector3 pos)
{
this.worldPos = pos;
return this;
}

public Model setModelPrevPos(Vector3 pos)
{
this.prevWorldPos = pos;
return this;
}
public Model setModelMatrix(Matrix4 m)
{
this.modelMatrix = m;
Expand Down
8 changes: 2 additions & 6 deletions Src/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

namespace RabbetGameEngine
{
/*This class will be responsable for most of the games rendering requests. It will then send the requests to the suitable sub renderers.
e.g, when the game requests text to be rendered on the screen, the renderer will send a request to the TextRenderer2D.
e.g, when the game requests entity models to be rendered in the world, the renderer will send a request to the model draw function.
This class also contains the projection matrix.*/
public static class Renderer
public static class Renderer//TODO: Add support for 3d text rendering
{
private static int privateTotalDrawCallCount;
private static Matrix4 projectionMatrix;
Expand All @@ -23,7 +19,7 @@ public static class Renderer
private static int renderFrame;//used to animate textures (noise texture for now)

/// <summary>
/// A list of all requested
/// A list of all requested static renders
/// </summary>
private static Dictionary<string, StaticRenderObject> staticDraws;

Expand Down
2 changes: 1 addition & 1 deletion Src/Rendering/ShaderUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class ShaderUtil
{
public static readonly string guiCutoutName = "GuiCutout";
public static readonly string text2DName = "GuiText";
public static readonly string text3DName = "";
public static readonly string text3DName = "StaticText3D_F";
public static readonly string trianglesName = "Static_F";
public static readonly string linesName = "StaticLines";
public static readonly string iSpheresName = "StaticISpheres_F";
Expand Down
2 changes: 2 additions & 0 deletions Src/Rendering/StaticRenderObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void draw(Matrix4 viewMatrix, Vector3 fogColor)
shader.setUniformMat4F("orthoMatrix", Renderer.orthoMatrix);
shader.setUniformMat4F("viewMatrix", viewMatrix);
shader.setUniformVec3F("fogColor", fogColor);
shader.setUniform1F("fogDensity", GameInstance.get.currentPlanet.getFogDensity());
shader.setUniform1F("fogGradient", GameInstance.get.currentPlanet.getFogGradient());
shader.setUniform1F("percentageToNextTick", TicksAndFrames.getPercentageToNextTick());
shader.setUniform1I("frame", Renderer.frame);
shader.setUniformVec2F("viewPortSize", Renderer.useOffScreenBuffer ? new Vector2(OffScreen.getWidth, OffScreen.getHeight) : new Vector2(GameInstance.gameWindowWidth, GameInstance.gameWindowWidth));
Expand Down
Loading

0 comments on commit b4f1c0e

Please sign in to comment.